8000 Use correct syntax for header matching · akx/GeoIP2-python@c18578d · GitHub
[go: up one dir, main page]

Skip to content

Commit c18578d

Browse files
committed
Use correct syntax for header matching
1 parent 94c3584 commit c18578d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/webservice_test.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,27 @@ def test_unknown_error(self):
279279
self.run_client(self.client.country(ip))
280280

281281
def test_request(self):
282-
matcher = HeaderValueMatcher(
283-
{
284-
"Accept": "application/json",
285-
"Authorization": "Basic NDI6YWJjZGVmMTIzNDU2",
286-
"User-Agent": lambda x: x.startswith("GeoIP2-Python-Client/"),
287-
}
288-
)
282+
def user_agent_compare(actual: str, expected: str) -> bool:
283+
if actual is None:
284+
return False
285+
return actual.startswith("GeoIP2-Python-Client/")
286+
287+
def accept_compare(actual: str, expected: str) -> bool:
288+
return actual == "application/json"
289+
290+
def authorization_compare(actual: str, expected: str) -> bool:
291+
return actual == "Basic NDI6YWJjZGVmMTIzNDU2"
292+
289293
self.httpserver.expect_request(
290294
"/geoip/v2.1/country/1.2.3.4",
291295
method="GET",
292-
header_value_matcher=matcher,
296+
header_value_matcher=HeaderValueMatcher(
297+
{
298+
"User-Agent": user_agent_compare,
299+
"Accept": accept_compare,
300+
"Authorization": authorization_compare,
301+
}
302+
),
293303
).respond_with_json(
294304
self.country,
295305
status=200,

0 commit comments

Comments
 (0)
0