Skip to content

Commit 560f31b

Browse files
committed
Move content type to target API
1 parent bc0e960 commit 560f31b

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

tests/mock_vws/test_date_header.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ def test_no_date_header(
3636
A `BAD_REQUEST` response is returned when no `Date` header is given.
3737
"""
3838
endpoint_headers = dict(endpoint.prepared_request.headers)
39-
content_type = endpoint_headers.get('Content-Type', '')
40-
assert isinstance(content_type, str)
4139
content = endpoint.prepared_request.body or b''
4240
assert isinstance(content, bytes)
4341

@@ -46,7 +44,7 @@ def test_no_date_header(
4644
secret_key=vuforia_database_keys.server_secret_key,
4745
method=str(endpoint.prepared_request.method),
4846
content=content,
49-
content_type=content_type,
47+
content_type=endpoint.auth_header_content_type,
5048
date='',
5149
request_path=endpoint.prepared_request.path_url,
5250
)
@@ -93,8 +91,6 @@ def test_incorrect_date_format(
9391
date_incorrect_format = now.strftime('%a %b %d %H:%M:%S %Y')
9492

9593
endpoint_headers = dict(endpoint.prepared_request.headers)
96-
content_type = endpoint_headers.get('Content-Type', '')
97-
assert isinstance(content_type, str)
9894
content = endpoint.prepared_request.body or b''
9995
assert isinstance(content, bytes)
10096

@@ -103,7 +99,7 @@ def test_incorrect_date_format(
10399
secret_key=vuforia_database_keys.server_secret_key,
104100
method=str(endpoint.prepared_request.method),
105101
content=content,
106-
content_type=content_type,
102+
content_type=endpoint.auth_header_content_type,
107103
date=date_incorrect_format,
108104
request_path=endpoint.prepared_request.path_url,
109105
)
@@ -160,8 +156,6 @@ def test_date_out_of_range(
160156
date = rfc_1123_date()
161157

162158
endpoint_headers = dict(endpoint.prepared_request.headers)
163-
content_type = endpoint_headers.get('Content-Type', '')
164-
assert isinstance(content_type, str)
165159
content = endpoint.prepared_request.body or b''
166160
assert isinstance(content, bytes)
167161

@@ -170,7 +164,7 @@ def test_date_out_of_range(
170164
secret_key=vuforia_database_keys.server_secret_key,
171165
method=str(endpoint.prepared_request.method),
172166
content=content,
173-
content_type=content_type,
167+
content_type=endpoint.auth_header_content_type,
174168
date=date,
175169
request_path=endpoint.prepared_request.path_url,
176170
)
@@ -219,8 +213,6 @@ def test_date_in_range(
219213
date = rfc_1123_date()
220214

221215
endpoint_headers = dict(endpoint.prepared_request.headers)
222-
content_type = endpoint_headers.get('Content-Type', '')
223-
assert isinstance(content_type, str)
224216
content = endpoint.prepared_request.body or b''
225217
assert isinstance(content, bytes)
226218

@@ -229,7 +221,7 @@ def test_date_in_range(
229221
secret_key=vuforia_database_keys.server_secret_key,
230222
method=str(endpoint.prepared_request.method),
231223
content=content,
232-
content_type=content_type,
224+
content_type=endpoint.auth_header_content_type,
233225
date=date,
234226
request_path=endpoint.prepared_request.path_url,
235227
)

tests/mock_vws/test_invalid_json.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,15 @@ def test_invalid_json(
4545
date = rfc_1123_date()
4646

4747
endpoint_headers = dict(endpoint.prepared_request.headers)
48-
content_type = endpoint_headers.get('Content-Type', '')
49-
assert isinstance(content_type, str)
50-
takes_data = bool(content_type)
48+
takes_data = bool(endpoint.auth_header_content_type)
5149
endpoint_headers = dict(endpoint.prepared_request.headers)
5250

5351
authorization_string = authorization_header(
5452
access_key=vuforia_database_keys.server_access_key,
5553
secret_key=vuforia_database_keys.server_secret_key,
5654
method=str(endpoint.prepared_request.method),
5755
content=content,
58-
content_type=content_type,
56+
content_type=endpoint.auth_header_content_type,
5957
date=date,
6058
request_path=endpoint.prepared_request.path_url,
6159
)

tests/mock_vws/test_unexpected_json.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def test_does_not_take_data(
4040
date = rfc_1123_date()
4141

4242
endpoint_headers = dict(endpoint.prepared_request.headers)
43-
assert isinstance(content_type, str)
4443

4544
authorization_string = authorization_header(
4645
access_key=vuforia_database_keys.server_access_key,

tests/mock_vws/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,16 @@ def __init__(
9494
example path is requested with the method.
9595
successful_headers_status_code: The expected status code if the
9696
example path is requested with the method.
97+
auth_header_content_type: The content type to use for the
98+
`Authorization` header.
9799
"""
98100
self.prepared_request = prepared_request
99101
self.successful_headers_status_code = successful_headers_status_code
100102
self.successful_headers_result_code = successful_headers_result_code
103+
headers = prepared_request.headers
104+
content_type = headers.get('Content-Type', '')
105+
assert isinstance(content_type, str)
106+
self.auth_header_content_type: str = content_type
101107

102108

103109
def assert_vws_failure(

0 commit comments

Comments
 (0)