Skip to content

Commit 7921dc7

Browse files
committed
fix py3 test call args
1 parent 9612015 commit 7921dc7

4 files changed

Lines changed: 40 additions & 21 deletions

File tree

identify/resources/base_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import six
55
from identify.util import validation
66
from identify.util.logger import LOGGER
7-
from identify.util.abstract_extra import classabstract, staticabstract
7+
from identify.util.abstract_extra import classabstract
88
from identify.util import camelcase
99
from identify.util.exceptions import HTTPResponseError, \
1010
EndpointNotImplemented, UnknownIdentifyClientError

identify/tests/resources/test_identity.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,44 @@ def test_create_many(self, mocker):
6464
mocker.patch('identify.http_clients.sync_client.SyncHttpClient.make_request')
6565
sc = SyncHttpClient('abc', 'abc')
6666
entities = {
67-
'key1': { 'asd': 1},
68-
'key2': { 'asd': 2},
67+
'key1': {'asd': 1},
68+
'key2': {'asd': 2},
6969
}
7070
Identity.create_many(sc, '123', '456', entities)
71-
SyncHttpClient.make_request.assert_called_once_with(
72-
Identity._endpoint['create_many'],
73-
[{
74-
'key': 'key2',
75-
'trafficTypeId': '123',
76-
'environmentId': '456',
77-
'values': {'asd': 2},
7871

79-
},
80-
{
81-
'key': 'key1',
82-
'trafficTypeId': '123',
83-
'environmentId': '456',
84-
'values': {'asd': 1},
85-
}],
72+
# Because Python2 & Python3 use different hash functions to bucket
73+
# dictionary keys, any identity may come first, so we need to assert
74+
# that make_request has been called with either the 'key1' identity
75+
# first or the 'key2' identity first
76+
77+
ikey1 = {
78+
'key': 'key1',
79+
'trafficTypeId': '123',
80+
'environmentId': '456',
81+
'values': {'asd': 1},
82+
}
83+
ikey2 = {
84+
'key': 'key2',
85+
'trafficTypeId': '123',
86+
'environmentId': '456',
87+
'values': {'asd': 2},
88+
}
89+
90+
call1 = mocker.call(
91+
Identity._endpoint['create_many'],
92+
[ikey1, ikey2],
8693
trafficTypeId='123',
87-
environmentId='456',
94+
environmentId='456'
8895
)
96+
call2 = mocker.call(
97+
Identity._endpoint['create_many'],
98+
[ikey2, ikey1],
99+
trafficTypeId='123',
100+
environmentId='456'
101+
)
102+
103+
assert ((call1 == SyncHttpClient.make_request.call_args) or
104+
(call2 == SyncHttpClient.make_request.call_args))
89105

90106
def test_update(self, mocker):
91107
'''
@@ -144,7 +160,7 @@ def test_update_this(self, mocker):
144160
mocker.patch('identify.resources.identity.Identity.update')
145161
sc = SyncHttpClient('abc', 'abc')
146162
attr = Identity(sc, 'key', '123', '456', {'asd': '1'})
147-
attr.update_this({'asd':'2'})
163+
attr.update_this({'asd': '2'})
148164
Identity.update.assert_called_once_with(
149165
sc,
150166
'key',
@@ -159,7 +175,7 @@ def test_patch_this(self, mocker):
159175
mocker.patch('identify.resources.identity.Identity.patch')
160176
sc = SyncHttpClient('abc', 'abc')
161177
attr = Identity(sc, 'key', '123', '456', {'asd': '1'})
162-
attr.patch_this({'qwe':'3'})
178+
attr.patch_this({'qwe': '3'})
163179
Identity.patch.assert_called_once_with(
164180
sc,
165181
'key',

identify/util/validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def is_correct_type(value, schema_type):
1515
'''
1616
'''
17-
validator = _validators.get(schema_type)
17+
validator = _validators.get(schema_type.lower())
1818
if validator is not None:
1919
return validator(value)
2020
else:

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[aliases]
22
test=pytest
3+
4+
[tool:pytest]
5+
addopts = --verbose

0 commit comments

Comments
 (0)