Skip to content

Commit 2504c66

Browse files
Merge pull request #2164 from VWS-Python/prepared-requests
Account for update in vws-auth-tools
2 parents d377456 + c3265a1 commit 2504c66

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

src/mock_vws/_database_matchers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,14 @@ def get_database_matching_client_keys(
4040
"""
4141
content_type = request_headers.get("Content-Type", "").split(";")[0]
4242
auth_header = request_headers.get("Authorization")
43-
content = request_body or b""
4443
date = request_headers.get("Date", "")
4544

4645
for database in databases:
4746
expected_authorization_header = authorization_header(
4847
access_key=database.client_access_key,
4948
secret_key=database.client_secret_key,
5049
method=request_method,
51-
content=content,
50+
content=request_body,
5251
content_type=content_type,
5352
date=date,
5453
request_path=request_path,
@@ -85,15 +84,14 @@ def get_database_matching_server_keys(
8584
"""
8685
content_type = request_headers.get("Content-Type", "").split(";")[0]
8786
auth_header = request_headers.get("Authorization")
88-
content = request_body or b""
8987
date = request_headers.get("Date", "")
9088

9189
for database in databases:
9290
expected_authorization_header = authorization_header(
9391
access_key=database.server_access_key,
9492
secret_key=database.server_secret_key,
9593
method=request_method,
96-
content=content,
94+
content=request_body,
9795
content_type=content_type,
9896
date=date,
9997
request_path=request_path,

tests/mock_vws/test_date_header.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ def test_no_date_header(endpoint: Endpoint) -> None:
4646
A `BAD_REQUEST` response is returned when no `Date` header is given.
4747
"""
4848
endpoint_headers = dict(endpoint.prepared_request.headers)
49-
content = endpoint.prepared_request.body or b""
50-
assert isinstance(content, bytes)
5149

5250
authorization_string = authorization_header(
5351
access_key=endpoint.access_key,
5452
secret_key=endpoint.secret_key,
55-
method=str(endpoint.prepared_request.method),
56-
content=content,
53+
method=endpoint.prepared_request.method or "",
54+
content=endpoint.prepared_request.body,
5755
content_type=endpoint.auth_header_content_type,
5856
date="",
5957
request_path=endpoint.prepared_request.path_url,
@@ -112,14 +110,12 @@ def test_incorrect_date_format(endpoint: Endpoint) -> None:
112110
date_incorrect_format = now.strftime("%a %b %d %H:%M:%S")
113111

114112
endpoint_headers = dict(endpoint.prepared_request.headers)
115-
content = endpoint.prepared_request.body or b""
116-
assert isinstance(content, bytes)
117113

118114
authorization_string = authorization_header(
119115
access_key=endpoint.access_key,
120116
secret_key=endpoint.secret_key,
121-
method=str(endpoint.prepared_request.method),
122-
content=content,
117+
method=endpoint.prepared_request.method or "",
118+
content=endpoint.prepared_request.body,
123119
content_type=endpoint.auth_header_content_type,
124120
date=date_incorrect_format,
125121
request_path=endpoint.prepared_request.path_url,
@@ -185,14 +181,12 @@ def test_date_out_of_range_after(endpoint: Endpoint) -> None:
185181
date = rfc_1123_date()
186182

187183
endpoint_headers = dict(endpoint.prepared_request.headers)
188-
content = endpoint.prepared_request.body or b""
189-
assert isinstance(content, bytes)
190184

191185
authorization_string = authorization_header(
192186
access_key=endpoint.access_key,
193187
secret_key=endpoint.secret_key,
194-
method=str(endpoint.prepared_request.method),
195-
content=content,
188+
method=endpoint.prepared_request.method or "",
189+
content=endpoint.prepared_request.body,
196190
content_type=endpoint.auth_header_content_type,
197191
date=date,
198192
request_path=endpoint.prepared_request.path_url,
@@ -251,14 +245,12 @@ def test_date_out_of_range_before(endpoint: Endpoint) -> None:
251245
date = rfc_1123_date()
252246

253247
endpoint_headers = dict(endpoint.prepared_request.headers)
254-
content = endpoint.prepared_request.body or b""
255-
assert isinstance(content, bytes)
256248

257249
authorization_string = authorization_header(
258250
access_key=endpoint.access_key,
259251
secret_key=endpoint.secret_key,
260-
method=str(endpoint.prepared_request.method),
261-
content=content,
252+
method=endpoint.prepared_request.method or "",
253+
content=endpoint.prepared_request.body,
262254
content_type=endpoint.auth_header_content_type,
263255
date=date,
264256
request_path=endpoint.prepared_request.path_url,
@@ -316,14 +308,12 @@ def test_date_in_range_after(endpoint: Endpoint) -> None:
316308
date = rfc_1123_date()
317309

318310
endpoint_headers = dict(endpoint.prepared_request.headers)
319-
content = endpoint.prepared_request.body or b""
320-
assert isinstance(content, bytes)
321311

322312
authorization_string = authorization_header(
323313
access_key=endpoint.access_key,
324314
secret_key=endpoint.secret_key,
325-
method=str(endpoint.prepared_request.method),
326-
content=content,
315+
method=endpoint.prepared_request.method or "",
316+
content=endpoint.prepared_request.body,
327317
content_type=endpoint.auth_header_content_type,
328318
date=date,
329319
request_path=endpoint.prepared_request.path_url,
@@ -372,14 +362,12 @@ def test_date_in_range_before(endpoint: Endpoint) -> None:
372362
date = rfc_1123_date()
373363

374364
endpoint_headers = dict(endpoint.prepared_request.headers)
375-
content = endpoint.prepared_request.body or b""
376-
assert isinstance(content, bytes)
377365

378366
authorization_string = authorization_header(
379367
access_key=endpoint.access_key,
380368
secret_key=endpoint.secret_key,
381-
method=str(endpoint.prepared_request.method),
382-
content=content,
369+
method=endpoint.prepared_request.method or "",
370+
content=endpoint.prepared_request.body,
383371
content_type=endpoint.auth_header_content_type,
384372
date=date,
385373
request_path=endpoint.prepared_request.path_url,

tests/mock_vws/test_invalid_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_invalid_json(endpoint: Endpoint) -> None:
5151
authorization_string = authorization_header(
5252
access_key=endpoint.access_key,
5353
secret_key=endpoint.secret_key,
54-
method=str(endpoint.prepared_request.method),
54+
method=endpoint.prepared_request.method or "",
5555
content=content,
5656
content_type=endpoint.auth_header_content_type,
5757
date=date,
@@ -123,7 +123,7 @@ def test_invalid_json_with_skewed_time(endpoint: Endpoint) -> None:
123123
authorization_string = authorization_header(
124124
access_key=endpoint.access_key,
125125
secret_key=endpoint.secret_key,
126-
method=str(endpoint.prepared_request.method),
126+
method=endpoint.prepared_request.method or "",
127127
content=content,
128128
content_type=endpoint.auth_header_content_type,
129129
date=date,

tests/mock_vws/test_unexpected_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_does_not_take_data(endpoint: Endpoint) -> None:
4949
authorization_string = authorization_header(
5050
access_key=endpoint.access_key,
5151
secret_key=endpoint.secret_key,
52-
method=str(endpoint.prepared_request.method),
52+
method=endpoint.prepared_request.method or "",
5353
content=content,
5454
content_type=content_type,
5555
date=date,

0 commit comments

Comments
 (0)