Skip to content

Commit 4cc3dd5

Browse files
committed
tests: add requests headers asserter
1 parent d218e80 commit 4cc3dd5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,8 @@ def assert_logging_policy(mock_warning, *args):
119119
"""Assert if an warning was outputted by PolicyWarning """
120120
assert logging.Logger.warning is mock_warning
121121
mock_warning.assert_called_with('[%s] %s', *args)
122+
123+
124+
def assert_request_contains_header(headers, name, value):
125+
assert name in headers
126+
assert headers[name] == value

tests/test_service_v2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from pyodata.exceptions import PyODataException, HttpError, ExpressionError
1212
from pyodata.v2.service import EntityKey, EntityProxy, GetEntitySetFilter
1313

14+
from tests.conftest import assert_request_contains_header
15+
16+
1417
URL_ROOT = 'http://odatapy.example.com'
1518

1619

@@ -158,8 +161,7 @@ def test_create_entity_header_x_requested_with(service):
158161
result = service.entity_sets.Cars.create_entity().set(**entity).execute()
159162

160163
assert result.Name == 'Hadraplan'
161-
assert 'X-Requested-With' in responses.calls[0].request.headers
162-
assert responses.calls[0].request.headers['X-Requested-With'] == 'X'
164+
assert_request_contains_header(responses.calls[0].request.headers, 'X-Requested-With', 'X')
163165

164166

165167
@responses.activate

0 commit comments

Comments
 (0)