Skip to content

Commit 9a5ceb2

Browse files
test: fix tests
1 parent e98dbd4 commit 9a5ceb2

File tree

3 files changed

+392
-23
lines changed

3 files changed

+392
-23
lines changed
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
{
2+
"products": {
3+
"identification": {
4+
"data": {
5+
"visitorId": "Ibk1527CUFmcnjLwIs4A9",
6+
"requestId": "1708102555327.NLOjmg",
7+
"incognito": true,
8+
"linkedId": {
9+
"broken": "format"
10+
},
11+
"tag": {},
12+
"time": "2019-05-21T16:40:13Z",
13+
"timestamp": 1582299576512,
14+
"url": "https://www.example.com/login?hope{this{works[!",
15+
"ip": "61.127.217.15",
16+
"ipLocation": {
17+
"accuracyRadius": 10,
18+
"latitude": 49.982,
19+
"longitude": 36.2566,
20+
"postalCode": "61202",
21+
"timezone": "Europe/Dusseldorf",
22+
"city": {
23+
"name": "Dusseldorf"
24+
},
25+
"country": {
26+
"code": "DE",
27+
"name": "Germany"
28+
},
29+
"continent": {
30+
"code": "EU",
31+
"name": "Europe"
32+
},
33+
"subdivisions": [
34+
{
35+
"isoCode": "63",
36+
"name": "North Rhine-Westphalia"
37+
}
38+
]
39+
},
40+
"browserDetails": {
41+
"browserName": "Chrome",
42+
"browserMajorVersion": "74",
43+
"browserFullVersion": "74.0.3729",
44+
"os": "Windows",
45+
"osVersion": "7",
46+
"device": "Other",
47+
"userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) ...."
48+
},
49+
"confidence": {
50+
"score": 0.97
51+
},
52+
"visitorFound": false,
53+
"firstSeenAt": {
54+
"global": "2022-03-16T11:26:45.362Z",
55+
"subscription": "2022-03-16T11:31:01.101Z"
56+
},
57+
"lastSeenAt": {
58+
"global": null,
59+
"subscription": null
60+
}
61+
}
62+
},
63+
"botd": {
64+
"data": {
65+
"bot": {
66+
"result": "notDetected"
67+
},
68+
"url": "https://www.example.com/login?hope{this{works}[!",
69+
"ip": "61.127.217.15",
70+
"time": "2019-05-21T16:40:13Z",
71+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36",
72+
"requestId": "1708102555327.NLOjmg"
73+
}
74+
},
75+
"rootApps": {
76+
"data": {
77+
"result": false
78+
}
79+
},
80+
"emulator": {
81+
"data": {
82+
"result": false
83+
}
84+
},
85+
"ipInfo": {
86+
"data": {
87+
"v4": {
88+
"address": "94.142.239.124",
89+
"geolocation": {
90+
"accuracyRadius": 20,
91+
"latitude": 50.05,
92+
"longitude": 14.4,
93+
"postalCode": "150 00",
94+
"timezone": "Europe/Prague",
95+
"city": {
96+
"name": "Prague"
97+
},
98+
"country": {
99+
"code": "CZ",
100+
"name": "Czechia"
101+
},
102+
"continent": {
103+
"code": "EU",
104+
"name": "Europe"
105+
},
106+
"subdivisions": [
107+
{
108+
"isoCode": "10",
109+
"name": "Hlavni mesto Praha"
110+
}
111+
]
112+
},
113+
"asn": {
114+
"asn": "7922",
115+
"name": "COMCAST-7922",
116+
"network": "73.136.0.0/13"
117+
},
118+
"datacenter": {
119+
"result": true,
120+
"name": "DediPath"
121+
}
122+
},
123+
"v6": {
124+
"address": "2001:db8:3333:4444:5555:6666:7777:8888",
125+
"geolocation": {
126+
"accuracyRadius": 5,
127+
"latitude": 49.982,
128+
"longitude": 36.2566,
129+
"postalCode": "10112",
130+
"timezone": "Europe/Berlin",
131+
"city": {
132+
"name": "Berlin"
133+
},
134+
"country": {
135+
"code": "DE",
136+
"name": "Germany"
137+
},
138+
"continent": {
139+
"code": "EU",
140+
"name": "Europe"
141+
},
142+
"subdivisions": [
143+
{
144+
"isoCode": "BE",
145+
"name": "Land Berlin"
146+
}
147+
]
148+
},
149+
"asn": {
150+
"asn": "6805",
151+
"name": "Telefonica Germany",
152+
"network": "2a02:3100::/24"
153+
},
154+
"datacenter": {
155+
"result": false,
156+
"name": ""
157+
}
158+
}
159+
}
160+
},
161+
"ipBlocklist": {
162+
"data": {
163+
"result": false,
164+
"details": {
165+
"emailSpam": false,
166+
"attackSource": false
167+
}
168+
}
169+
},
170+
"tor": {
171+
"data": {
172+
"result": false
173+
}
174+
},
175+
"vpn": {
176+
"data": {
177+
"result": false,
178+
"originTimezone": "Europe/Berlin",
179+
"originCountry": "unknown",
180+
"methods": {
181+
"timezoneMismatch": false,
182+
"publicVPN": false,
183+
"auxiliaryMobile": false
184+
}
185+
}
186+
},
187+
"proxy": {
188+
"data": {
189+
"result": false
190+
}
191+
},
192+
"incognito": {
193+
"data": {
194+
"result": false
195+
}
196+
},
197+
"tampering": {
198+
"data": {
199+
"result": false,
200+
"anomalyScore": 0.1955
201+
}
202+
},
203+
"clonedApp": {
204+
"data": {
205+
"result": false
206+
}
207+
},
208+
"factoryReset": {
209+
"data": {
210+
"time": "1970-01-01T00:00:00Z",
211+
"timestamp": 0
212+
}
213+
},
214+
"jailbroken": {
215+
"data": {
216+
"result": false
217+
}
218+
},
219+
"frida": {
220+
"data": {
221+
"result": false
222+
}
223+
},
224+
"privacySettings": {
225+
"data": {
226+
"result": false
227+
}
228+
},
229+
"virtualMachine": {
230+
"data": {
231+
"result": false
232+
}
233+
},
234+
"rawDeviceAttributes": {
235+
"data": {
236+
"architecture": {
237+
"value": 127
238+
},
239+
"audio": {
240+
"value": 35.73832903057337
241+
},
242+
"canvas": {
243+
"value": {
244+
"Winding": true,
245+
"Geometry": "4dce9d6017c3e0c052a77252f29f2b1c",
246+
"Text": "dd2474a56ff78c1de3e7a07070ba3b7d"
247+
}
248+
},
249+
"colorDepth": {
250+
"value": 30
251+
},
252+
"colorGamut": {
253+
"value": "p3"
254+
},
255+
"contrast": {
256+
"value": 0
257+
},
258+
"cookiesEnabled": {
259+
"value": true
260+
},
261+
"cpuClass": {},
262+
"fonts": {
263+
"value": [
264+
"Arial Unicode MS",
265+
"Gill Sans",
266+
"Helvetica Neue",
267+
"Menlo"
268+
]
269+
}
270+
}
271+
},
272+
"highActivity": {
273+
"data": {
274+
"result": false
275+
}
276+
},
277+
"locationSpoofing": {
278+
"data": {
279+
"result": false
280+
}
281+
}
282+
}
283+
}

