Skip to content

Commit

Permalink
Use correct syntax for header matching
Browse files Browse the repository at this point in the history
  • Loading branch information
shadromani committed Jul 10, 2024
1 parent 94c3584 commit c18578d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/webservice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,27 @@ def test_unknown_error(self):
self.run_client(self.client.country(ip))

def test_request(self):
matcher = HeaderValueMatcher(
{
"Accept": "application/json",
"Authorization": "Basic NDI6YWJjZGVmMTIzNDU2",
"User-Agent": lambda x: x.startswith("GeoIP2-Python-Client/"),
}
)
def user_agent_compare(actual: str, expected: str) -> bool:
if actual is None:
return False
return actual.startswith("GeoIP2-Python-Client/")

def accept_compare(actual: str, expected: str) -> bool:
return actual == "application/json"

def authorization_compare(actual: str, expected: str) -> bool:
return actual == "Basic NDI6YWJjZGVmMTIzNDU2"

self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.4",
method="GET",
header_value_matcher=matcher,
header_value_matcher=HeaderValueMatcher(
{
"User-Agent": user_agent_compare,
"Accept": accept_compare,
"Authorization": authorization_compare,
}
),
).respond_with_json(
self.country,
status=200,
Expand Down

0 comments on commit c18578d

Please sign in to comment.