Skip to content

Commit 08738e4

Browse files
Merge pull request #2168 from VWS-Python/simplify-cid
2 parents 98058eb + b0b3cdf commit 08738e4

File tree

5 files changed

+53
-59
lines changed

5 files changed

+53
-59
lines changed

tests/mock_vws/test_authorization_header.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,9 @@ def test_missing(endpoint: Endpoint) -> None:
4646
is given.
4747
"""
4848
date = rfc_1123_date()
49-
headers = endpoint.prepared_request.headers.copy()
50-
headers.update({"Date": date})
49+
endpoint.prepared_request.headers.update({"Date": date})
50+
endpoint.prepared_request.headers.pop("Authorization", None)
5151

52-
headers.pop("Authorization", None)
53-
54-
endpoint.prepared_request.headers = headers
5552
session = requests.Session()
5653
response = session.send(request=endpoint.prepared_request)
5754
handle_server_errors(response=response)
@@ -96,10 +93,10 @@ def test_one_part_no_space(endpoint: Endpoint) -> None:
9693
# string, but really any string which is not two parts when split on a
9794
# space will do.
9895
authorization_string = "VWS"
99-
headers = endpoint.prepared_request.headers.copy()
100-
headers.update({"Authorization": authorization_string, "Date": date})
96+
endpoint.prepared_request.headers.update(
97+
{"Authorization": authorization_string, "Date": date},
98+
)
10199

102-
endpoint.prepared_request.headers = headers
103100
session = requests.Session()
104101
response = session.send(request=endpoint.prepared_request)
105102
handle_server_errors(response=response)
@@ -134,10 +131,10 @@ def test_one_part_with_space(endpoint: Endpoint) -> None:
134131
authorization_string = "VWS "
135132
date = rfc_1123_date()
136133

137-
headers = endpoint.prepared_request.headers.copy()
138-
headers.update({"Authorization": authorization_string, "Date": date})
134+
endpoint.prepared_request.headers.update(
135+
{"Authorization": authorization_string, "Date": date},
136+
)
139137

140-
endpoint.prepared_request.headers = headers
141138
session = requests.Session()
142139
response = session.send(request=endpoint.prepared_request)
143140
handle_server_errors(response=response)
@@ -171,10 +168,10 @@ def test_missing_signature(endpoint: Endpoint) -> None:
171168
date = rfc_1123_date()
172169

173170
authorization_string = "VWS foobar:"
174-
headers = endpoint.prepared_request.headers.copy()
175-
headers.update({"Authorization": authorization_string, "Date": date})
171+
endpoint.prepared_request.headers.update(
172+
{"Authorization": authorization_string, "Date": date},
173+
)
176174

177-
endpoint.prepared_request.headers = headers
178175
session = requests.Session()
179176
response = session.send(request=endpoint.prepared_request)
180177
handle_server_errors(response=response)

tests/mock_vws/test_content_length.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ def test_not_integer(endpoint: Endpoint) -> None:
4141
A ``BAD_REQUEST`` error is given when the given ``Content-Length`` is
4242
not an integer.
4343
"""
44-
headers = endpoint.prepared_request.headers.copy()
45-
if not headers.get("Content-Type"):
44+
if not endpoint.prepared_request.headers.get("Content-Type"):
4645
return
4746

4847
content_length = "0.4"
49-
headers.update({"Content-Length": content_length})
50-
endpoint.prepared_request.headers = headers
48+
endpoint.prepared_request.headers.update(
49+
{"Content-Length": content_length},
50+
)
5151
session = requests.Session()
5252
response = session.send(request=endpoint.prepared_request)
5353
handle_server_errors(response=response)
@@ -94,16 +94,18 @@ def test_too_large(endpoint: Endpoint) -> None: # pragma: no cover
9494
"""
9595
An error is given if the given content length is too large.
9696
"""
97-
headers = endpoint.prepared_request.headers.copy()
98-
if not headers.get("Content-Type"):
97+
if not endpoint.prepared_request.headers.get("Content-Type"):
9998
pytest.skip("No Content-Type header for this request")
10099