test/test_fingerprint_api.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import io
14+
import os
1415
import unittest
1516

1617
import urllib3
@@ -30,9 +31,14 @@
3031

3132

3233
class MockPoolManager(object):
33-
def __init__(self, tc):
34+
35+
36+
def __init__(self, tc, request_headers=None):
37+
if request_headers is None:
38+
request_headers = {}
3439
self._tc = tc
3540
self._reqs = []
41+
self.request_headers = request_headers
3642

3743
def expect_request(self, *args, **kwargs):
3844
self._reqs.append((args, kwargs))
@@ -72,14 +78,15 @@ def request(self, *args, **kwargs):
7278
if mock_file_by_first_argument == 'update_event':
7379
return urllib3.HTTPResponse(status=200, body='OK')
7480
try:
75-
with io.open('./test/mocks/' + mock_file_by_first_argument, 'r', encoding='utf-8') as mock_file:
81+
path = './test/mocks/' + mock_file_by_first_argument
82+
83+
if not os.path.isfile(path):
84+
path = './test/mocks/shared/' + mock_file_by_first_argument
85+
86+
with io.open(path, 'r', encoding='utf-8') as mock_file:
7687
answer_mock = mock_file.read()
7788
mock_file.close()
78-
headers = {}
79-
if mock_file_by_first_argument == 'get_visits_429_too_many_requests_error.json':
80-
headers.update({'Retry-After': '4'})
81-
82-
return urllib3.HTTPResponse(status=status, body=answer_mock, headers=headers)
89+
return urllib3.HTTPResponse(status=status, body=answer_mock, headers=self.request_headers)
8390
except IOError as e:
8491
print(e)
8592
return urllib3.HTTPResponse(status=200, body='{"visitorId": "%s", "visits": []}' % mock_file_by_first_argument)
@@ -161,7 +168,7 @@ def test_get_visits_error_403(self):
161168

162169
def test_get_visits_error_429(self):
163170
"""Test checks correct code run result in case of 429 error for get_visits method"""
164-
mock_pool = MockPoolManager(self)
171+
mock_pool = MockPoolManager(self, request_headers={'Retry-After': '4'})
165172
self.api.api_client.rest_client.pool_manager = mock_pool
166173
mock_file = 'get_visits_429_too_many_requests_error.json'
167174
mock_pool.expect_request('GET', TestFingerprintApi.get_visitors_path(visitor_id=mock_file),
@@ -177,7 +184,7 @@ def test_get_visits_error_429_empty_retry_after(self):
177184
"""Test checks retry after value in exception in case of 429 error for get_visits method"""
178185
mock_pool = MockPoolManager(self)
179186
self.api.api_client.rest_client.pool_manager = mock_pool
180-
mock_file = 'get_visits_429_too_many_requests_error_empty_header.json'
187+
mock_file = 'get_visits_429_too_many_requests_error.json'
181188
mock_pool.expect_request('GET', TestFingerprintApi.get_visitors_path(visitor_id=mock_file),
182189
fields=[self.integration_info], headers=self.request_headers,
183190
preload_content=True, timeout=None, status=429)
@@ -501,7 +508,7 @@ def test_get_event_wrong_shape(self):
501508
mock_pool = MockPoolManager(self)
502509
self.api.api_client.rest_client.pool_manager = mock_pool
503510

504-
mock_file = 'get_event_200_wrong_shape.json'
511+
mock_file = 'get_event_200_with_broken_format.json'
505512
mock_pool.expect_request('GET', TestFingerprintApi.get_events_path(request_id=mock_file),
506513
fields=[self.integration_info], headers=self.request_headers,
507514
preload_content=True, timeout=None)

0 commit comments

Comments
 (0)