-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba49e05
commit 65627ff
Showing
2 changed files
with
24 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
minfraud.webservice._SCHEME = "http" | ||
|
||
|
||
class BaseTest(unittest.TestCase): | ||
client_class: Union[Type[AsyncClient], Type[Client]] = Client | ||
|
||
|
@@ -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() | ||
|
@@ -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(): | ||
|