1
1
import unittest
2
+ from typing import Any , Union
2
3
3
4
from minfraud .models import *
4
5
5
6
6
7
class TestModels (unittest .TestCase ):
7
- def setUp (self ):
8
+ def setUp (self ) -> None :
8
9
self .maxDiff = 20_000
9
10
10
- def test_billing_address (self ):
11
- address = BillingAddress (** self .address_dict )
11
+ def test_billing_address (self ) -> None :
12
+ address = BillingAddress (** self .address_dict ) # type: ignore[arg-type]
12
13
self .check_address (address )
13
14
14
- def test_shipping_address (self ):
15
+ def test_shipping_address (self ) -> None :
15
16
address_dict = self .address_dict
16
17
address_dict ["is_high_risk" ] = False
17
18
address_dict ["distance_to_billing_address" ] = 200
18
19
19
- address = ShippingAddress (** address_dict )
20
+ address = ShippingAddress (** address_dict ) # type:ignore[arg-type]
20
21
self .check_address (address )
21
22
self .assertEqual (False , address .is_high_risk )
22
23
self .assertEqual (200 , address .distance_to_billing_address )
23
24
24
25
@property
25
- def address_dict (self ):
26
+ def address_dict (self ) -> dict [ str , Union [ bool , float ]] :
26
27
return {
27
28
"is_in_ip_country" : True ,
28
29
"latitude" : 43.1 ,
@@ -31,14 +32,14 @@ def address_dict(self):
31
32
"is_postal_in_city" : True ,
32
33
}
33
34
34
- def check_address (self , address ):
35
+ def check_address (self , address ) -> None :
35
36
self .assertEqual (True , address .is_in_ip_country )
36
37
self .assertEqual (True , address .is_postal_in_city )
37
38
self .assertEqual (100 , address .distance_to_ip_location )
38
39
self .assertEqual (32.1 , address .longitude )
39
40
self .assertEqual (43.1 , address .latitude )
40
41
41
- def test_credit_card (self ):
42
+ def test_credit_card (self ) -> None :
42
43
cc = CreditCard (
43
44
issuer = {"name" : "Bank" },
44
45
brand = "Visa" ,
@@ -59,7 +60,7 @@ def test_credit_card(self):
59
60
self .assertEqual (True , cc .is_issued_in_billing_address_country )
60
61
self .assertEqual ("credit" , cc .type )
61
62
62
- def test_device (self ):
63
+ def test_device (self ) -> None :
63
64
id = "b643d445-18b2-4b9d-bad4-c9c4366e402a"
64
65
last_seen = "2016-06-08T14:16:38Z"
65
66
local_time = "2016-06-10T14:19:10-08:00"
@@ -75,7 +76,7 @@ def test_device(self):
75
76
self .assertEqual (last_seen , device .last_seen )
76
77
self .assertEqual (local_time , device .local_time )
77
78
78
- def test_disposition (self ):
79
+ def test_disposition (self ) -> None :
79
80
disposition = Disposition (
80
81
action = "accept" ,
81
82
reason = "default" ,
@@ -86,7 +87,7 @@ def test_disposition(self):
86
87
self .assertEqual ("default" , disposition .reason )
87
88
self .assertEqual ("custom rule label" , disposition .rule_label )
88
89
89
- def test_email (self ):
90
+ def test_email (self ) -> None :
90
91
first_seen = "2016-01-01"
91
92
email = Email (
92
93
first_seen = first_seen ,
@@ -100,21 +101,21 @@ def test_email(self):
100
101
self .assertEqual (True , email .is_free )
101
102
self .assertEqual (False , email .is_high_risk )
102
103
103
- def test_email_domain (self ):
104
+ def test_email_domain (self ) -> None :
104
105
first_seen = "2016-01-01"
105
106
domain = EmailDomain (
106
107
first_seen = first_seen ,
107
108
)
108
109
109
110
self .assertEqual (first_seen , domain .first_seen )
110
111
111
- def test_geoip2_location (self ):
112
+ def test_geoip2_location (self ) -> None :
112
113
time = "2015-04-19T12:59:23-01:00"
113
114
location = GeoIP2Location (local_time = time , latitude = 5 )
114
115
self .assertEqual (time , location .local_time )
115
116
self .assertEqual (5 , location .latitude )
116
117
117
- def test_ip_address (self ):
118
+ def test_ip_address (self ) -> None :
118
119
time = "2015-04-19T12:59:23-01:00"
119
120
address = IPAddress (
120
121
["en" ],
@@ -175,15 +176,15 @@ def test_ip_address(self):
175
176
address .risk_reasons [1 ].reason ,
176
177
)
177
178
178
- def test_empty_address (self ):
179
+ def test_empty_address (self ) -> None :
179
180
address = IPAddress ([])
180
181
self .assertEqual ([], address .risk_reasons )
181
182
182
- def test_score_ip_address (self ):
183
+ def test_score_ip_address (self ) -> None :
183
184
address = ScoreIPAddress (risk = 99 )
184
185
self .assertEqual (99 , address .risk )
185
186
186
- def test_ip_address_locales (self ):
187
+ def test_ip_address_locales (self ) -> None :
187
188
loc = IPAddress (
188
189
["fr" ],
189
190
country = {"names" : {"fr" : "Country" }},
@@ -193,7 +194,7 @@ def test_ip_address_locales(self):
193
194
self .assertEqual ("City" , loc .city .name )
194
195
self .assertEqual ("Country" , loc .country .name )
195
196
196
- def test_issuer (self ):
197
+ def test_issuer (self ) -> None :
197
198
phone = "132-342-2131"
198
199
199
200
issuer = Issuer (
@@ -208,7 +209,7 @@ def test_issuer(self):
208
209
self .assertEqual (phone , issuer .phone_number )
209
210
self .assertEqual (True , issuer .matches_provided_phone_number )
210
211
211
- def test_phone (self ):
212
+ def test_phone (self ) -> None :
212
213
phone = Phone (
213
214
country = "US" ,
214
215
is_voip = True ,
@@ -221,7 +222,7 @@ def test_phone(self):
221
222
self .assertEqual ("Verizon/1" , phone .network_operator )
222
223
self .assertEqual ("fixed" , phone .number_type )
223
224
224
- def test_warning (self ):
225
+ def test_warning (self ) -> None :
225
226
code = "INVALID_INPUT"
226
227
msg = "Input invalid"
227
228
@@ -231,7 +232,7 @@ def test_warning(self):
231
232
self .assertEqual (msg , warning .warning )
232
233
self .assertEqual ("/first/second" , warning .input_pointer )
233
234
234
- def test_reason (self ):
235
+ def test_reason (self ) -> None :
235
236
code = "EMAIL_ADDRESS_NEW"
236
237
msg = "Riskiness of newly-sighted email address"
237
238
@@ -240,7 +241,7 @@ def test_reason(self):
240
241
self .assertEqual (code , reason .code )
241
242
self .assertEqual (msg , reason .reason )
242
243
243
- def test_risk_score_reason (self ):
244
+ def test_risk_score_reason (self ) -> None :
244
245
multiplier = 0.34
245
246
code = "EMAIL_ADDRESS_NEW"
246
247
msg = "Riskiness of newly-sighted email address"
@@ -254,7 +255,7 @@ def test_risk_score_reason(self):
254
255
self .assertEqual (code , reason .reasons [0 ].code )
255
256
self .assertEqual (msg , reason .reasons [0 ].reason )
256
257
257
- def test_score (self ):
258
+ def test_score (self ) -> None :
258
259
id = "b643d445-18b2-4b9d-bad4-c9c4366e402a"
259
260
response = {
260
261
"id" : id ,
@@ -264,7 +265,7 @@ def test_score(self):
264
265
"ip_address" : {"risk" : 99 },
265
266
"warnings" : [{"code" : "INVALID_INPUT" }],
266
267
}
267
- score = Score (** response )
268
+ score = Score (** response ) # type: ignore[arg-type]
268
269
269
270
self .assertEqual (id , score .id )
270
271
self .assertEqual (10.01 , score .funds_remaining )
@@ -275,17 +276,17 @@ def test_score(self):
275
276
276
277
self .assertEqual (response , score .to_dict ())
277
278
278
- def test_insights (self ):
279
+ def test_insights (self ) -> None :
279
280
response = self .factors_response ()
280
281
del response ["risk_score_reasons" ]
281
282
del response ["subscores" ]
282
- insights = Insights (None , ** response )
283
+ insights = Insights (None , ** response ) # type: ignore[arg-type]
283
284
self .check_insights_data (insights , response ["id" ])
284
285
self .assertEqual (response , insights .to_dict ())
285
286
286
- def test_factors (self ):
287
+ def test_factors (self ) -> None :
287
288
response = self .factors_response ()
288
- factors = Factors (None , ** response )
289
+ factors = Factors (None , ** response ) # type: ignore[arg-type]
289
290
self .check_insights_data (factors , response ["id" ])
290
291
self .check_risk_score_reasons_data (factors .risk_score_reasons )
291
292
self .assertEqual (0.01 , factors .subscores .avs_result )
@@ -317,7 +318,7 @@ def test_factors(self):
317
318
318
319
self .assertEqual (response , factors .to_dict ())
319
320
320
- def factors_response (self ):
321
+ def factors_response (self ) -> dict [ str , Any ] :
321
322
return {
322
323
"id" : "b643d445-18b2-4b9d-bad4-c9c4366e402a" ,
323
324
"disposition" : {"action" : "reject" },
@@ -373,7 +374,7 @@ def factors_response(self):
373
374
],
374
375
}
375
376
376
- def check_insights_data (self , insights , uuid ):
377
+ def check_insights_data (self , insights , uuid ) -> None :
377
378
self .assertEqual ("US" , insights .ip_address .country .iso_code )
378
379
self .assertEqual (False , insights .ip_address .country .is_in_european_union )
379
380
self .assertEqual (True , insights .credit_card .is_business )
@@ -395,7 +396,7 @@ def check_insights_data(self, insights, uuid):
395
396
self .assertEqual ("INVALID_INPUT" , insights .warnings [0 ].code )
396
397
self .assertIsInstance (insights .warnings , list , "warnings is a list" )
397
398
398
- def check_risk_score_reasons_data (self , reasons ):
399
+ def check_risk_score_reasons_data (self , reasons ) -> None :
399
400
self .assertEqual (1 , len (reasons ))
400
401
self .assertEqual (45 , reasons [0 ].multiplier )
401
402
self .assertEqual (1 , len (reasons [0 ].reasons ))
0 commit comments