Skip to content

Commit

Permalink
fix: no varying in snapshot test (#21009)
Browse files Browse the repository at this point in the history
* fix: no varying in snapshot test

* can we snapshot CH while we're here

* Update query snapshots

* Update query snapshots

* need to freeze time for CH now

* Update query snapshots

* ah, that's why we don't snapshot CH in this test

* Update query snapshots

* wat

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pauldambra and github-actions[bot] authored Mar 19, 2024
1 parent 711b282 commit a8d3ba9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,31 @@
FROM "posthog_persondistinctid"
INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id")
WHERE ("posthog_persondistinctid"."distinct_id" IN ('user2',
'user_one_2')
'user_one_0')
AND "posthog_persondistinctid"."team_id" = 2) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'''
# ---
# name: TestSessionRecordings.test_get_session_recordings.36
'''
SELECT "posthog_persondistinctid"."id",
"posthog_persondistinctid"."team_id",
"posthog_persondistinctid"."person_id",
"posthog_persondistinctid"."distinct_id",
"posthog_persondistinctid"."version",
"posthog_person"."id",
"posthog_person"."created_at",
"posthog_person"."properties_last_updated_at",
"posthog_person"."properties_last_operation",
"posthog_person"."team_id",
"posthog_person"."properties",
"posthog_person"."is_user_id",
"posthog_person"."is_identified",
"posthog_person"."uuid",
"posthog_person"."version"
FROM "posthog_persondistinctid"
INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id")
WHERE ("posthog_persondistinctid"."distinct_id" IN ('user2',
'user_one_0')
AND "posthog_persondistinctid"."team_id" = 2) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/
'''
# ---
Expand Down
45 changes: 43 additions & 2 deletions posthog/session_recordings/test/test_session_recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def create_snapshot(
)

@snapshot_postgres_queries
# we can't take snapshots of the CH queries
# because we use `now()` in the CH queries which don't know about any frozen time
# @snapshot_clickhouse_queries
def test_get_session_recordings(self):
twelve_distinct_ids: List[str] = [f"user_one_{i}" for i in range(12)]

Expand All @@ -78,8 +81,8 @@ def test_get_session_recordings(self):
base_time = (now() - relativedelta(days=1)).replace(microsecond=0)
session_id_one = f"test_get_session_recordings-1"
self.create_snapshot("user_one_0", session_id_one, base_time)
self.create_snapshot("user_one_1", session_id_one, base_time + relativedelta(seconds=10))
self.create_snapshot("user_one_2", session_id_one, base_time + relativedelta(seconds=30))
self.create_snapshot("user_one_0", session_id_one, base_time + relativedelta(seconds=10))
self.create_snapshot("user_one_0", session_id_one, base_time + relativedelta(seconds=30))
session_id_two = f"test_get_session_recordings-2"
self.create_snapshot("user2", session_id_two, base_time + relativedelta(seconds=20))

Expand Down Expand Up @@ -125,6 +128,44 @@ def test_get_session_recordings(self):
assert results_[0]["distinct_id"] == "user2"
assert results_[1]["distinct_id"] in twelve_distinct_ids

def test_can_list_recordings_even_when_the_person_has_multiple_distinct_ids(self):
# almost duplicate of test_get_session_recordings above
# but if we have multiple distinct ids on a recording the snapshot
# varies which makes the snapshot useless
twelve_distinct_ids: List[str] = [f"user_one_{i}" for i in range(12)]

Person.objects.create(
team=self.team,
distinct_ids=twelve_distinct_ids, # that's too many! we should limit them
properties={"$some_prop": "something", "email": "[email protected]"},
)
Person.objects.create(
team=self.team,
distinct_ids=["user2"],
properties={"$some_prop": "something", "email": "[email protected]"},
)

base_time = (now() - relativedelta(days=1)).replace(microsecond=0)
session_id_one = f"test_get_session_recordings-1"
self.create_snapshot("user_one_0", session_id_one, base_time)
self.create_snapshot("user_one_1", session_id_one, base_time + relativedelta(seconds=10))
self.create_snapshot("user_one_2", session_id_one, base_time + relativedelta(seconds=30))
session_id_two = f"test_get_session_recordings-2"
self.create_snapshot("user2", session_id_two, base_time + relativedelta(seconds=20))

response = self.client.get(f"/api/projects/{self.team.id}/session_recordings")
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_data = response.json()

results_ = response_data["results"]
assert results_ is not None
# detailed assertion is in the other test
assert len(results_) == 2

# user distinct id varies because we're adding more than one
assert results_[0]["distinct_id"] == "user2"
assert results_[1]["distinct_id"] in twelve_distinct_ids

@patch("posthog.session_recordings.session_recording_api.SessionRecordingListFromReplaySummary")
def test_console_log_filters_are_correctly_passed_to_listing(self, mock_summary_lister):
mock_summary_lister.return_value.run.return_value = ([], False)
Expand Down

0 comments on commit a8d3ba9

Please sign in to comment.