Skip to content

Commit

Permalink
Use headers and a matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
shadromani committed Jul 15, 2024
1 parent c18578d commit fa73af1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pylint.txt
*.swp
.tox
violations.pyflakes.txt
/venv
22 changes: 11 additions & 11 deletions tests/webservice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from pytest_httpserver import HeaderValueMatcher
import pytest_httpserver
import pytest
from collections import defaultdict


sys.path.append("..")
import geoip2
Expand Down Expand Up @@ -284,21 +286,19 @@ def user_agent_compare(actual: str, expected: str) -> bool:
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",
headers={
"Accept": "application/json",
"Authorization": "Basic NDI6YWJjZGVmMTIzNDU2",
"User-Agent": "GeoIP2-Python-Client/",
},
header_value_matcher=HeaderValueMatcher(
{
"User-Agent": user_agent_compare,
"Accept": accept_compare,
"Authorization": authorization_compare,
}
defaultdict(
lambda: HeaderValueMatcher.default_header_value_matcher,
{"User-Agent": user_agent_compare},
)
),
).respond_with_json(
self.country,
Expand Down

0 comments on commit fa73af1

Please sign in to comment.