Skip to content

Commit

Permalink
Fix old trends query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robbie-c committed Nov 17, 2023
1 parent 98336ab commit 23d6f65
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions posthog/queries/test/test_trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,14 @@ def test_trends_breakdown_cumulative(self):
self.team,
)

self.assertEqual(response[0]["label"], "sign up - none")
self.assertEqual(response[0]["label"], "none")
self.assertEqual(response[0]["labels"][4], "1-Jan-2020")
self.assertEqual(response[0]["data"], [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0])

self.assertEqual(response[1]["label"], "sign up - other_value")
self.assertEqual(response[1]["label"], "other_value")
self.assertEqual(response[1]["data"], [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0])

self.assertEqual(response[2]["label"], "sign up - value")
self.assertEqual(response[2]["label"], "value")
self.assertEqual(response[2]["data"], [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0])

def test_trends_single_aggregate_dau(self):
Expand Down Expand Up @@ -919,13 +919,14 @@ def test_trends_breakdown_single_aggregate_cohorts(self):
)

for result in event_response:
if result["label"] == "sign up - cohort1":
if result["label"] == "cohort1":
self.assertEqual(result["aggregated_value"], 2)
elif result["label"] == "sign up - cohort2":
elif result["label"] == "cohort2":
self.assertEqual(result["aggregated_value"], 2)
elif result["label"] == "sign up - cohort3":
elif result["label"] == "cohort3":
self.assertEqual(result["aggregated_value"], 3)
else:
self.assertEqual(result["label"], "all users")
self.assertEqual(result["aggregated_value"], 7)

def test_trends_breakdown_single_aggregate(self):
Expand Down Expand Up @@ -3869,7 +3870,7 @@ def test_breakdown_by_empty_cohort(self):
self.team,
)

self.assertEqual(event_response[0]["label"], "$pageview - all users")
self.assertEqual(event_response[0]["label"], "all users")
self.assertEqual(sum(event_response[0]["data"]), 1)

@also_test_with_person_on_events_v2
Expand Down Expand Up @@ -3935,15 +3936,15 @@ def test_breakdown_by_cohort(self):
counts[res["label"]] = sum(res["data"])
break_val[res["label"]] = res["breakdown_value"]

self.assertEqual(counts["watched movie - cohort1"], 1)
self.assertEqual(counts["watched movie - cohort2"], 3)
self.assertEqual(counts["watched movie - cohort3"], 4)
self.assertEqual(counts["watched movie - all users"], 7)
self.assertEqual(counts["cohort1"], 1)
self.assertEqual(counts["cohort2"], 3)
self.assertEqual(counts["cohort3"], 4)
self.assertEqual(counts["all users"], 7)

self.assertEqual(break_val["watched movie - cohort1"], cohort.pk)
self.assertEqual(break_val["watched movie - cohort2"], cohort2.pk)
self.assertEqual(break_val["watched movie - cohort3"], cohort3.pk)
self.assertEqual(break_val["watched movie - all users"], "all")
self.assertEqual(break_val["cohort1"], cohort.pk)
self.assertEqual(break_val["cohort2"], cohort2.pk)
self.assertEqual(break_val["cohort3"], cohort3.pk)
self.assertEqual(break_val["all users"], "all")

self.assertEntityResponseEqual(event_response, action_response)

Expand Down Expand Up @@ -4085,7 +4086,7 @@ def test_breakdown_by_person_property(self):
for response in event_response:
if response["breakdown_value"] == "person1":
self.assertEqual(response["count"], 1)
self.assertEqual(response["label"], "watched movie - person1")
self.assertEqual(response["label"], "person1")
if response["breakdown_value"] == "person2":
self.assertEqual(response["count"], 3)
if response["breakdown_value"] == "person3":
Expand Down Expand Up @@ -4126,7 +4127,7 @@ def test_breakdown_by_person_property_for_person_on_events(self):
for response in event_response:
if response["breakdown_value"] == "person1":
self.assertEqual(response["count"], 1)
self.assertEqual(response["label"], "watched movie - person1")
self.assertEqual(response["label"], "person1")
if response["breakdown_value"] == "person2":
self.assertEqual(response["count"], 3)
if response["breakdown_value"] == "person3":
Expand Down Expand Up @@ -4666,9 +4667,9 @@ def test_trends_aggregate_by_distinct_id(self):
self.team,
)
self.assertEqual(daily_response[0]["data"][0], 2)
self.assertEqual(daily_response[0]["label"], "sign up - some_val")
self.assertEqual(daily_response[0]["label"], "some_val")
self.assertEqual(daily_response[1]["data"][0], 1)
self.assertEqual(daily_response[1]["label"], "sign up - none")
self.assertEqual(daily_response[1]["label"], "none")

