def test_last_step_dropoff(self): self._create_sample_data_multiple_dropoffs() data = { "insight": INSIGHT_FUNNELS, "interval": "day", "date_from": "2021-05-01 00:00:00", "date_to": "2021-05-07 00:00:00", "funnel_window_days": 7, "funnel_step": -3, "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], } filter = Filter(data=data) _, serialized_results = ClickhouseFunnelUnorderedActors( filter, self.team).get_actors() self.assertEqual(10, len(serialized_results))
def _get_actor_ids_at_step(self, filter, funnel_step, breakdown_value=None): person_filter = filter.with_data({ "funnel_step": funnel_step, "funnel_step_breakdown": breakdown_value }) _, serialized_result = ClickhouseFunnelUnorderedActors( person_filter, self.team).get_actors() return [val["id"] for val in serialized_result]
def test_invalid_steps(self): data = { "insight": INSIGHT_FUNNELS, "interval": "day", "date_from": "2021-05-01 00:00:00", "date_to": "2021-05-07 00:00:00", "funnel_window_days": 7, "funnel_step": "blah", "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], } filter = Filter(data=data) with self.assertRaises(ValueError): ClickhouseFunnelUnorderedActors(filter, self.team).run() filter = filter.with_data({"funnel_step": -1}) with pytest.raises(ValueError): _, _ = ClickhouseFunnelUnorderedActors(filter, self.team).run()
def test_unordered_funnel_does_not_return_recordings(self): p1 = _create_person(distinct_ids=[f"user_1"], team=self.team) _create_event( event="step two", distinct_id="user_1", team=self.team, timestamp=timezone.now().strftime("%Y-%m-%d %H:%M:%S.%f"), properties={ "$session_id": "s1", "$window_id": "w1" }, event_uuid="21111111-1111-1111-1111-111111111111", ) _create_event( event="step one", distinct_id="user_1", team=self.team, timestamp=(timezone.now() + timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S.%f"), properties={ "$session_id": "s1", "$window_id": "w1" }, event_uuid="11111111-1111-1111-1111-111111111111", ) _create_session_recording_event(self.team.pk, "user_1", "s1", timezone.now() + timedelta(days=1)) filter = Filter( data={ "insight": INSIGHT_FUNNELS, "date_from": "2021-01-01", "date_to": "2021-01-08", "interval": "day", "funnel_window_days": 7, "funnel_step": 1, "events": [ { "id": "step one", "order": 0 }, { "id": "step two", "order": 1 }, { "id": "step three", "order": 2 }, ], "include_recordings": "true", # <- The important line }) _, results = ClickhouseFunnelUnorderedActors(filter, self.team).get_actors() self.assertEqual(results[0]["id"], p1.uuid) self.assertEqual( results[0]["matched_recordings"], [], )