:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(test): replace real sleep with freeze_time in survey duplicate test (#66365)
Georges-Antoine Assi1a97fdf73960
diff --git a/products/surveys/backend/api/test/test_survey.py b/products/surveys/backend/api/test/test_survey.pyindex 6bf7449c9198..1e26c075fadf 100644--- a/products/surveys/backend/api/test/test_survey.py+++ b/products/surveys/backend/api/test/test_survey.py@@ -1,6 +1,5 @@import reimport json-import timeimport uuidfrom datetime import UTC, datetime, timedeltafrom typing import Any, Optional, cast@@ -6304,24 +6303,26 @@ class TestSurveyBulkDuplication(APIBaseTest):def test_bulk_duplicate_multiple_times_to_same_team(self):"""Test that multiple duplications to the same team create surveys with different timestamps"""- # Create first duplicate- response1 = self.client.post(- f"/api/projects/{self.team.project_id}/surveys/{self.source_survey.id}/duplicate_to_projects/",- data={"target_team_ids": [self.team2.id]},- format="json",- )- assert response1.status_code == status.HTTP_201_CREATED+ with freeze_time("2024-01-01 00:00:00") as frozen_time:+ # Create first duplicate+ response1 = self.client.post(+ f"/api/projects/{self.team.project_id}/surveys/{self.source_survey.id}/duplicate_to_projects/",+ data={"target_team_ids": [self.team2.id]},+ format="json",+ )+ assert response1.status_code == status.HTTP_201_CREATED- # Wait a second to ensure different timestamp- time.sleep(1)+ # Advance the clock so the second duplicate's name timestamp differs (the+ # duplicate name embeds datetime.now() at second precision)+ frozen_time.tick(timedelta(seconds=1))- # Try to create another duplicate (should succeed because timestamp is different)- response2 = self.client.post(- f"/api/projects/{self.team.project_id}/surveys/{self.source_survey.id}/duplicate_to_projects/",- data={"target_team_ids": [self.team2.id]},- format="json",- )- assert response2.status_code == status.HTTP_201_CREATED+ # Try to create another duplicate (should succeed because timestamp is different)+ response2 = self.client.post(+ f"/api/projects/{self.team.project_id}/surveys/{self.source_survey.id}/duplicate_to_projects/",+ data={"target_team_ids": [self.team2.id]},+ format="json",+ )+ assert response2.status_code == status.HTTP_201_CREATED# Verify two surveys exist with different namesteam2_surveys = Survey.objects.filter(team=self.team2).order_by("created_at")