# MAU
with freeze_time("2019-12-31T13:00:01Z"):
Expand Down Expand Up @@ -4809,8 +4810,8 @@ def test_breakdown_filtering(self):
)

self.assertEqual(response[0]["label"], "sign up - none")
self.assertEqual(response[2]["label"], "sign up - other_value")
self.assertEqual(response[1]["label"], "sign up - value")
self.assertEqual(response[2]["label"], "sign up - other_value")
self.assertEqual(response[3]["label"], "no events - none")

self.assertEqual(sum(response[0]["data"]), 2)
Expand Down Expand Up @@ -4869,9 +4870,9 @@ def test_breakdown_filtering_persons(self):
),
self.team,
)
self.assertEqual(response[0]["label"], "sign up - none")
self.assertEqual(response[1]["label"], "sign up - [email protected]")
self.assertEqual(response[2]["label"], "sign up - [email protected]")
self.assertEqual(response[0]["label"], "none")
self.assertEqual(response[1]["label"], "[email protected]")
self.assertEqual(response[2]["label"], "[email protected]")

self.assertEqual(response[0]["count"], 1)
self.assertEqual(response[1]["count"], 1)
Expand Down Expand Up @@ -4927,9 +4928,9 @@ def test_breakdown_filtering_persons_with_action_props(self):
),
self.team,
)
self.assertEqual(response[0]["label"], "sign up - none")
self.assertEqual(response[1]["label"], "sign up - [email protected]")
self.assertEqual(response[2]["label"], "sign up - [email protected]")
self.assertEqual(response[0]["label"], "none")
self.assertEqual(response[1]["label"], "[email protected]")
self.assertEqual(response[2]["label"], "[email protected]")

self.assertEqual(response[0]["count"], 1)
self.assertEqual(response[1]["count"], 1)
Expand Down Expand Up @@ -5003,8 +5004,8 @@ def test_breakdown_filtering_with_properties(self):
)

response = sorted(response, key=lambda x: x["label"])
self.assertEqual(response[0]["label"], "sign up - first url")
self.assertEqual(response[1]["label"], "sign up - second url")
self.assertEqual(response[0]["label"], "first url")
self.assertEqual(response[1]["label"], "second url")

self.assertEqual(sum(response[0]["data"]), 1)
self.assertEqual(response[0]["breakdown_value"], "first url")
Expand Down Expand Up @@ -5086,7 +5087,7 @@ def test_breakdown_filtering_with_properties_in_new_format(self):
)

response = sorted(response, key=lambda x: x["label"])
self.assertEqual(response[0]["label"], "sign up - second url")
self.assertEqual(response[0]["label"], "second url")

self.assertEqual(sum(response[0]["data"]), 1)
self.assertEqual(response[0]["breakdown_value"], "second url")
Expand Down Expand Up @@ -5170,8 +5171,8 @@ def test_mau_with_breakdown_filtering_and_prop_filter(self):
self.team,
)

self.assertEqual(event_response[0]["label"], "sign up - some_val")
self.assertEqual(event_response[1]["label"], "sign up - some_val2")
self.assertEqual(event_response[0]["label"], "some_val")
self.assertEqual(event_response[1]["label"], "some_val2")

self.assertEqual(sum(event_response[0]["data"]), 2)
self.assertEqual(event_response[0]["data"][5], 1)
Expand Down Expand Up @@ -5211,8 +5212,8 @@ def test_dau_with_breakdown_filtering(self):
self.team,
)

self.assertEqual(event_response[1]["label"], "sign up - other_value")
self.assertEqual(event_response[2]["label"], "sign up - value")
self.assertEqual(event_response[1]["label"], "other_value")
self.assertEqual(event_response[2]["label"], "value")

self.assertEqual(sum(event_response[1]["data"]), 1)
self.assertEqual(event_response[1]["data"][5], 1)
Expand Down Expand Up @@ -5256,8 +5257,8 @@ def test_dau_with_breakdown_filtering_with_sampling(self):
self.team,
)

self.assertEqual(event_response[1]["label"], "sign up - other_value")
self.assertEqual(event_response[2]["label"], "sign up - value")
self.assertEqual(event_response[1]["label"], "other_value")
self.assertEqual(event_response[2]["label"], "value")

self.assertEqual(sum(event_response[1]["data"]), 1)
self.assertEqual(event_response[1]["data"][5], 1)
Expand Down Expand Up @@ -5301,7 +5302,7 @@ def test_dau_with_breakdown_filtering_with_prop_filter(self):
self.team,
)

self.assertEqual(event_response[0]["label"], "sign up - other_value")
self.assertEqual(event_response[0]["label"], "other_value")

self.assertEqual(sum(event_response[0]["data"]), 1)
self.assertEqual(event_response[0]["data"][5], 1) # property not defined
Expand Down

0 comments on commit 23d6f65

Please sign in to comment.