@@ -30,6 +30,10 @@ def _create_event(**kwargs):
30
30
class TestFunnelTrends (ClickhouseTestMixin , APIBaseTest ):
31
31
maxDiff = None
32
32
33
+ def _get_people_at_step (self , filter , entrance_period_start , drop_off , funnel_class = ClickhouseFunnel ):
34
+ person_filter = filter .with_data ({"entrance_period_start" : entrance_period_start , "drop_off" : drop_off })
35
+ return ClickhouseFunnelTrendsPersons (person_filter , self .team , funnel_class ).run ()
36
+
33
37
def _create_sample_data (self ):
34
38
# five people, three steps
35
39
_create_person (distinct_ids = ["user_one" ], team = self .team )
@@ -177,11 +181,9 @@ def test_only_one_user_reached_one_step(self):
177
181
)
178
182
179
183
# 1 user who dropped off starting 2021-06-07
180
- funnel_trends_persons_existent_dropped_off_results , _ = ClickhouseFunnelTrendsPersons (
181
- Filter ({** filter ._data , "entrance_period_start" : "2021-06-07 00:00:00" , "drop_off" : True }),
182
- self .team ,
183
- ClickhouseFunnel ,
184
- ).run ()
184
+ funnel_trends_persons_existent_dropped_off_results , _ = self ._get_people_at_step (
185
+ filter , "2021-06-07 00:00:00" , True
186
+ )
185
187
186
188
self .assertEqual (
187
189
len (funnel_trends_persons_existent_dropped_off_results ), 1 ,
@@ -191,22 +193,18 @@ def test_only_one_user_reached_one_step(self):
191
193
)
192
194
193
195
# No users converted 2021-06-07
194
- funnel_trends_persons_nonexistent_converted_results , _ = ClickhouseFunnelTrendsPersons (
195
- Filter ({** filter ._data , "entrance_period_start" : "2021-06-07 00:00:00" , "drop_off" : False }),
196
- self .team ,
197
- ClickhouseFunnel ,
198
- ).run ()
196
+ funnel_trends_persons_nonexistent_converted_results , _ = self ._get_people_at_step (
197
+ filter , "2021-06-07 00:00:00" , False
198
+ )
199
199
200
200
self .assertEqual (
201
201
len (funnel_trends_persons_nonexistent_converted_results ), 0 ,
202
202
)
203
203
204
204
# No users dropped off 2021-06-08
205
- funnel_trends_persons_nonexistent_converted_results , _ = ClickhouseFunnelTrendsPersons (
206
- Filter ({** filter ._data , "entrance_period_start" : "2021-06-08 00:00:00" , "drop_off" : True }),
207
- self .team ,
208
- ClickhouseFunnel ,
209
- ).run ()
205
+ funnel_trends_persons_nonexistent_converted_results , _ = self ._get_people_at_step (
206
+ filter , "2021-06-08 00:00:00" , True
207
+ )
210
208
211
209
self .assertEqual (
212
210
len (funnel_trends_persons_nonexistent_converted_results ), 0 ,
@@ -248,8 +246,21 @@ def test_day_interval(self):
248
246
],
249
247
}
250
248
)
249
+ _create_person (distinct_ids = ["user_one" ], team = self .team )
250
+
251
+ # full run
252
+ _create_event (event = "step one" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 00:00:00" )
253
+ _create_event (event = "step two" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 01:00:00" )
254
+ _create_event (event = "step three" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 02:00:00" )
255
+
251
256
results = ClickhouseFunnelTrends (filter , self .team , ClickhouseFunnel )._exec_query ()
252
- self .assertEqual (len (results ), 7 )
257
+ self .assertEqual (7 , len (results ))
258
+
259
+ persons , _ = self ._get_people_at_step (filter , "2021-05-01 00:00:00" , False )
260
+
261
+ self .assertEqual (
262
+ [person ["distinct_ids" ] for person in persons ], [["user_one" ]],
263
+ )
253
264
254
265
def test_week_interval (self ):
255
266
filter = Filter (
@@ -267,8 +278,21 @@ def test_week_interval(self):
267
278
],
268
279
}
269
280
)
281
+
282
+ _create_person (distinct_ids = ["user_one" ], team = self .team )
283
+
284
+ # full run
285
+ _create_event (event = "step one" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 00:00:00" )
286
+ _create_event (event = "step two" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 01:00:00" )
287
+ _create_event (event = "step three" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 02:00:00" )
288
+
270
289
results = ClickhouseFunnelTrends (filter , self .team , ClickhouseFunnel )._exec_query ()
290
+ persons , _ = self ._get_people_at_step (filter , "2021-04-25 00:00:00" , False )
291
+
271
292
self .assertEqual (2 , len (results ))
293
+ self .assertEqual (
294
+ [person ["distinct_ids" ] for person in persons ], [["user_one" ]],
295
+ )
272
296
273
297
def test_month_interval (self ):
274
298
filter = Filter (
@@ -286,8 +310,21 @@ def test_month_interval(self):
286
310
],
287
311
}
288
312
)
313
+ _create_person (distinct_ids = ["user_one" ], team = self .team )
314
+
315
+ # full run
316
+ _create_event (event = "step one" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 00:00:00" )
317
+ _create_event (event = "step two" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 01:00:00" )
318
+ _create_event (event = "step three" , distinct_id = "user_one" , team = self .team , timestamp = "2021-05-01 02:00:00" )
319
+
289
320
results = ClickhouseFunnelTrends (filter , self .team , ClickhouseFunnel )._exec_query ()
290
- self .assertEqual (len (results ), 1 )
321
+ self .assertEqual (1 , len (results ))
322
+
323
+ persons , _ = self ._get_people_at_step (filter , "2021-05-01 00:00:00" , False )
324
+
325
+ self .assertEqual (
326
+ [person ["distinct_ids" ] for person in persons ], [["user_one" ]],
327
+ )
291
328
292
329
def test_all_results_for_day_interval (self ):
293
330
self ._create_sample_data ()
@@ -604,11 +641,9 @@ def test_one_person_in_multiple_periods_and_windows(self):
604
641
self .assertEqual (day_4 ["is_period_final" ], True )
605
642
606
643
# 1 user who dropped off starting # 2021-05-04
607
- funnel_trends_persons_existent_dropped_off_results , _ = ClickhouseFunnelTrendsPersons (
608
- Filter ({** filter ._data , "entrance_period_start" : "2021-05-04 00:00:00" , "drop_off" : True }),
609
- self .team ,
610
- ClickhouseFunnel ,
611
- ).run ()
644
+ funnel_trends_persons_existent_dropped_off_results , _ = self ._get_people_at_step (
645
+ filter , "2021-05-04 00:00:00" , True
646
+ )
612
647
613
648
self .assertEqual (
614
649
len (funnel_trends_persons_existent_dropped_off_results ), 1 ,
@@ -618,11 +653,9 @@ def test_one_person_in_multiple_periods_and_windows(self):
618
653
)
619
654
620
655
# 1 user who converted starting # 2021-05-04
621
- funnel_trends_persons_existent_dropped_off_results , _ = ClickhouseFunnelTrendsPersons (
622
- Filter ({** filter ._data , "entrance_period_start" : "2021-05-04 00:00:00" , "drop_off" : False }),
623
- self .team ,
624
- ClickhouseFunnel ,
625
- ).run ()
656
+ funnel_trends_persons_existent_dropped_off_results , _ = self ._get_people_at_step (
657
+ filter , "2021-05-04 00:00:00" , False
658
+ )
626
659
627
660
self .assertEqual (
628
661
len (funnel_trends_persons_existent_dropped_off_results ), 1 ,
@@ -845,11 +878,9 @@ def test_one_person_in_multiple_periods_and_windows_in_unordered_funnel(self):
845
878
self .assertEqual (day_4 ["is_period_final" ], True )
846
879
847
880
# 1 user who dropped off starting # 2021-05-04
848
- funnel_trends_persons_existent_dropped_off_results , _ = ClickhouseFunnelTrendsPersons (
849
- Filter ({** filter ._data , "entrance_period_start" : "2021-05-04 00:00:00" , "drop_off" : True }),
850
- self .team ,
851
- ClickhouseFunnelUnordered ,
852
- ).run ()
881
+ funnel_trends_persons_existent_dropped_off_results , _ = self ._get_people_at_step (
882
+ filter , "2021-05-04 00:00:00" , True , ClickhouseFunnelUnordered
883
+ )
853
884
854
885
self .assertEqual (
855
886
len (funnel_trends_persons_existent_dropped_off_results ), 1 ,
@@ -859,11 +890,9 @@ def test_one_person_in_multiple_periods_and_windows_in_unordered_funnel(self):
859
890
)
860
891
861
892
# 1 user who converted starting # 2021-05-04
862
- funnel_trends_persons_existent_dropped_off_results , _ = ClickhouseFunnelTrendsPersons (
863
- Filter ({** filter ._data , "entrance_period_start" : "2021-05-04 00:00:00" , "drop_off" : False }),
864
- self .team ,
865
- ClickhouseFunnelUnordered ,
866
- ).run ()
893
+ funnel_trends_persons_existent_dropped_off_results , _ = self ._get_people_at_step (
894
+ filter , "2021-05-04 00:00:00" , False , ClickhouseFunnelUnordered
895
+ )
867
896
868
897
self .assertEqual (
869
898
len (funnel_trends_persons_existent_dropped_off_results ), 1 ,
0 commit comments