Skip to content

Commit 691d02a

Browse files
chore: add changeset and first test
1 parent 292a22f commit 691d02a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

.changeset/giant-dolls-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"fingerprint-pro-server-api-python-sdk": minor
3+
---
4+
5+
Add Related Visitors API

test/test_fingerprint_api.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import urllib3
1818

1919
from fingerprint_pro_server_api_sdk import (Configuration, ErrorResponse, ErrorPlainResponse, ErrorCode,
20-
RawDeviceAttributes, EventsUpdateRequest)
20+
RawDeviceAttributes, EventsUpdateRequest, RelatedVisitorsResponse)
2121
from fingerprint_pro_server_api_sdk.api.fingerprint_api import FingerprintApi # noqa: E501
2222
from fingerprint_pro_server_api_sdk.rest import KnownApiException, ApiException
2323
from urllib.parse import urlencode
@@ -61,6 +61,8 @@
6161
MOCK_UPDATE_EVENT_404 = '404_request_not_found.json' # errors/
6262
MOCK_UPDATE_EVENT_409 = '409_state_not_ready.json' # errors/
6363

64+
MOCK_GET_RELATED_VISITORS_200= 'related-visitors/get_related_visitors_200.json'
65+
6466
class MockPoolManager(object):
6567

6668

@@ -109,6 +111,10 @@ def request(self, *args, **kwargs):
109111
if mock_file_by_first_argument == 'update_event':
110112
return urllib3.HTTPResponse(status=200, body='OK')
111113
try:
114+
if mock_file_by_first_argument == 'related-visitors':
115+
# Extract file name from visitor_id param
116+
mock_file_by_first_argument = r[1]['fields'][1][1]
117+
112118
path = './test/mocks/' + mock_file_by_first_argument
113119

114120
if not os.path.isfile(path):
@@ -160,6 +166,15 @@ def get_events_path(request_id, region='us'):
160166
}.get(region, "api.fpjs.io")
161167
return 'https://%s/events/%s' % (domain, request_id)
162168

169+
@staticmethod
170+
def get_related_visitors_path(region='us'):
171+
domain = {
172+
"us": "api.fpjs.io",
173+
"eu": "eu.api.fpjs.io",
174+
"ap": "ap.api.fpjs.io",
175+
}.get(region, "api.fpjs.io")
176+
return 'https://%s/related-visitors' % domain
177+
163178
def test_get_visits_correct_data(self):
164179
"""Test checks correct code run result in default scenario"""
165180
mock_pool = MockPoolManager(self)
@@ -558,6 +573,17 @@ def test_get_event_wrong_shape(self):
558573
self.assertIsInstance(context.exception.reason, ValueError)
559574
self.assertEqual(context.exception.body, raw_file_data)
560575

576+
def test_get_related_visitors(self):
577+
"""Test that get related visitors returns correct response"""
578+
mock_pool = MockPoolManager(self)
579+
self.api.api_client.rest_client.pool_manager = mock_pool
580+
mock_pool.expect_request('GET', TestFingerprintApi.get_related_visitors_path(),
581+
fields=[self.integration_info, ('visitor_id', MOCK_GET_RELATED_VISITORS_200)], headers=self.request_headers,
582+
preload_content=True, timeout=None)
583+
584+
response = self.api.get_related_visitors(MOCK_GET_RELATED_VISITORS_200)
585+
self.assertIsInstance(response, RelatedVisitorsResponse)
586+
561587

562588
if __name__ == '__main__':
563589
unittest.main()

0 commit comments

Comments
 (0)