MCPcopy
hub / github.com/PostHog/posthog / test_timezones_hourly

Method test_timezones_hourly

posthog/queries/test/test_trends.py:4995–5081  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4993
4994 @snapshot_clickhouse_queries
4995 def test_timezones_hourly(self):
4996 self.team.timezone = "US/Pacific"
4997 self.team.save()
4998 _create_person(team_id=self.team.pk, distinct_ids=["blabla"], properties={})
4999 with freeze_time("2020-01-05T06:01:01Z"): # Previous day in pacific time, don't include
5000 _create_event(
5001 team=self.team,
5002 event="sign up",
5003 distinct_id="blabla",
5004 properties={"$current_url": "first url", "$browser": "Firefox", "$os": "Mac"},
5005 )
5006 with freeze_time("2020-01-05T15:01:01Z"): # 07:01 in pacific time
5007 _create_event(
5008 team=self.team,
5009 event="sign up",
5010 distinct_id="blabla",
5011 properties={"$current_url": "first url", "$browser": "Firefox", "$os": "Mac"},
5012 )
5013 with freeze_time("2020-01-05T16:01:01Z"): # 08:01 in pacific time
5014 _create_event(
5015 team=self.team,
5016 event="sign up",
5017 distinct_id="blabla",
5018 properties={"$current_url": "first url", "$browser": "Firefox", "$os": "Mac"},
5019 )
5020
5021 with freeze_time("2020-01-05T18:01:01Z"): # 10:01 in pacific time
5022 response = Trends().run(
5023 Filter(
5024 data={
5025 "date_from": "dStart",
5026 "interval": "hour",
5027 "events": [{"id": "sign up", "name": "sign up", "math": "dau"}],
5028 },
5029 team=self.team,
5030 ),
5031 self.team,
5032 )
5033 self.assertEqual(
5034 response[0]["labels"],
5035 [
5036 "5-Jan-2020 00:00",
5037 "5-Jan-2020 01:00",
5038 "5-Jan-2020 02:00",
5039 "5-Jan-2020 03:00",
5040 "5-Jan-2020 04:00",
5041 "5-Jan-2020 05:00",
5042 "5-Jan-2020 06:00",
5043 "5-Jan-2020 07:00",
5044 "5-Jan-2020 08:00",
5045 "5-Jan-2020 09:00",
5046 "5-Jan-2020 10:00",
5047 ],
5048 )
5049 self.assertEqual(response[0]["data"], [0.0, 0.0, 0.0, 0.0, 0, 0, 0, 1, 1, 0, 0])
5050 persons = self.client.get("/" + response[0]["persons_urls"][7]["url"]).json()
5051 self.assertEqual(persons["results"][0]["count"], 1)
5052

Callers

nothing calls this directly

Calls 8

_create_personFunction · 0.90
_create_eventFunction · 0.90
TrendsClass · 0.90
FilterClass · 0.90
jsonMethod · 0.80
getMethod · 0.65
saveMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected