Skip to content

Commit

Permalink
Set method to get explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
shadromani committed Jul 8, 2024
1 parent 2d92b56 commit 94c3584
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions tests/webservice_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def setup_httpserver(self, httpserver: pytest_httpserver.HTTPServer):
self.httpserver = httpserver

def test_country_ok(self):
self.httpserver.expect_request("/geoip/v2.1/country/1.2.3.4").respond_with_json(
self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.4", method="GET"
).respond_with_json(
self.country,
status=200,
content_type=self._content_type("country"),
Expand Down Expand Up @@ -110,7 +112,9 @@ def test_country_ok(self):
self.assertEqual(country.raw, self.country, "raw response is correct")

def test_me(self):
self.httpserver.expect_request("/geoip/v2.1/country/me").respond_with_json(
self.httpserver.expect_request(
"/geoip/v2.1/country/me", method="GET"
).respond_with_json(
self.country,
status=200,
content_type=self._content_type("country"),
Expand All @@ -127,7 +131,9 @@ def test_me(self):
)

def test_200_error(self):
self.httpserver.expect_request("/geoip/v2.1/country/1.1.1.1").respond_with_data(
self.httpserver.expect_request(
"/geoip/v2.1/country/1.1.1.1", method="GET"
).respond_with_data(
"",
status=200,
content_type=self._content_type("country"),
Expand All @@ -146,7 +152,7 @@ def test_bad_ip_address(self):

def test_no_body_error(self):
self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.7"
"/geoip/v2.1/country/1.2.3.7", method="GET"
).respond_with_data(
"",
status=400,
Expand All @@ -160,7 +166,7 @@ def test_no_body_error(self):
def test_weird_body_error(self):

self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.8"
"/geoip/v2.1/country/1.2.3.8", method="GET"
).respond_with_json(
{"wierd": 42},
status=400,
Expand All @@ -176,7 +182,7 @@ def test_weird_body_error(self):
def test_bad_body_error(self):

self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.9"
"/geoip/v2.1/country/1.2.3.9", method="GET"
).respond_with_data(
"bad body",
status=400,
Expand All @@ -189,7 +195,7 @@ def test_bad_body_error(self):

def test_500_error(self):
self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.10"
"/geoip/v2.1/country/1.2.3.10", method="GET"
).respond_with_data(
"",
status=500,
Expand All @@ -201,7 +207,7 @@ def test_500_error(self):
def test_300_error(self):

self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.11"
"/geoip/v2.1/country/1.2.3.11", method="GET"
).respond_with_data(
"",
status=300,
Expand Down Expand Up @@ -249,7 +255,7 @@ def _test_error(self, status, error_code, error_class):
msg = "Some error message"
body = {"error": msg, "code": error_code}
self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.18"
"/geoip/v2.1/country/1.2.3.18", method="GET"
).respond_with_json(
body,
status=status,
Expand All @@ -262,7 +268,9 @@ def test_unknown_error(self):
msg = "Unknown error type"
ip = "1.2.3.19"
body = {"error": msg, "code": "UNKNOWN_TYPE"}
self.httpserver.expect_request("/geoip/v2.1/country/" + ip).respond_with_json(
self.httpserver.expect_request(
"/geoip/v2.1/country/" + ip, method="GET"
).respond_with_json(
body,
status=400,
content_type=self._content_type("country"),
Expand All @@ -271,14 +279,17 @@ 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/"),})
matcher = HeaderValueMatcher(
{
"Accept": "application/json",
"Authorization": "Basic NDI6YWJjZGVmMTIzNDU2",
"User-Agent": lambda x: x.startswith("GeoIP2-Python-Client/"),
}
)
self.httpserver.expect_request(
"/geoip/v2.1/country/1.2.3.4",
method="GET",
header_value_matcher=matcher,

).respond_with_json(
self.country,
status=200,
Expand All @@ -287,7 +298,9 @@ def test_request(self):
self.run_client(self.client.country("1.2.3.4"))

def test_city_ok(self):
self.httpserver.expect_request("/geoip/v2.1/city/1.2.3.4").respond_with_json(
self.httpserver.expect_request(
"/geoip/v2.1/city/1.2.3.4", method="GET"
).respond_with_json(
self.country,
status=200,
content_type=self._content_type("city"),
Expand All @@ -301,7 +314,7 @@ def test_city_ok(self):

def test_insights_ok(self):
self.httpserver.expect_request(
"/geoip/v2.1/insights/1.2.3.4"
"/geoip/v2.1/insights/1.2.3.4", method="GET"
).respond_with_json(
self.insights,
status=200,
Expand Down

0 comments on commit 94c3584

Please sign in to comment.