101100
url = str(endpoint.prepared_request.url)
102101
netloc = urlparse(url).netloc
103-
content_length = str(int(headers["Content-Length"]) + 1)
104-
headers.update({"Content-Length": content_length})
102+
content_length = str(
103+
int(endpoint.prepared_request.headers["Content-Length"]) + 1
104+
)
105+
endpoint.prepared_request.headers.update(
106+
{"Content-Length": content_length}
107+
)
105108

106-
endpoint.prepared_request.headers = headers
107109
session = requests.Session()
108110
response = session.send(request=endpoint.prepared_request)
109111
# We do not use ``handle_server_errors`` here because we do not want to
@@ -141,14 +143,16 @@ def test_too_small(endpoint: Endpoint) -> None:
141143
An ``UNAUTHORIZED`` response is given if the given content length is
142144
too small.
143145
"""
144-
headers = endpoint.prepared_request.headers.copy()
145-
if not headers.get("Content-Type"):
146+
if not endpoint.prepared_request.headers.get("Content-Type"):
146147
return
147148

148-
content_length = str(int(headers["Content-Length"]) - 1)
149-
headers.update({"Content-Length": content_length})
149+
content_length = str(
150+
int(endpoint.prepared_request.headers["Content-Length"]) - 1
151+
)
152+
endpoint.prepared_request.headers.update(
153+
{"Content-Length": content_length}
154+
)
150155

151-
endpoint.prepared_request.headers = headers
152156
session = requests.Session()
153157
response = session.send(request=endpoint.prepared_request)
154158
handle_server_errors(response=response)

tests/mock_vws/test_date_header.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def test_no_date_header(endpoint: Endpoint) -> None:
5454
request_path=endpoint.prepared_request.path_url,
5555
)
5656

57-
headers = endpoint.prepared_request.headers.copy()
58-
headers.update({"Authorization": authorization_string})
59-
headers.pop("Date", None)
60-
endpoint.prepared_request.headers = headers
57+
endpoint.prepared_request.headers.update(
58+
{"Authorization": authorization_string}
59+
)
60+
endpoint.prepared_request.headers.pop("Date", None)
6161
session = requests.Session()
6262
response = session.send(request=endpoint.prepared_request)
6363
handle_server_errors(response=response)
@@ -105,8 +105,6 @@ def test_incorrect_date_format(endpoint: Endpoint) -> None:
105105
now = datetime.now(tz=gmt)
106106
date_incorrect_format = now.strftime("%a %b %d %H:%M:%S")
107107

108-
headers = endpoint.prepared_request.headers.copy()
109-
110108
authorization_string = authorization_header(
111109
access_key=endpoint.access_key,
112110
secret_key=endpoint.secret_key,
@@ -117,14 +115,13 @@ def test_incorrect_date_format(endpoint: Endpoint) -> None:
117115
request_path=endpoint.prepared_request.path_url,
118116
)
119117

120-
headers.update(
118+
endpoint.prepared_request.headers.update(
121119
{
122120
"Authorization": authorization_string,
123121
"Date": date_incorrect_format,
124122
},
125123
)
126124

127-
endpoint.prepared_request.headers = headers
128125
session = requests.Session()
129126
response = session.send(request=endpoint.prepared_request)
130127
handle_server_errors(response=response)
@@ -188,10 +185,10 @@ def test_date_out_of_range_after(endpoint: Endpoint) -> None:
188185
request_path=endpoint.prepared_request.path_url,
189186
)
190187

191-
headers = endpoint.prepared_request.headers.copy()
192-
headers.update({"Authorization": authorization_string, "Date": date})
188+
endpoint.prepared_request.headers.update(
189+
{"Authorization": authorization_string, "Date": date}
190+
)
193191

194-
endpoint.prepared_request.headers = headers
195192
session = requests.Session()
196193
response = session.send(request=endpoint.prepared_request)
197194
handle_server_errors(response=response)
@@ -248,10 +245,10 @@ def test_date_out_of_range_before(endpoint: Endpoint) -> None:
248245
request_path=endpoint.prepared_request.path_url,
249246
)
250247

251-
headers = endpoint.prepared_request.headers.copy()
252-
headers.update({"Authorization": authorization_string, "Date": date})
248+
endpoint.prepared_request.headers.update(
249+
{"Authorization": authorization_string, "Date": date},
250+
)
253251

254-
endpoint.prepared_request.headers = headers
255252
session = requests.Session()
256253
response = session.send(request=endpoint.prepared_request)
257254
handle_server_errors(response=response)
@@ -297,8 +294,6 @@ def test_date_in_range_after(endpoint: Endpoint) -> None:
297294
with freeze_time(datetime.now(tz=gmt) + time_difference_from_now):
298295
date = rfc_1123_date()
299296

300-
headers = endpoint.prepared_request.headers.copy()
301-
302297
authorization_string = authorization_header(
303298
access_key=endpoint.access_key,
304299
secret_key=endpoint.secret_key,
@@ -309,9 +304,10 @@ def test_date_in_range_after(endpoint: Endpoint) -> None:
309304
request_path=endpoint.prepared_request.path_url,
310305
)
311306

312-
headers.update({"Authorization": authorization_string, "Date": date})
307+
endpoint.prepared_request.headers.update(
308+
{"Authorization": authorization_string, "Date": date},
309+
)
313310

314-
endpoint.prepared_request.headers = headers
315311
session = requests.Session()
316312
response = session.send(request=endpoint.prepared_request)
317313
handle_server_errors(response=response)
@@ -358,10 +354,10 @@ def test_date_in_range_before(endpoint: Endpoint) -> None:
358354
request_path=endpoint.prepared_request.path_url,
359355
)
360356

361-
headers = endpoint.prepared_request.headers.copy()
362-
headers.update({"Authorization": authorization_string, "Date": date})
357+
endpoint.prepared_request.headers.update(
358+
{"Authorization": authorization_string, "Date": date},
359+
)
363360

364-
endpoint.prepared_request.headers = headers
365361
session = requests.Session()
366362
response = session.send(request=endpoint.prepared_request)
367363
handle_server_errors(response=response)

tests/mock_vws/test_invalid_json.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def test_invalid_json(endpoint: Endpoint) -> None:
5656
request_path=endpoint.prepared_request.path_url,
5757
)
5858

59-
headers = endpoint.prepared_request.headers.copy()
60-
headers.update({"Authorization": authorization_string, "Date": date})
59+
endpoint.prepared_request.headers.update(
60+
{"Authorization": authorization_string, "Date": date}
61+
)
6162

6263
endpoint.prepared_request.body = content
63-
endpoint.prepared_request.headers = headers
6464
endpoint.prepared_request.prepare_content_length(body=content)
6565
session = requests.Session()
6666
response = session.send(request=endpoint.prepared_request)
@@ -125,11 +125,11 @@ def test_invalid_json_with_skewed_time(endpoint: Endpoint) -> None:
125125
request_path=endpoint.prepared_request.path_url,
126126
)
127127

128-
headers = endpoint.prepared_request.headers.copy()
129-
headers.update({"Authorization": authorization_string, "Date": date})
128+
endpoint.prepared_request.headers.update(
129+
{"Authorization": authorization_string, "Date": date},
130+
)
130131

131132
endpoint.prepared_request.body = content
132-
endpoint.prepared_request.headers = headers
133133
endpoint.prepared_request.prepare_content_length(body=content)
134134
session = requests.Session()
135135
response = session.send(request=endpoint.prepared_request)

tests/mock_vws/test_unexpected_json.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def test_does_not_take_data(endpoint: Endpoint) -> None:
4343
content_type = "application/json"
4444
date = rfc_1123_date()
4545

46-
headers = endpoint.prepared_request.headers.copy()
47-
4846
authorization_string = authorization_header(
4947
access_key=endpoint.access_key,
5048
secret_key=endpoint.secret_key,
@@ -55,7 +53,7 @@ def test_does_not_take_data(endpoint: Endpoint) -> None:
5553
request_path=endpoint.prepared_request.path_url,
5654
)
5755

58-
headers.update(
56+
endpoint.prepared_request.headers.update(
5957
{
6058
"Authorization": authorization_string,
6159
"Date": date,
@@ -64,7 +62,6 @@ def test_does_not_take_data(endpoint: Endpoint) -> None:
6462
)
6563

6664
endpoint.prepared_request.body = content
67-
endpoint.prepared_request.headers = headers
6865
endpoint.prepared_request.prepare_content_length(body=content)
6966
session = requests.Session()
7067
response = session.send(request=endpoint.prepared_request)

0 commit comments

Comments
 (0)