2222
2323minfraud .webservice ._SCHEME = "http"
2424
25+
2526class BaseTest (unittest .TestCase ):
2627 client_class : Union [Type [AsyncClient ], Type [Client ]] = Client
2728
@@ -30,7 +31,11 @@ def setup_httpserver(self, httpserver: HTTPServer):
3031 self .httpserver = httpserver
3132
3233 def setUp (self ):
33- self .client = self .client_class (42 , "abcdef123456" ,host = "{0}:{1}" .format (self .httpserver .host ,self .httpserver .port ))
34+ self .client = self .client_class (
35+ 42 ,
36+ "abcdef123456" ,
37+ host = "{0}:{1}" .format (self .httpserver .host , self .httpserver .port ),
38+ )
3439 test_dir = os .path .join (os .path .dirname (__file__ ), "data" )
3540 with open (os .path .join (test_dir , self .request_file ), encoding = "utf-8" ) as file :
3641 content = file .read ()
@@ -205,36 +210,34 @@ def test_200_on_request_with_nones(self):
205210
206211 def test_200_with_email_hashing (self ):
207212 uri = "/" .join (["/minfraud/v2.0" , self .type ])
208-
209- last = None
210-
211- def custom_handler (r ):
212- nonlocal last
213- last = r
214- return '{"status": 204}'
215-
216- self .httpserver .expect_request (uri , method = "POST" ).respond_with_handler (
217- custom_handler
218- )
219-
220- request = {"email" : {"address" : "Test+ignore@maxmind.com" }}
221- self .run_client (getattr (self .client , self .type )(request , hash_email = True ))
222-
223- self .assertEqual (
224- {
213+ self .httpserver .expect_request (
214+ uri ,
215+ method = "POST" ,
216+ json = {
225217 "email" : {
226218 "address" : "977577b140bfb7c516e4746204fbdb01" ,
227219 "domain" : "maxmind.com" ,
228220 }
229221 },
230- json .loads (last .data .decode ("utf-8" )),
222+ ).respond_with_data (
223+ self .response ,
224+ content_type = f"application/vnd.maxmind.com-minfraud-{ self .type } +json; charset=UTF-8; version=2.0" ,
225+ status = 200 ,
231226 )
232227
228+ request = {"email" : {"address" : "Test+ignore@maxmind.com" }}
229+ self .run_client (getattr (self .client , self .type )(request , hash_email = True ))
230+
233231 # This was fixed in https://github.com/maxmind/minfraud-api-python/pull/78
234232
235233 def test_200_with_locales (self ):
236234 locales = ("fr" ,)
237- client = self .client_class (42 , "abcdef123456" , locales = locales ,host = "{0}:{1}" .format (self .httpserver .host ,self .httpserver .port ))
235+ client = self .client_class (
236+ 42 ,
237+ "abcdef123456" ,
238+ locales = locales ,
239+ host = "{0}:{1}" .format (self .httpserver .host , self .httpserver .port ),
240+ )
238241 model = self .create_success (client = client )
239242 response = json .loads (self .response )
240243 if self .has_ip_location ():
0 commit comments