Skip to content

Commit

Permalink
Remove custom handler
Browse files Browse the repository at this point in the history
  • Loading branch information
shadromani committed Jul 17, 2024
1 parent ba49e05 commit 65627ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions minfraud/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

_SCHEME = "https"


# pylint: disable=too-many-instance-attributes, missing-class-docstring
class BaseClient:
_account_id: str
Expand Down
43 changes: 23 additions & 20 deletions tests/test_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

minfraud.webservice._SCHEME = "http"


class BaseTest(unittest.TestCase):
client_class: Union[Type[AsyncClient], Type[Client]] = Client

Expand All @@ -30,7 +31,11 @@ def setup_httpserver(self, httpserver: HTTPServer):
self.httpserver = httpserver

def setUp(self):
self.client = self.client_class(42, "abcdef123456",host="{0}:{1}".format(self.httpserver.host,self.httpserver.port))
self.client = self.client_class(
42,
"abcdef123456",
host="{0}:{1}".format(self.httpserver.host, self.httpserver.port),
)
test_dir = os.path.join(os.path.dirname(__file__), "data")
with open(os.path.join(test_dir, self.request_file), encoding="utf-8") as file:
content = file.read()
Expand Down Expand Up @@ -205,36 +210,34 @@ def test_200_on_request_with_nones(self):

def test_200_with_email_hashing(self):
uri = "/".join(["/minfraud/v2.0", self.type])

last = None

def custom_handler(r):
nonlocal last
last = r
return '{"status": 204}'

self.httpserver.expect_request(uri, method="POST").respond_with_handler(
custom_handler
)

request = {"email": {"address": "[email protected]"}}
self.run_client(getattr(self.client, self.type)(request, hash_email=True))

self.assertEqual(
{
self.httpserver.expect_request(
uri,
method="POST",
json={
"email": {
"address": "977577b140bfb7c516e4746204fbdb01",
"domain": "maxmind.com",
}
},
json.loads(last.data.decode("utf-8")),
).respond_with_data(
self.response,
content_type=f"application/vnd.maxmind.com-minfraud-{self.type}+json; charset=UTF-8; version=2.0",
status=200,
)

request = {"email": {"address": "[email protected]"}}
self.run_client(getattr(self.client, self.type)(request, hash_email=True))

# This was fixed in https://github.com/maxmind/minfraud-api-python/pull/78

def test_200_with_locales(self):
locales = ("fr",)
client = self.client_class(42, "abcdef123456", locales=locales,host="{0}:{1}".format(self.httpserver.host,self.httpserver.port))
client = self.client_class(
42,
"abcdef123456",
locales=locales,
host="{0}:{1}".format(self.httpserver.host, self.httpserver.port),
)
model = self.create_success(client=client)
response = json.loads(self.response)
if self.has_ip_location():
Expand Down

0 comments on commit 65627ff

Please sign in to comment.