@@ -30,7 +30,7 @@ def clear(self):
30
30
self .log = []
31
31
32
32
33
- class TestMixpanel :
33
+ class TestMixpanelBase :
34
34
TOKEN = '12345'
35
35
36
36
def setup_method (self , method ):
@@ -39,6 +39,9 @@ def setup_method(self, method):
39
39
self .mp ._now = lambda : 1000.1
40
40
self .mp ._make_insert_id = lambda : "abcdefg"
41
41
42
+
43
+ class TestMixpanelTracking (TestMixpanelBase ):
44
+
42
45
def test_track (self ):
43
46
self .mp .track ('ID' , 'button press' , {'size' : 'big' , 'color' : 'blue' , '$insert_id' : 'abc123' })
44
47
assert self .consumer .log == [(
@@ -49,7 +52,7 @@ def test_track(self):
49
52
'size' : 'big' ,
50
53
'color' : 'blue' ,
51
54
'distinct_id' : 'ID' ,
52
- 'time' : int ( self .mp ._now () ),
55
+ 'time' : self .mp ._now (),
53
56
'$insert_id' : 'abc123' ,
54
57
'mp_lib' : 'python' ,
55
58
'$lib_version' : mixpanel .__version__ ,
@@ -72,7 +75,7 @@ def test_track_empty(self):
72
75
'properties' : {
73
76
'token' : self .TOKEN ,
74
77
'distinct_id' : 'person_xyz' ,
75
- 'time' : int ( self .mp ._now () ),
78
+ 'time' : self .mp ._now (),
76
79
'$insert_id' : self .mp ._make_insert_id (),
77
80
'mp_lib' : 'python' ,
78
81
'$lib_version' : mixpanel .__version__ ,
@@ -93,7 +96,7 @@ def test_import_data(self):
93
96
'size' : 'big' ,
94
97
'color' : 'blue' ,
95
98
'distinct_id' : 'ID' ,
96
- 'time' : int ( timestamp ) ,
99
+ 'time' : timestamp ,
97
100
'$insert_id' : 'abc123' ,
98
101
'mp_lib' : 'python' ,
99
102
'$lib_version' : mixpanel .__version__ ,
@@ -113,7 +116,7 @@ def test_track_meta(self):
113
116
'size' : 'big' ,
114
117
'color' : 'blue' ,
115
118
'distinct_id' : 'ID' ,
116
- 'time' : int ( self .mp ._now () ),
119
+ 'time' : self .mp ._now (),
117
120
'$insert_id' : 'abc123' ,
118
121
'mp_lib' : 'python' ,
119
122
'$lib_version' : mixpanel .__version__ ,
@@ -122,11 +125,14 @@ def test_track_meta(self):
122
125
}
123
126
)]
124
127
128
+
129
+ class TestMixpanelPeople (TestMixpanelBase ):
130
+
125
131
def test_people_set (self ):
126
132
self .mp .people_set ('amq' , {'birth month' : 'october' , 'favorite color' : 'purple' })
127
133
assert self .consumer .log == [(
128
134
'people' , {
129
- '$time' : int ( self .mp ._now () ),
135
+ '$time' : self .mp ._now (),
130
136
'$token' : self .TOKEN ,
131
137
'$distinct_id' : 'amq' ,
132
138
'$set' : {
@@ -140,7 +146,7 @@ def test_people_set_once(self):
140
146
self .mp .people_set_once ('amq' , {'birth month' : 'october' , 'favorite color' : 'purple' })
141
147
assert self .consumer .log == [(
142
148
'people' , {
143
- '$time' : int ( self .mp ._now () ),
149
+ '$time' : self .mp ._now (),
144
150
'$token' : self .TOKEN ,
145
151
'$distinct_id' : 'amq' ,
146
152
'$set_once' : {
@@ -154,7 +160,7 @@ def test_people_increment(self):
154
160
self .mp .people_increment ('amq' , {'Albums Released' : 1 })
155
161
assert self .consumer .log == [(
156
162
'people' , {
157
- '$time' : int ( self .mp ._now () ),
163
+ '$time' : self .mp ._now (),
158
164
'$token' : self .TOKEN ,
159
165
'$distinct_id' : 'amq' ,
160
166
'$add' : {
@@ -167,7 +173,7 @@ def test_people_append(self):
167
173
self .mp .people_append ('amq' , {'birth month' : 'october' , 'favorite color' : 'purple' })
168
174
assert self .consumer .log == [(
169
175
'people' , {
170
- '$time' : int ( self .mp ._now () ),
176
+ '$time' : self .mp ._now (),
171
177
'$token' : self .TOKEN ,
172
178
'$distinct_id' : 'amq' ,
173
179
'$append' : {
@@ -181,7 +187,7 @@ def test_people_union(self):
181
187
self .mp .people_union ('amq' , {'Albums' : ['Diamond Dogs' ]})
182
188
assert self .consumer .log == [(
183
189
'people' , {
184
- '$time' : int ( self .mp ._now () ),
190
+ '$time' : self .mp ._now (),
185
191
'$token' : self .TOKEN ,
186
192
'$distinct_id' : 'amq' ,
187
193
'$union' : {
@@ -194,7 +200,7 @@ def test_people_unset(self):
194
200
self .mp .people_unset ('amq' , ['Albums' , 'Singles' ])
195
201
assert self .consumer .log == [(
196
202
'people' , {
197
- '$time' : int ( self .mp ._now () ),
203
+ '$time' : self .mp ._now (),
198
204
'$token' : self .TOKEN ,
199
205
'$distinct_id' : 'amq' ,
200
206
'$unset' : ['Albums' , 'Singles' ],
@@ -205,7 +211,7 @@ def test_people_remove(self):
205
211
self .mp .people_remove ('amq' , {'Albums' : 'Diamond Dogs' })
206
212
assert self .consumer .log == [(
207
213
'people' , {
208
- '$time' : int ( self .mp ._now () ),
214
+ '$time' : self .mp ._now (),
209
215
'$token' : self .TOKEN ,
210
216
'$distinct_id' : 'amq' ,
211
217
'$remove' : {'Albums' : 'Diamond Dogs' },
@@ -216,7 +222,7 @@ def test_people_track_charge(self):
216
222
self .mp .people_track_charge ('amq' , 12.65 , {'$time' : '2013-04-01T09:02:00' })
217
223
assert self .consumer .log == [(
218
224
'people' , {
219
- '$time' : int ( self .mp ._now () ),
225
+ '$time' : self .mp ._now (),
220
226
'$token' : self .TOKEN ,
221
227
'$distinct_id' : 'amq' ,
222
228
'$append' : {
@@ -232,7 +238,7 @@ def test_people_track_charge_without_properties(self):
232
238
self .mp .people_track_charge ('amq' , 12.65 )
233
239
assert self .consumer .log == [(
234
240
'people' , {
235
- '$time' : int ( self .mp ._now () ),
241
+ '$time' : self .mp ._now (),
236
242
'$token' : self .TOKEN ,
237
243
'$distinct_id' : 'amq' ,
238
244
'$append' : {
@@ -247,7 +253,7 @@ def test_people_clear_charges(self):
247
253
self .mp .people_clear_charges ('amq' )
248
254
assert self .consumer .log == [(
249
255
'people' , {
250
- '$time' : int ( self .mp ._now () ),
256
+ '$time' : self .mp ._now (),
251
257
'$token' : self .TOKEN ,
252
258
'$distinct_id' : 'amq' ,
253
259
'$unset' : ['$transactions' ],
@@ -259,7 +265,7 @@ def test_people_set_created_date_string(self):
259
265
self .mp .people_set ('amq' , {'$created' : created , 'favorite color' : 'purple' })
260
266
assert self .consumer .log == [(
261
267
'people' , {
262
- '$time' : int ( self .mp ._now () ),
268
+ '$time' : self .mp ._now (),
263
269
'$token' : self .TOKEN ,
264
270
'$distinct_id' : 'amq' ,
265
271
'$set' : {
@@ -274,7 +280,7 @@ def test_people_set_created_date_datetime(self):
274
280
self .mp .people_set ('amq' , {'$created' : created , 'favorite color' : 'purple' })
275
281
assert self .consumer .log == [(
276
282
'people' , {
277
- '$time' : int ( self .mp ._now () ),
283
+ '$time' : self .mp ._now (),
278
284
'$token' : self .TOKEN ,
279
285
'$distinct_id' : 'amq' ,
280
286
'$set' : {
@@ -284,6 +290,26 @@ def test_people_set_created_date_datetime(self):
284
290
}
285
291
)]
286
292
293
+ def test_people_meta (self ):
294
+ self .mp .people_set ('amq' , {'birth month' : 'october' , 'favorite color' : 'purple' },
295
+ meta = {'$ip' : 0 , '$ignore_time' : True })
296
+ assert self .consumer .log == [(
297
+ 'people' , {
298
+ '$time' : self .mp ._now (),
299
+ '$token' : self .TOKEN ,
300
+ '$distinct_id' : 'amq' ,
301
+ '$set' : {
302
+ 'birth month' : 'october' ,
303
+ 'favorite color' : 'purple' ,
304
+ },
305
+ '$ip' : 0 ,
306
+ '$ignore_time' : True ,
307
+ }
308
+ )]
309
+
310
+
311
+ class TestMixpanelIdentity (TestMixpanelBase ):
312
+
287
313
def test_alias (self ):
288
314
# More complicated since alias() forces a synchronous call.
289
315
@@ -333,28 +359,14 @@ def test_merge(self):
333
359
('my_good_api_key' , 'my_secret' ),
334
360
)]
335
361
336
- def test_people_meta (self ):
337
- self .mp .people_set ('amq' , {'birth month' : 'october' , 'favorite color' : 'purple' },
338
- meta = {'$ip' : 0 , '$ignore_time' : True })
339
- assert self .consumer .log == [(
340
- 'people' , {
341
- '$time' : int (self .mp ._now ()),
342
- '$token' : self .TOKEN ,
343
- '$distinct_id' : 'amq' ,
344
- '$set' : {
345
- 'birth month' : 'october' ,
346
- 'favorite color' : 'purple' ,
347
- },
348
- '$ip' : 0 ,
349
- '$ignore_time' : True ,
350
- }
351
- )]
362
+
363
+ class TestMixpanelGroups (TestMixpanelBase ):
352
364
353
365
def test_group_set (self ):
354
366
self .mp .group_set ('company' , 'amq' , {'birth month' : 'october' , 'favorite color' : 'purple' })
355
367
assert self .consumer .log == [(
356
368
'groups' , {
357
- '$time' : int ( self .mp ._now () ),
369
+ '$time' : self .mp ._now (),
358
370
'$token' : self .TOKEN ,
359
371
'$group_key' : 'company' ,
360
372
'$group_id' : 'amq' ,
@@ -369,7 +381,7 @@ def test_group_set_once(self):
369
381
self .mp .group_set_once ('company' , 'amq' , {'birth month' : 'october' , 'favorite color' : 'purple' })
370
382
assert self .consumer .log == [(
371
383
'groups' , {
372
- '$time' : int ( self .mp ._now () ),
384
+ '$time' : self .mp ._now (),
373
385
'$token' : self .TOKEN ,
374
386
'$group_key' : 'company' ,
375
387
'$group_id' : 'amq' ,
@@ -384,7 +396,7 @@ def test_group_union(self):
384
396
self .mp .group_union ('company' , 'amq' , {'Albums' : ['Diamond Dogs' ]})
385
397
assert self .consumer .log == [(
386
398
'groups' , {
387
- '$time' : int ( self .mp ._now () ),
399
+ '$time' : self .mp ._now (),
388
400
'$token' : self .TOKEN ,
389
401
'$group_key' : 'company' ,
390
402
'$group_id' : 'amq' ,
@@ -398,7 +410,7 @@ def test_group_unset(self):
398
410
self .mp .group_unset ('company' , 'amq' , ['Albums' , 'Singles' ])
399
411
assert self .consumer .log == [(
400
412
'groups' , {
401
- '$time' : int ( self .mp ._now () ),
413
+ '$time' : self .mp ._now (),
402
414
'$token' : self .TOKEN ,
403
415
'$group_key' : 'company' ,
404
416
'$group_id' : 'amq' ,
@@ -410,7 +422,7 @@ def test_group_remove(self):
410
422
self .mp .group_remove ('company' , 'amq' , {'Albums' : 'Diamond Dogs' })
411
423
assert self .consumer .log == [(
412
424
'groups' , {
413
- '$time' : int ( self .mp ._now () ),
425
+ '$time' : self .mp ._now (),
414
426
'$token' : self .TOKEN ,
415
427
'$group_key' : 'company' ,
416
428
'$group_id' : 'amq' ,
@@ -438,7 +450,7 @@ def default(self, obj):
438
450
'token' : self .TOKEN ,
439
451
'size' : decimal_string ,
440
452
'distinct_id' : 'ID' ,
441
- 'time' : int ( self .mp ._now () ),
453
+ 'time' : self .mp ._now (),
442
454
'$insert_id' : 'abc123' ,
443
455
'mp_lib' : 'python' ,
444
456
'$lib_version' : mixpanel .__version__ ,
0 commit comments