@@ -17,7 +17,7 @@ def setUp(self) -> None:
17
17
def tearDown (self ) -> None :
18
18
self .client .shutdown ()
19
19
20
- def test_track_success (self ):
20
+ def test_amplitude_client_track_success (self ):
21
21
post_method = MagicMock ()
22
22
HttpClient .post = post_method
23
23
res = Response (HttpStatus .SUCCESS )
@@ -40,7 +40,7 @@ def callback_func(event, code, message=None):
40
40
self .assertEqual (25 , len (events ))
41
41
post_method .assert_called ()
42
42
43
- def test_track_invalid_api_key (self ):
43
+ def test_amplitude_client_track_invalid_api_key_log_error (self ):
44
44
post_method = MagicMock ()
45
45
HttpClient .post = post_method
46
46
res = Response (HttpStatus .INVALID_REQUEST )
@@ -57,7 +57,7 @@ def test_track_invalid_api_key(self):
57
57
post_method .assert_called_once ()
58
58
self .assertEqual (["ERROR:test:Invalid API Key" ], cm .output )
59
59
60
- def test_track_invalid (self ):
60
+ def test_amplitude_client_track_invalid_response_then_success_response (self ):
61
61
post_method = MagicMock ()
62
62
HttpClient .post = post_method
63
63
invalid_res = Response (HttpStatus .INVALID_REQUEST )
@@ -97,7 +97,7 @@ def callback_func(event, code, message=None):
97
97
self .assertEqual ([(1 , 0 ), (2 , 0 ), (5 , 0 ), (6 , 0 ), (8 , 0 ),
98
98
(0 , 1 ), (3 , 1 ), (4 , 1 ), (7 , 1 ), (9 , 1 )], events )
99
99
100
- def test_identify (self ):
100
+ def test_amplitude_client_identify_invalid_log_error_then_success (self ):
101
101
post_method = MagicMock ()
102
102
HttpClient .post = post_method
103
103
res = Response (HttpStatus .SUCCESS )
@@ -118,14 +118,19 @@ def callback_func(event, code, message=None):
118
118
self .client .configuration .use_batch = use_batch
119
119
identify_obj = Identify ()
120
120
self .assertFalse (identify_obj .is_valid ())
121
+ with self .assertLogs ("test" , "ERROR" ) as cm :
122
+ self .client .configuration .logger = logging .getLogger ("test" )
123
+ self .client .identify (identify_obj ,
124
+ EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
125
+ self .assertEqual (["ERROR:test:Empty identify properties" ], cm .output )
121
126
identify_obj .set ("birth_date" , "4-1-2022" )
122
127
self .assertTrue (identify_obj .is_valid ())
123
128
self .assertEqual ({"$set" : {"birth_date" : "4-1-2022" }}, identify_obj .user_properties )
124
129
self .client .identify (identify_obj , EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
125
130
self .client .flush ()
126
131
post_method .assert_called_once ()
127
132
128
- def test_group_identify (self ):
133
+ def test_amplitude_client_group_identify_invalid_log_error_then_success (self ):
129
134
post_method = MagicMock ()
130
135
HttpClient .post = post_method
131
136
res = Response (HttpStatus .SUCCESS )
@@ -147,6 +152,11 @@ def callback_func(event, code, message=None):
147
152
self .client .configuration .use_batch = use_batch
148
153
identify_obj = Identify ()
149
154
self .assertFalse (identify_obj .is_valid ())
155
+ with self .assertLogs ("test" , "ERROR" ) as cm :
156
+ self .client .configuration .logger = logging .getLogger ("test" )
157
+ self .client .group_identify ("Sports" , "Football" , identify_obj ,
158
+ EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
159
+ self .assertEqual (["ERROR:test:Empty group identify properties" ], cm .output )
150
160
identify_obj .set ("team_name" , "Super Power" )
151
161
self .assertTrue (identify_obj .is_valid ())
152
162
self .assertEqual ({"$set" : {"team_name" : "Super Power" }}, identify_obj .user_properties )
@@ -155,7 +165,32 @@ def callback_func(event, code, message=None):
155
165
self .client .flush ()
156
166
post_method .assert_called_once ()
157
167
158
- def test_revenue (self ):
168
+ def test_amplitude_set_group_success (self ):
169
+ post_method = MagicMock ()
170
+ HttpClient .post = post_method
171
+ res = Response (HttpStatus .SUCCESS )
172
+ post_method .return_value = res
173
+
174
+ def callback_func (event , code , message = None ):
175
+ self .assertEqual (200 , code )
176
+ self .assertTrue (isinstance (event , IdentifyEvent ))
177
+ self .assertTrue ("user_properties" in event )
178
+ self .assertEqual ("$identify" , event ["event_type" ])
179
+ self .assertEqual ("test_user_id" , event ["user_id" ])
180
+ self .assertEqual ("test_device_id" , event ["device_id" ])
181
+ self .assertEqual ({"$set" : {"type" : ["test_group" , "test_group_2" ]}}, event .user_properties )
182
+
183
+ self .client .configuration .callback = callback_func
184
+ for use_batch in (True , False ):
185
+ with self .subTest (use_batch = use_batch ):
186
+ post_method .reset_mock ()
187
+ self .client .configuration .use_batch = use_batch
188
+ self .client .set_group ("type" , ["test_group" , "test_group_2" ],
189
+ EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
190
+ self .client .flush ()
191
+ post_method .assert_called_once ()
192
+
193
+ def test_amplitude_client_revenue_invalid_log_error_then_success (self ):
159
194
post_method = MagicMock ()
160
195
HttpClient .post = post_method
161
196
res = Response (HttpStatus .SUCCESS )
@@ -169,7 +204,7 @@ def callback_func(event, code, message=None):
169
204
self .assertEqual ("test_user_id" , event ["user_id" ])
170
205
self .assertEqual ("test_device_id" , event ["device_id" ])
171
206
self .assertEqual ({'$price' : 60.2 , '$productId' : 'P63' , '$quantity' : 3 , '$receipt' : 'A0001' ,
172
- '$receiptSig' : '0001A' , '$revenue' : None , '$revenueType' : None , ' other_property' : 'test' },
207
+ '$receiptSig' : '0001A' , 'other_property' : 'test' },
173
208
event ["event_properties" ])
174
209
175
210
self .client .configuration .callback = callback_func
@@ -179,14 +214,18 @@ def callback_func(event, code, message=None):
179
214
self .client .configuration .use_batch = use_batch
180
215
revenue_obj = Revenue (price = "abc" , quantity = 3 , product_id = "P63" , properties = {"other_property" : "test" })
181
216
self .assertFalse (revenue_obj .is_valid ())
217
+ with self .assertLogs ("test" , "ERROR" ) as cm :
218
+ self .client .configuration .logger = logging .getLogger ("test" )
219
+ self .client .revenue (revenue_obj , EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
220
+ self .assertEqual (["ERROR:test:Invalid price for revenue event" ], cm .output )
182
221
revenue_obj .price = 60.2
183
222
self .assertTrue (revenue_obj .is_valid ())
184
223
revenue_obj .set_receipt ("A0001" , "0001A" )
185
224
self .client .revenue (revenue_obj , EventOptions (user_id = "test_user_id" , device_id = "test_device_id" ))
186
225
self .client .flush ()
187
226
post_method .assert_called_once ()
188
227
189
- def test_flush (self ):
228
+ def test_amplitude_client_flush_success (self ):
190
229
post_method = MagicMock ()
191
230
HttpClient .post = post_method
192
231
res = Response (HttpStatus .SUCCESS )
@@ -210,7 +249,7 @@ def callback_func(event, code, message=None):
210
249
self .client .flush ()
211
250
post_method .assert_called_once ()
212
251
213
- def test_add_remove (self ):
252
+ def test_amplitude_add_remove_plugins_success (self ):
214
253
timeline = self .client ._Amplitude__timeline
215
254
before_plugin = EventPlugin (PluginType .BEFORE )
216
255
enrich_plugin = EventPlugin (plugin_type = PluginType .ENRICHMENT )
0 commit comments