Skip to content

Commit 5545e8f

Browse files
committed
Update tests for new mocket version
Mocket 3.11.0 switched to a new package for parsing HTTP requests. This changed the header normalization. Unfortunately, the library does not seem to expose a method on the request object that normalizes the header name before checking for it; as such, we normalize them to lowercase ourselves.
1 parent 5c63c45 commit 5545e8f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
include_package_data=True,
2727
python_requires=">=3.7",
2828
install_requires=requirements,
29-
tests_require=["mocket>=3.8.9"],
29+
tests_require=["mocket>=3.11.0"],
3030
test_suite="tests",
3131
license=geoip2.__license__,
3232
classifiers=[

tests/webservice_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,18 @@ def test_request(self):
298298
self.assertEqual(
299299
request.path, "/geoip/v2.1/country/1.2.3.4", "correct URI is used"
300300
)
301-
self.assertEqual(
302-
request.headers["Accept"], "application/json", "correct Accept header"
303-
)
301+
302+
# This is to prevent breakage if header normalization in Mocket
303+
# changes again in the future.
304+
headers = {k.lower(): v for k, v in request.headers.items()}
305+
self.assertEqual(headers["accept"], "application/json", "correct Accept header")
304306
self.assertRegex(
305-
request.headers["User-Agent"],
307+
headers["user-agent"],
306308
"^GeoIP2-Python-Client/",
307309
"Correct User-Agent",
308310
)
309311
self.assertEqual(
310-
request.headers["Authorization"],
312+
headers["authorization"],
311313
"Basic NDI6YWJjZGVmMTIzNDU2",
312314
"correct auth",
313315
)

0 commit comments

Comments
 (0)