|
17 | 17 | import urllib3
|
18 | 18 |
|
19 | 19 | from fingerprint_pro_server_api_sdk import (Configuration, ErrorResponse, ErrorPlainResponse, ErrorCode,
|
20 |
| - RawDeviceAttributes, EventsUpdateRequest) |
| 20 | + RawDeviceAttributes, EventsUpdateRequest, RelatedVisitorsResponse) |
21 | 21 | from fingerprint_pro_server_api_sdk.api.fingerprint_api import FingerprintApi # noqa: E501
|
22 | 22 | from fingerprint_pro_server_api_sdk.rest import KnownApiException, ApiException
|
23 | 23 | from urllib.parse import urlencode
|
|
61 | 61 | MOCK_UPDATE_EVENT_404 = '404_request_not_found.json' # errors/
|
62 | 62 | MOCK_UPDATE_EVENT_409 = '409_state_not_ready.json' # errors/
|
63 | 63 |
|
| 64 | +MOCK_GET_RELATED_VISITORS_200= 'related-visitors/get_related_visitors_200.json' |
| 65 | + |
64 | 66 | class MockPoolManager(object):
|
65 | 67 |
|
66 | 68 |
|
@@ -109,6 +111,10 @@ def request(self, *args, **kwargs):
|
109 | 111 | if mock_file_by_first_argument == 'update_event':
|
110 | 112 | return urllib3.HTTPResponse(status=200, body='OK')
|
111 | 113 | 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 | + |
112 | 118 | path = './test/mocks/' + mock_file_by_first_argument
|
113 | 119 |
|
114 | 120 | if not os.path.isfile(path):
|
@@ -160,6 +166,15 @@ def get_events_path(request_id, region='us'):
|
160 | 166 | }.get(region, "api.fpjs.io")
|
161 | 167 | return 'https://%s/events/%s' % (domain, request_id)
|
162 | 168 |
|
| 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 | + |
163 | 178 | def test_get_visits_correct_data(self):
|
164 | 179 | """Test checks correct code run result in default scenario"""
|
165 | 180 | mock_pool = MockPoolManager(self)
|
@@ -558,6 +573,17 @@ def test_get_event_wrong_shape(self):
|
558 | 573 | self.assertIsInstance(context.exception.reason, ValueError)
|
559 | 574 | self.assertEqual(context.exception.body, raw_file_data)
|
560 | 575 |
|
| 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 | + |
561 | 587 |
|
562 | 588 | if __name__ == '__main__':
|
563 | 589 | unittest.main()
|
0 commit comments