File: test_csw_headers.py

package info (click to toggle)
owslib 0.35.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,772 kB
  • sloc: xml: 143,288; python: 24,542; makefile: 15
file content (35 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from unittest import mock
from tests.utils import service_ok

import pytest

from owslib.csw import CatalogueServiceWeb


def test_csw_sends_headers():
    """
    Test that if headers are provided in the CSW class they are sent
    when performing HTTP requests (in this case for GetCapabilities)
    """

    with mock.patch('owslib.util.requests.request', side_effect=RuntimeError) as mock_request:
        try:
            CatalogueServiceWeb(
                'http://example.com/csw',
                version='2.0.2',
                headers={'User-agent': 'my-app/1.0'}
            )
        except RuntimeError:
            assert mock_request.called
            assert mock_request.call_args[1]['headers'] == {'User-agent': 'my-app/1.0'}

    with mock.patch('owslib.util.requests.request', side_effect=RuntimeError) as mock_request:
        try:
            CatalogueServiceWeb(
                'http://example.com/csw',
                version='3.0.0',
                headers={'User-agent': 'my-app/1.0'}
            )
        except RuntimeError:
            assert mock_request.called
            assert mock_request.call_args[1]['headers'] == {'Accept': 'application/xml', 'User-agent': 'my-app/1.0'}