def test_simplify_cohorts(self): cohort = Cohort.objects.create( team=self.team, groups=[{"properties": [{"key": "email", "operator": "icontains", "value": ".com", "type": "person"}]}], ) cohort.calculate_people_ch(pending_version=0) filter = Filter(data={"properties": [{"type": "cohort", "key": "id", "value": cohort.pk}]}) filter_with_groups = Filter( data={"properties": {"type": "AND", "values": [{"type": "cohort", "key": "id", "value": cohort.pk}]}} ) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"key": "email", "value": ".com", "operator": "icontains", "type": "person"}], } }, ) self.assertEqual( filter_with_groups.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"key": "email", "value": ".com", "operator": "icontains", "type": "person"}], } }, ) with self.settings(USE_PRECALCULATED_CH_COHORT_PEOPLE=True): self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"key": "id", "value": cohort.pk, "operator": None, "type": "precalculated-cohort"}], } }, ) self.assertEqual( filter_with_groups.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"key": "id", "value": cohort.pk, "operator": None, "type": "precalculated-cohort"}], } }, )
def test_simplify_entities(self): cohort = Cohort.objects.create( team=self.team, groups=[{"properties": [{"key": "email", "operator": "icontains", "value": ".com", "type": "person"}]}], ) filter = Filter( data={"events": [{"id": "$pageview", "properties": [{"type": "cohort", "key": "id", "value": cohort.pk}]}]} ) self.assertEqual( filter.simplify(self.team).entities_to_dict(), { "events": [ { "type": "events", "id": "$pageview", "math": None, "math_property": None, "math_group_type_index": None, "custom_name": None, "order": None, "name": "$pageview", "properties": { "type": "AND", "values": [{"key": "email", "operator": "icontains", "value": ".com", "type": "person"},], }, } ], }, )
def test_simplify_multi_group_cohort(self): cohort = Cohort.objects.create( team=self.team, groups=[{ "properties": { "$some_prop": "something" } }, { "properties": { "$another_prop": "something" } }], ) filter = Filter(data={ "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk }] }) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk, "operator": None }] }, )
def test_simplify_hasdone_cohort(self): cohort = Cohort.objects.create(team=self.team, groups=[{ "event_id": "$pageview", "days": 1 }]) filter = Filter(data={ "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk }] }) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk, "operator": None }] }, )
def test_simplify_static_cohort(self): cohort = Cohort.objects.create(team=self.team, groups=[], is_static=True) filter = Filter(data={ "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk }] }) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": [ { "type": "static-cohort", "key": "id", "value": cohort.pk, "operator": None }, ] }, )
def test_simplify_not_ee(self): cohort = Cohort.objects.create( team=self.team, groups=[{ "properties": [{ "key": "email", "operator": "icontains", "value": ".com", "type": "person" }] }], ) filter = Filter(data={ "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk }] }) self.assertEqual( filter.simplify(self.team, is_clickhouse_enabled=False).properties_to_dict(), { "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk, "operator": None }] }, )
def test_simplify_funnel_entities_when_aggregating_by_group(self): filter = Filter(data={"events": [{"id": "$pageview"}], "aggregation_group_type_index": 2}) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"key": "$group_2", "operator": "is_not", "value": "", "type": "event"}], } }, )
def test_simplify_no_such_cohort(self): filter = Filter(data={"properties": [{"type": "cohort", "key": "id", "value": 555_555}]}) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{"type": "cohort", "key": "id", "value": 555_555, "operator": None}], } }, )
def test_recursive_cohort(self): cohort = Cohort.objects.create( team=self.team, groups=[{ "properties": [{ "key": "email", "operator": "icontains", "value": ".com", "type": "person" }] }], ) recursive_cohort = Cohort.objects.create( team=self.team, groups=[{ "properties": [{ "type": "cohort", "key": "id", "value": cohort.pk, "operator": None }] }], ) filter = Filter( data={ "properties": [{ "type": "cohort", "key": "id", "value": recursive_cohort.pk }] }) self.assertEqual( filter.simplify(self.team).properties_to_dict(), { "properties": { "type": "AND", "values": [{ "key": "email", "operator": "icontains", "value": ".com", "type": "person" }], } }, )
def test_simplify_entities_with_group_math(self): filter = Filter( data={ "events": [{ "id": "$pageview", "math": "unique_group", "math_group_type_index": 2 }] }) self.assertEqual( filter.simplify(self.team).entities_to_dict(), { "events": [{ "type": "events", "id": "$pageview", "math": "unique_group", "math_property": None, "math_group_type_index": 2, "custom_name": None, "order": None, "name": "$pageview", "properties": [ { "key": "$group_2", "operator": "is_not", "value": "", "type": "event" }, ], }], }, )