Skip to content

Commit fa73af1

Browse files
committed
Use headers and a matcher
1 parent c18578d commit fa73af1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ pylint.txt
1919
*.swp
2020
.tox
2121
violations.pyflakes.txt
22+
/venv

tests/webservice_test.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from pytest_httpserver import HeaderValueMatcher
1212
import pytest_httpserver
1313
import pytest
14+
from collections import defaultdict
15+
1416

1517
sys.path.append("..")
1618
import geoip2
@@ -284,21 +286,19 @@ def user_agent_compare(actual: str, expected: str) -> bool:
284286
return False
285287
return actual.startswith("GeoIP2-Python-Client/")
286288

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-
293289
self.httpserver.expect_request(
294290
"/geoip/v2.1/country/1.2.3.4",
295291
method="GET",
292+
headers={
293+
"Accept": "application/json",
294+
"Authorization": "Basic NDI6YWJjZGVmMTIzNDU2",
295+
"User-Agent": "GeoIP2-Python-Client/",
296+
},
296297
header_value_matcher=HeaderValueMatcher(
297-
{
298-
"User-Agent": user_agent_compare,
299-
"Accept": accept_compare,
300-
"Authorization": authorization_compare,
301-
}
298+
defaultdict(
299+
lambda: HeaderValueMatcher.default_header_value_matcher,
300+
{"User-Agent": user_agent_compare},
301+
)
302302
),
303303
).respond_with_json(
304304
self.country,

0 commit comments

Comments
 (0)