@@ -30,10 +30,15 @@ def test_amplitude_client_track_success(self):
3030 res = Response (HttpStatus .SUCCESS )
3131 post_method .return_value = res
3232 events = []
33+ self .assertion_errors = []
3334
3435 def callback_func (event , code , message = None ):
35- self .assertEqual (200 , code )
36- events .append (event .event_properties ["id" ])
36+ try :
37+ self .assertEqual (200 , code )
38+ events .append (event .event_properties ["id" ])
39+ self .assertEqual ('USD' , event .currency )
40+ except AssertionError as e :
41+ self .assertion_errors .append (str (e ))
3742
3843 self .client .configuration .callback = callback_func
3944 for use_batch in (True , False ):
@@ -42,12 +47,14 @@ def callback_func(event, code, message=None):
4247 events .clear ()
4348 self .client .configuration .use_batch = use_batch
4449 for i in range (25 ):
45- self .client .track (BaseEvent ("test_event" , "test_user_id" , event_properties = {"id" : i }))
50+ self .client .track (BaseEvent ("test_event" , "test_user_id" ,
51+ event_properties = {"id" : i }, currency = 'USD' ))
4652 for flush_future in self .client .flush ():
4753 if flush_future :
4854 flush_future .result ()
4955 self .assertEqual (25 , len (events ))
5056 post_method .assert_called ()
57+ self .assertEqual (0 , len (self .assertion_errors ))
5158
5259 def test_amplitude_client_track_invalid_api_key_log_error (self ):
5360 post_method = MagicMock ()
@@ -84,13 +91,17 @@ def test_amplitude_client_track_invalid_response_then_success_response(self):
8491 }
8592 success_res = Response (HttpStatus .SUCCESS )
8693 events = []
94+ self .assertion_errors = []
8795
8896 def callback_func (event , code , message = None ):
89- if event .event_properties ["id" ] in (1 , 2 , 5 , 6 , 8 ):
90- self .assertEqual (400 , code )
91- else :
92- self .assertEqual (200 , code )
93- events .append ((event .event_properties ["id" ], event .retry ))
97+ try :
98+ if event .event_properties ["id" ] in (1 , 2 , 5 , 6 , 8 ):
99+ self .assertEqual (400 , code )
100+ else :
101+ self .assertEqual (200 , code )
102+ events .append ((event .event_properties ["id" ], event .retry ))
103+ except AssertionError as e :
104+ self .assertion_errors .append (str (e ))
94105
95106 self .client .configuration .callback = callback_func
96107 for use_batch in (True , False ):
@@ -107,20 +118,25 @@ def callback_func(event, code, message=None):
107118 self .assertEqual (2 , post_method .call_count )
108119 self .assertEqual ([(1 , 0 ), (2 , 0 ), (5 , 0 ), (6 , 0 ), (8 , 0 ),
109120 (0 , 1 ), (3 , 1 ), (4 , 1 ), (7 , 1 ), (9 , 1 )], events )
121+ self .assertEqual (0 , len (self .assertion_errors ))
110122
111123 def test_amplitude_client_identify_invalid_log_error_then_success (self ):
112124 post_method = MagicMock ()
113125 HttpClient .post = post_method
114126 res = Response (HttpStatus .SUCCESS )
115127 post_method .return_value = res
128+ self .assertion_errors = []
116129
117130 def callback_func (event , code , message = None ):
118- self .assertEqual (200 , code )
119- self .assertTrue (isinstance (event , IdentifyEvent ))
120- self .assertTrue ("user_properties" in event )
121- self .assertEqual ("$identify" , event ["event_type" ])
122- self .assertEqual ("test_user_id" , event ["user_id" ])
123- self .assertEqual ("test_device_id" , event ["device_id" ])
131+ try :
132+ self .assertEqual (200 , code )
133+ self .assertTrue (isinstance (event , IdentifyEvent ))
134+ self .assertTrue ("user_properties" in event )
135+ self .assertEqual ("$identify" , event ["event_type" ])
136+ self .assertEqual ("test_user_id" , event ["user_id" ])
137+ self .assertEqual ("test_device_id" , event ["device_id" ])
138+ except AssertionError as e :
139+ self .assertion_errors .append (str (e ))
124140
125141 self .client .configuration .callback = callback_func
126142 for use_batch in (True , False ):
@@ -142,21 +158,26 @@ def callback_func(event, code, message=None):
142158 if flush_future :
143159 flush_future .result ()
144160 post_method .assert_called_once ()
161+ self .assertEqual (0 , len (self .assertion_errors ))
145162
146163 def test_amplitude_client_group_identify_invalid_log_error_then_success (self ):
147164 post_method = MagicMock ()
148165 HttpClient .post = post_method
149166 res = Response (HttpStatus .SUCCESS )
150167 post_method .return_value = res
168+ self .assertion_errors = []
151169
152170 def callback_func (event , code , message = None ):
153- self .assertEqual (200 , code )
154- self .assertTrue (isinstance (event , GroupIdentifyEvent ))
155- self .assertTrue ("group_properties" in event )
156- self .assertEqual ("$groupidentify" , event ["event_type" ])
157- self .assertEqual ("test_user_id" , event ["user_id" ])
158- self .assertEqual ("test_device_id" , event ["device_id" ])
159- self .assertEqual ({"Sports" : "Football" }, event ["groups" ])
171+ try :
172+ self .assertEqual (200 , code )
173+ self .assertTrue (isinstance (event , GroupIdentifyEvent ))
174+ self .assertTrue ("group_properties" in event )
175+ self .assertEqual ("$groupidentify" , event ["event_type" ])
176+ self .assertEqual ("test_user_id" , event ["user_id" ])
177+ self .assertEqual ("test_device_id" , event ["device_id" ])
178+ self .assertEqual ({"Sports" : "Football" }, event ["groups" ])
179+ except AssertionError as e :
180+ self .assertion_errors .append (str (e ))
160181
161182 self .client .configuration .callback = callback_func
162183 for use_batch in (True , False ):
@@ -179,22 +200,27 @@ def callback_func(event, code, message=None):
179200 if flush_future :
180201 flush_future .result ()
181202 post_method .assert_called_once ()
203+ self .assertEqual (0 , len (self .assertion_errors ))
182204
183205 def test_amplitude_set_group_success (self ):
184206 post_method = MagicMock ()
185207 HttpClient .post = post_method
186208 res = Response (HttpStatus .SUCCESS )
187209 post_method .return_value = res
210+ self .assertion_errors = []
188211
189212 def callback_func (event , code , message = None ):
190- self .assertEqual (200 , code )
191- self .assertTrue (isinstance (event , IdentifyEvent ))
192- self .assertTrue ("groups" in event )
193- self .assertEqual ("$identify" , event ["event_type" ])
194- self .assertEqual ("test_user_id" , event ["user_id" ])
195- self .assertEqual ("test_device_id" , event ["device_id" ])
196- self .assertEqual ({"type" : ["test_group" , "test_group_2" ]}, event .groups )
197- self .assertEqual ({"$set" : {"type" : ["test_group" , "test_group_2" ]}}, event .user_properties )
213+ try :
214+ self .assertEqual (200 , code )
215+ self .assertTrue (isinstance (event , IdentifyEvent ))
216+ self .assertTrue ("groups" in event )
217+ self .assertEqual ("$identify" , event ["event_type" ])
218+ self .assertEqual ("test_user_id" , event ["user_id" ])
219+ self .assertEqual ("test_device_id" , event ["device_id" ])
220+ self .assertEqual ({"type" : ["test_group" , "test_group_2" ]}, event .groups )
221+ self .assertEqual ({"$set" : {"type" : ["test_group" , "test_group_2" ]}}, event .user_properties )
222+ except AssertionError as e :
223+ self .assertion_errors .append (str (e ))
198224
199225 self .client .configuration .callback = callback_func
200226 for use_batch in (True , False ):
@@ -207,30 +233,35 @@ def callback_func(event, code, message=None):
207233 if flush_future :
208234 flush_future .result ()
209235 post_method .assert_called_once ()
236+ self .assertEqual (0 , len (self .assertion_errors ))
210237
211238 def test_amplitude_client_revenue_invalid_log_error_then_success (self ):
212239 post_method = MagicMock ()
213240 HttpClient .post = post_method
214241 res = Response (HttpStatus .SUCCESS )
215242 post_method .return_value = res
243+ self .assertion_errors = []
216244
217245 def callback_func (event , code , message = None ):
218- self .assertEqual (200 , code )
219- self .assertTrue (isinstance (event , RevenueEvent ))
220- self .assertTrue ("event_properties" in event )
221- self .assertEqual ("revenue_amount" , event ["event_type" ])
222- self .assertEqual ("test_user_id" , event ["user_id" ])
223- self .assertEqual ("test_device_id" , event ["device_id" ])
224- self .assertEqual ({'$price' : 60.2 , '$productId' : 'P63' , '$quantity' : 3 , '$receipt' : 'A0001' ,
225- '$receiptSig' : '0001A' , 'other_property' : 'test' },
226- event ["event_properties" ])
246+ try :
247+ self .assertEqual (200 , code )
248+ self .assertTrue (isinstance (event , RevenueEvent ))
249+ self .assertTrue ("event_properties" in event )
250+ self .assertEqual ("revenue_amount" , event ["event_type" ])
251+ self .assertEqual ("test_user_id" , event ["user_id" ])
252+ self .assertEqual ("test_device_id" , event ["device_id" ])
253+ self .assertEqual ({'$price' : 60.2 , '$productId' : 'P63' , '$quantity' : 3 , '$receipt' : 'A0001' ,
254+ '$currency' : 'USD' , '$receiptSig' : '0001A' , 'other_property' : 'test' },
255+ event ["event_properties" ])
256+ except AssertionError as e :
257+ self .assertion_errors .append (str (e ))
227258
228259 self .client .configuration .callback = callback_func
229260 for use_batch in (True , False ):
230261 with self .subTest (use_batch = use_batch ):
231262 post_method .reset_mock ()
232263 self .client .configuration .use_batch = use_batch
233- revenue_obj = Revenue (price = "abc" , quantity = 3 , product_id = "P63" , properties = {"other_property" : "test" })
264+ revenue_obj = Revenue (price = "abc" , quantity = 3 , product_id = "P63" , currency = "USD" , properties = {"other_property" : "test" })
234265 self .assertFalse (revenue_obj .is_valid ())
235266 with self .assertLogs ("test" , "ERROR" ) as cm :
236267 self .client .configuration .logger = logging .getLogger ("test" )
@@ -244,18 +275,23 @@ def callback_func(event, code, message=None):
244275 if flush_future :
245276 flush_future .result ()
246277 post_method .assert_called_once ()
278+ self .assertEqual (0 , len (self .assertion_errors ))
247279
248280 def test_amplitude_client_flush_success (self ):
249281 post_method = MagicMock ()
250282 HttpClient .post = post_method
251283 res = Response (HttpStatus .SUCCESS )
252284 post_method .return_value = res
285+ self .assertion_errors = []
253286
254287 def callback_func (event , code , message = None ):
255- self .assertEqual (200 , code )
256- self .assertEqual ("flush_test" , event ["event_type" ])
257- self .assertEqual ("test_user_id" , event ["user_id" ])
258- self .assertEqual ("test_device_id" , event ["device_id" ])
288+ try :
289+ self .assertEqual (200 , code )
290+ self .assertEqual ("flush_test" , event ["event_type" ])
291+ self .assertEqual ("test_user_id" , event ["user_id" ])
292+ self .assertEqual ("test_device_id" , event ["device_id" ])
293+ except AssertionError as e :
294+ self .assertion_errors .append (str (e ))
259295
260296 self .client .configuration .callback = callback_func
261297 for use_batch in (True , False ):
@@ -272,6 +308,7 @@ def callback_func(event, code, message=None):
272308 if flush_future :
273309 flush_future .result ()
274310 post_method .assert_called_once ()
311+ self .assertEqual (0 , len (self .assertion_errors ))
275312
276313 def test_amplitude_add_remove_plugins_success (self ):
277314 timeline = self .client ._Amplitude__timeline
0 commit comments