Skip to content

Commit 10d0b14

Browse files
committed
test: assert unordered fields via Counter
Removes flatten function and use Counter to assert unordered fields on request
1 parent dba8914 commit 10d0b14

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

test/test_fingerprint_api.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@ def expect_request(self, *args, **kwargs):
8989
def get_mock_from_path(path):
9090
return path.split('/')[-1]
9191

92-
@staticmethod
93-
def _flatten(fields):
94-
flatten = []
95-
for k, obj in fields:
96-
if isinstance(obj, list):
97-
flatten.extend((k, v) for v in obj)
98-
else:
99-
flatten.append((k, obj))
100-
return flatten
101-
10292
def request(self, *args, **kwargs):
10393
self._tc.assertTrue(len(self._reqs) > 0)
10494
(request_method, request_url), request_config = self._reqs.pop(0)
@@ -117,12 +107,7 @@ def request(self, *args, **kwargs):
117107
self._tc.assertEqual(request_url, args[1])
118108

119109
self._tc.assertEqual(set(request_config.keys()), set(kwargs.keys()))
120-
for k in request_config.keys() - { 'fields' }:
121-
self._tc.assertEqual(request_config[k], kwargs[k], msg=f"Mismatch on request key: '{k}'")
122-
123-
expected_fields = MockPoolManager._flatten(request_config.get('fields', []))
124-
actual_fields = MockPoolManager._flatten(kwargs.get('fields', []))
125-
self._tc.assertEqual(Counter(expected_fields), Counter(actual_fields), msg="fields on request do not match")
110+
self._tc.assertEqual(Counter(kwargs['fields']), Counter(request_config['fields']))
126111

127112
# TODO Add support for more complex paths?
128113
mock_file_by_first_argument = MockPoolManager.get_mock_from_path(request_path)
@@ -715,7 +700,7 @@ def test_search_events_only_limit(self):
715700

716701
def test_search_events_all_params(self):
717702
"""Test that search events returns 200 with all params"""
718-
params = {
703+
base_params = {
719704
'limit': 100,
720705
'visitor_id': MOCK_SEARCH_EVENTS_200,
721706
'bot': 'good',
@@ -747,10 +732,13 @@ def test_search_events_all_params(self):
747732
'proxy': True,
748733
'sdk_version': 'testSdkVersion',
749734
'sdk_platform': 'testSdkPlatform',
750-
'environment': ["env1", "env2"]
751735
}
736+
multivalue_params = [
737+
('environment', 'env1'),
738+
('environment', 'env2'),
739+
]
752740

753-
expected_fields = [self.integration_info] + list(params.items())
741+
expected_fields = [self.integration_info] + list(base_params.items()) + multivalue_params
754742

755743
mock_pool = MockPoolManager(self)
756744
self.api.api_client.rest_client.pool_manager = mock_pool
@@ -763,7 +751,11 @@ def test_search_events_all_params(self):
763751
timeout=None
764752
)
765753

766-
response = self.api.search_events(**params)
754+
multi = {}
755+
for k, v in multivalue_params:
756+
multi.setdefault(k, []).append(v)
757+
758+
response = self.api.search_events(**base_params, **multi)
767759

768760
self.assertIsInstance(response, SearchEventsResponse)
769761
event_response = response.events[0]

0 commit comments

Comments
 (0)