0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 18:26:15 +01:00
posthog/ee/clickhouse/views/test/test_clickhouse_paths.py
Li Yi Yu 6284b645b0
New paths tab querybuilder UI (#5825)
* new path tab querybuilder

* prettier

* clean up

* wip

* format querybuidler

* prepare path type filter component

* dropdown

* formatted popup

* change button for endpoints

* styling the type buttons

* logic for all left side querybuilder components

* exclusion UI and logic

* improve exclusion handling, ensure API calls are made

* API fixes for event types

* fix popup on close issue with exclusions

* hide overflow on buttons

* all ui working

* more formatting adjustments

* type fixes

* leave response ambiguous

* feature flagging and adjust styles

* Add Step limit option

* add tooltip to wildcards

* rewrite tooltip for exclusions

* make Events toggle responsive

* fix types

* responsive at xl instead of lg for no overlaps

* Proof of concept of connecting Funnel to Paths

* protecc wip

* Connect Funnels to Paths

* remove funnel button for now

* remove unused

Co-authored-by: eric <eeoneric@gmail.com>
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
2021-09-28 12:53:03 -04:00

161 lines
6.7 KiB
Python

import json
from uuid import uuid4
from django.core.cache import cache
from ee.clickhouse.models.event import create_event
from ee.clickhouse.util import ClickhouseTestMixin
from posthog.models.person import Person
from posthog.test.base import APIBaseTest
def _create_person(**kwargs):
person = Person.objects.create(**kwargs)
return Person(id=person.uuid, uuid=person.uuid)
def _create_event(**kwargs):
kwargs.update({"event_uuid": uuid4()})
create_event(**kwargs)
class TestClickhousePaths(ClickhouseTestMixin, APIBaseTest):
def test_insight_paths_basic(self):
_create_person(team=self.team, distinct_ids=["person_1"])
_create_event(
properties={"$current_url": "/"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about"}, distinct_id="person_1", event="$pageview", team=self.team,
)
response = self.client.get("/api/insight/path",).json()
self.assertEqual(len(response["result"]), 1)
def test_insight_paths_basic_exclusions(self):
_create_person(team=self.team, distinct_ids=["person_1"])
_create_event(
distinct_id="person_1", event="first event", team=self.team,
)
_create_event(
distinct_id="person_1", event="second event", team=self.team,
)
_create_event(
distinct_id="person_1", event="third event", team=self.team,
)
response = self.client.get("/api/insight/path", data={"exclude_events": '["second event"]'}).json()
self.assertEqual(len(response["result"]), 1)
def test_backwards_compatible_path_types(self):
_create_person(team=self.team, distinct_ids=["person_1"])
_create_event(
properties={"$current_url": "/"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/something else"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$screen_name": "/screen1"}, distinct_id="person_1", event="$screen", team=self.team,
)
_create_event(
distinct_id="person_1", event="custom1", team=self.team,
)
_create_event(
distinct_id="person_1", event="custom2", team=self.team,
)
response = self.client.get("/api/insight/path", data={"path_type": "$pageview", "insight": "PATHS",}).json()
self.assertEqual(len(response["result"]), 2)
response = self.client.get("/api/insight/path", data={"path_type": "custom_event", "insight": "PATHS"}).json()
self.assertEqual(len(response["result"]), 1)
response = self.client.get("/api/insight/path", data={"path_type": "$screen", "insight": "PATHS"}).json()
self.assertEqual(len(response["result"]), 0)
def test_backwards_compatible_start_point(self):
_create_person(team=self.team, distinct_ids=["person_1"])
_create_event(
properties={"$current_url": "/"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/something else"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$screen_name": "/screen1"}, distinct_id="person_1", event="$screen", team=self.team,
)
_create_event(
properties={"$screen_name": "/screen2"}, distinct_id="person_1", event="$screen", team=self.team,
)
_create_event(
distinct_id="person_1", event="custom1", team=self.team,
)
_create_event(
distinct_id="person_1", event="custom2", team=self.team,
)
response = self.client.get(
"/api/insight/path", data={"path_type": "$pageview", "insight": "PATHS", "start_point": "/about",}
).json()
self.assertEqual(len(response["result"]), 1)
response = self.client.get(
"/api/insight/path", data={"path_type": "custom_event", "insight": "PATHS", "start_point": "custom2",}
).json()
self.assertEqual(len(response["result"]), 0)
response = self.client.get(
"/api/insight/path", data={"path_type": "$screen", "insight": "PATHS", "start_point": "/screen1",}
).json()
self.assertEqual(len(response["result"]), 1)
def test_path_groupings(self):
_create_person(team=self.team, distinct_ids=["person_1"])
_create_event(
properties={"$current_url": "/about_1"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about_2"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/something else"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about3"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about4"}, distinct_id="person_1", event="$pageview", team=self.team,
)
_create_person(team=self.team, distinct_ids=["person_2"])
_create_event(
properties={"$current_url": "/about_1"}, distinct_id="person_2", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about_2"}, distinct_id="person_2", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/something else"}, distinct_id="person_2", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about3"}, distinct_id="person_2", event="$pageview", team=self.team,
)
_create_event(
properties={"$current_url": "/about4"}, distinct_id="person_2", event="$pageview", team=self.team,
)
response = self.client.get(
"/api/insight/path", data={"insight": "PATHS", "path_groupings": json.dumps(["/about*"])}
).json()
self.assertEqual(len(response["result"]), 2)
response = self.client.get(
"/api/insight/path", data={"insight": "PATHS", "path_groupings": json.dumps(["/about_*"])}
).json()
self.assertEqual(len(response["result"]), 3)