@@ -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' ,
0 commit comments