: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(tests): avoid database setup in product backend tests (part 4) (#116234)
Paul D'Ambradaaa320fdd32
diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex 5d1720dd4496..8ad02c0f7e67 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -126,30 +126,6 @@ products/business_knowledge/backend/tests/test_url_ingest.py::TestParseHtmlproducts/cdp/backend/templates/avo/test_template_avo.py::TestTemplateMigrationproducts/conversations/backend/api/tests/test_teams_token_storage.py::TestTrustedTeamsServiceUrlproducts/data_modeling/backend/test/test_saved_query_dag_sync.py::TestGetDagId-products/experiments/backend/hogql_queries/test/test_stats_config.py::TestSequentialStatsConfig-products/experiments/backend/test/test_experiment_summary_tool.py::TestExperimentSummaryToolHelpers-products/exports/backend/tasks/test/test_csv_exporter_url_sanitising.py::TestCSVExporterURLSanitization-products/exports/backend/tasks/test/test_export_utils.py::TestSiteURLReachability-products/feature_flags/backend/test/test_flag_definitions_cache_tasks.py::TestCleanupStaleFlagDefinitionsExpiryTrackingTask-products/feature_flags/backend/test/test_flag_definitions_cache_tasks.py::TestRefreshExpiringFlagDefinitionsCacheEntries-products/feature_flags/backend/test/test_flags_cache.py::TestExtractCohortIdsFromFlagFilters-products/growth/backend/temporal/signup_enrichment/tests/test_harmonic_status_poll.py::TestReportStatusPollRunActivity-products/legal_documents/backend/tests/test_admin.py::TestLegalDocumentInlineRegistration-products/logs/backend/test/test_logs_url_params.py::TestBuildLogsUrlParams-products/marketing_analytics/backend/services/test_utm_matching.py::TestSharedMatchHelpers-products/marketing_analytics/backend/test_api_serializer_parity.py::TestSerializerFieldParity-products/marketing_analytics/backend/test_max_tools.py::TestFormatAuditUtmForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatConversionGoalsForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatDataSourcesForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatDiagnosticForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatEventSuggestionsForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatExplainGoalForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatGoalLine-products/marketing_analytics/backend/test_max_tools.py::TestFormatTimestampForLlm-products/marketing_analytics/backend/test_max_tools.py::TestFormatUtmMappingSuggestionsForLlm-products/marketing_analytics/backend/test_max_tools.py::TestSanitizeForPrompt-products/mcp_store/backend/test/test_api.py::TestIsValidPosthogCodeCallbackUrl-products/metrics/backend/tests/test_metric_query_runner.py::TestAlignToIntervalproducts/posthog_ai/eval_harness/test/test_acp_log.py::TestSandboxedTraceCaptureParserproducts/posthog_ai/scripts/hogql_example/test/test_hogql_example.py::TestRenderHogQLExampleproducts/revenue_analytics/backend/test/test_joins.py::TestGetCustomerRevenueViewNamediff --git a/products/experiments/backend/hogql_queries/test/test_stats_config.py b/products/experiments/backend/hogql_queries/test/test_stats_config.pyindex e6e797584d7f..58a18e70399a 100644--- a/products/experiments/backend/hogql_queries/test/test_stats_config.py+++ b/products/experiments/backend/hogql_queries/test/test_stats_config.py@@ -2,6 +2,8 @@ from typing import castfrom posthog.test.base import APIBaseTest+from django.test import SimpleTestCase+from parameterized import parameterizedfrom rest_framework.exceptions import ValidationError@@ -412,7 +414,7 @@ class TestStatsConfig(APIBaseTest):self.assertEqual(runner.baseline_variant_key, expected_baseline)-class TestSequentialStatsConfig(APIBaseTest):+class TestSequentialStatsConfig(SimpleTestCase):"""Verify sequential_testing flags propagate from stats_config (and team defaults) into the engine."""def _metric(self) -> ExperimentMeanMetric:diff --git a/products/experiments/backend/test/test_experiment_summary_tool.py b/products/experiments/backend/test/test_experiment_summary_tool.pyindex d8a4a8589e41..a524fb7c0aab 100644--- a/products/experiments/backend/test/test_experiment_summary_tool.py+++ b/products/experiments/backend/test/test_experiment_summary_tool.py@@ -5,7 +5,7 @@ import time_machinefrom posthog.test.base import APIBaseTest, ClickhouseTestMixinfrom unittest.mock import MagicMock, patch-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.utils import timezonefrom parameterized import parameterized@@ -34,7 +34,7 @@ from products.feature_flags.backend.models.feature_flag import FeatureFlag@override_settings(IN_UNIT_TESTING=True)-class TestExperimentSummaryToolHelpers(APIBaseTest):+class TestExperimentSummaryToolHelpers(SimpleTestCase):def test_parse_metric_dict_funnel(self):metric_dict = {"metric_type": "funnel",diff --git a/products/exports/backend/tasks/test/test_csv_exporter_url_sanitising.py b/products/exports/backend/tasks/test/test_csv_exporter_url_sanitising.pyindex 5907629777b8..189951f4a61b 100644--- a/products/exports/backend/tasks/test/test_csv_exporter_url_sanitising.py+++ b/products/exports/backend/tasks/test/test_csv_exporter_url_sanitising.py@@ -1,11 +1,11 @@-from posthog.test.base import APIBaseTest+from django.test import SimpleTestCasefrom parameterized import parameterizedfrom posthog.utils import PotentialSecurityProblemException, absolute_uri-class TestCSVExporterURLSanitization(APIBaseTest):+class TestCSVExporterURLSanitization(SimpleTestCase):def test_sanitize_url_when_provided_path(self) -> None:with self.settings(SITE_URL="https://something.posthog.com"):sanitised = absolute_uri(None or "/some/location")diff --git a/products/exports/backend/tasks/test/test_export_utils.py b/products/exports/backend/tasks/test/test_export_utils.pyindex 9942cec59006..0f44ecc4786e 100644--- a/products/exports/backend/tasks/test/test_export_utils.py+++ b/products/exports/backend/tasks/test/test_export_utils.py@@ -1,15 +1,16 @@from typing import Anyimport pytest-from posthog.test.base import APIBaseTestfrom unittest.mock import patch+from django.test import SimpleTestCase+from products.exports.backend.tasks import exporter_utilsTEST_PREFIX = "Test-Exports"-class TestSiteURLReachability(APIBaseTest):+class TestSiteURLReachability(SimpleTestCase):@patch("products.exports.backend.tasks.exporter_utils.logger")def test_url_not_reachable_exception(self, logger_mock: Any) -> None:test_url = "http://some-bad-url.test"diff --git a/products/feature_flags/backend/test/test_flag_definitions_cache_tasks.py b/products/feature_flags/backend/test/test_flag_definitions_cache_tasks.pyindex d28b94eb13ba..905052e6f6fd 100644--- a/products/feature_flags/backend/test/test_flag_definitions_cache_tasks.py+++ b/products/feature_flags/backend/test/test_flag_definitions_cache_tasks.py@@ -1,7 +1,7 @@from unittest.mock import MagicMock, patchfrom django.conf import settings-from django.test import TestCase, override_settings+from django.test import SimpleTestCase, override_settingsfrom posthog.storage.cache_expiry_manager import CacheRefreshCountsfrom posthog.tasks.test.utils import PushGatewayTaskTestMixin@@ -14,7 +14,7 @@ from products.feature_flags.backend.tasks import ()-class TestRefreshExpiringFlagDefinitionsCacheEntries(PushGatewayTaskTestMixin, TestCase):+class TestRefreshExpiringFlagDefinitionsCacheEntries(PushGatewayTaskTestMixin, SimpleTestCase):@patch("products.feature_flags.backend.tasks.get_cache_stats_generic", return_value={})@patch("posthog.storage.cache_expiry_manager.refresh_expiring_caches")def test_refreshes_cache(self, mock_refresh: MagicMock, mock_stats: MagicMock) -> None:@@ -74,7 +74,7 @@ class TestRefreshExpiringFlagDefinitionsCacheEntries(PushGatewayTaskTestMixin, Trefresh_expiring_flag_definitions_cache_entries()-class TestCleanupStaleFlagDefinitionsExpiryTrackingTask(PushGatewayTaskTestMixin, TestCase):+class TestCleanupStaleFlagDefinitionsExpiryTrackingTask(PushGatewayTaskTestMixin, SimpleTestCase):@patch("posthog.storage.cache_expiry_manager.cleanup_stale_expiry_tracking")def test_cleans_up_cache(self, mock_cleanup: MagicMock) -> None:mock_cleanup.return_value = 3diff --git a/products/feature_flags/backend/test/test_flags_cache.py b/products/feature_flags/backend/test/test_flags_cache.pyindex 6beb47486373..b8593f1526e2 100644--- a/products/feature_flags/backend/test/test_flags_cache.py+++ b/products/feature_flags/backend/test/test_flags_cache.py@@ -4305,7 +4305,7 @@ class TestBlankInactiveFiltersInPayload(BaseTest):@override_settings(FLAGS_REDIS_URL="redis://test")-class TestExtractCohortIdsFromFlagFilters(BaseTest):+class TestExtractCohortIdsFromFlagFilters(SimpleTestCase):def test_extracts_cohort_ids_from_active_flag(self):flags_data = [{diff --git a/products/growth/backend/temporal/signup_enrichment/tests/test_harmonic_status_poll.py b/products/growth/backend/temporal/signup_enrichment/tests/test_harmonic_status_poll.pyindex f61c7de7a69a..70e0f161ab9b 100644--- a/products/growth/backend/temporal/signup_enrichment/tests/test_harmonic_status_poll.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_harmonic_status_poll.py@@ -3,7 +3,7 @@ import datetime as dtfrom posthog.test.base import BaseTestfrom unittest.mock import MagicMock, patch-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom asgiref.sync import async_to_syncfrom parameterized import parameterized@@ -345,7 +345,7 @@ class TestPollStatusBatchActivity(BaseTest):assert not OrganizationEnrichment.objects.filter(organization=organization).exists()-class TestReportStatusPollRunActivity(BaseTest):+class TestReportStatusPollRunActivity(SimpleTestCase):def test_emits_one_event_with_the_counts(self):capture = MagicMock()scoped_capture = MagicMock()diff --git a/products/legal_documents/backend/tests/test_admin.py b/products/legal_documents/backend/tests/test_admin.pyindex 9e21ad392759..dd5fe9b179cd 100644--- a/products/legal_documents/backend/tests/test_admin.py+++ b/products/legal_documents/backend/tests/test_admin.py@@ -10,7 +10,7 @@ from django.contrib.messages.storage.fallback import FallbackStoragefrom django.core.exceptions import PermissionDenied, ValidationErrorfrom django.core.files.uploadedfile import SimpleUploadedFile, UploadedFilefrom django.template.response import TemplateResponse-from django.test import RequestFactory+from django.test import RequestFactory, SimpleTestCasefrom django.utils.datastructures import MultiValueDictfrom parameterized import parameterized@@ -520,7 +520,7 @@ class TestLegalDocumentAdminPermissions(APIBaseTest):self.assertFalse(self.admin.has_delete_permission(request))-class TestLegalDocumentInlineRegistration(APIBaseTest):+class TestLegalDocumentInlineRegistration(SimpleTestCase):def test_inline_attaches_to_organization_admin(self) -> None:# legal_documents registers LegalDocumentInline via posthog.admin.inline_registry, so# core surfaces it on the Organization admin page without importing the product.diff --git a/products/logs/backend/test/test_logs_url_params.py b/products/logs/backend/test/test_logs_url_params.pyindex 8da976943f2a..c0d59f897ac2 100644--- a/products/logs/backend/test/test_logs_url_params.py+++ b/products/logs/backend/test/test_logs_url_params.py@@ -2,14 +2,14 @@ import jsonfrom datetime import UTC, datetimefrom urllib.parse import parse_qs-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom parameterized import parameterizedfrom products.logs.backend.logs_url_params import build_logs_url_params-class TestBuildLogsUrlParams(BaseTest):+class TestBuildLogsUrlParams(SimpleTestCase):@parameterized.expand([("empty_filters", {}, None, None, ""),diff --git a/products/marketing_analytics/backend/services/test_utm_matching.py b/products/marketing_analytics/backend/services/test_utm_matching.pyindex fed13440c848..2862ed363cdb 100644--- a/products/marketing_analytics/backend/services/test_utm_matching.py+++ b/products/marketing_analytics/backend/services/test_utm_matching.py@@ -1,6 +1,8 @@from posthog.test.base import BaseTestfrom unittest.mock import patch+from django.test import SimpleTestCase+from posthog.hogql import astfrom products.marketing_analytics.backend.services.types import Campaign, MatchType, TeamMappings@@ -244,7 +246,7 @@ class TestCampaignsQueryShape(BaseTest):)-class TestSharedMatchHelpers(BaseTest):+class TestSharedMatchHelpers(SimpleTestCase):"""These existed as private copies in both suggesters before they moved here."""PREFERS_ID = TeamMappings(diff --git a/products/marketing_analytics/backend/test_api_serializer_parity.py b/products/marketing_analytics/backend/test_api_serializer_parity.pyindex fc0c280e088b..06ba7d00d169 100644--- a/products/marketing_analytics/backend/test_api_serializer_parity.py+++ b/products/marketing_analytics/backend/test_api_serializer_parity.py@@ -7,7 +7,7 @@ for that reason while every service test passed, because they assert on the datafrom dataclasses import fields as dataclass_fields-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom parameterized import parameterized@@ -34,7 +34,7 @@ from products.marketing_analytics.backend.services.types import (_INTENTIONALLY_UNSERIALIZED: dict[str, set[str]] = {}-class TestSerializerFieldParity(BaseTest):+class TestSerializerFieldParity(SimpleTestCase):@parameterized.expand([("UtmIssue", UtmIssue, UtmIssueSerializer),diff --git a/products/marketing_analytics/backend/test_max_tools.py b/products/marketing_analytics/backend/test_max_tools.pyindex 4a76f3787991..5c8a36eb08ba 100644--- a/products/marketing_analytics/backend/test_max_tools.py+++ b/products/marketing_analytics/backend/test_max_tools.py@@ -6,6 +6,8 @@ import time_machinefrom posthog.test.base import BaseTestfrom unittest.mock import AsyncMock, patch+from django.test import SimpleTestCase+from langchain_core.runnables import RunnableConfigfrom parameterized import parameterized@@ -148,7 +150,7 @@ def _make_goal_summary()-class TestSanitizeForPrompt(BaseTest):+class TestSanitizeForPrompt(SimpleTestCase):@parameterized.expand([("newline_to_space", "google\nads", "google ads"),@@ -204,7 +206,7 @@ class TestSanitizeForPrompt(BaseTest):@time_machine.travel("2025-06-15", tick=False)-class TestFormatTimestampForLlm(BaseTest):+class TestFormatTimestampForLlm(SimpleTestCase):@parameterized.expand([("none_returns_never", None, "never"),@@ -297,7 +299,7 @@ class TestResolveLookbackDays(BaseTest):@time_machine.travel("2025-06-15", tick=False)-class TestFormatDiagnosticForLlm(BaseTest):+class TestFormatDiagnosticForLlm(SimpleTestCase):def _make_minimal_response(self, *, overall_status="healthy", summary="All good"):return MarketingDiagnosticResponse(integrations=[],@@ -396,7 +398,7 @@ class TestFormatDiagnosticForLlm(BaseTest):assert "Purchase" in result-class TestFormatConversionGoalsForLlm(BaseTest):+class TestFormatConversionGoalsForLlm(SimpleTestCase):def test_empty_goals_returns_no_goals_message(self):response = ConversionGoalsListResponse(goals=[],@@ -442,7 +444,7 @@ class TestFormatConversionGoalsForLlm(BaseTest):assert "14" in result-class TestFormatGoalLine(BaseTest):+class TestFormatGoalLine(SimpleTestCase):def test_includes_goal_name_and_kind(self):goal = _make_goal_summary(name="Signup", kind="EventsNode")result = _format_goal_line(goal)@@ -468,7 +470,7 @@ class TestFormatGoalLine(BaseTest):@time_machine.travel("2025-06-15", tick=False)-class TestFormatDataSourcesForLlm(BaseTest):+class TestFormatDataSourcesForLlm(SimpleTestCase):def test_not_connected_shows_in_output(self):entry = _make_data_source_entry(display_name="Meta Ads",@@ -536,7 +538,7 @@ class TestFormatDataSourcesForLlm(BaseTest):assert "cost_micros" in result-class TestFormatExplainGoalForLlm(BaseTest):+class TestFormatExplainGoalForLlm(SimpleTestCase):def _make_explanation(self, *, kind="EventsNode", total_count=200):return GoalExplanation(conversion_goal_id="goal-1",@@ -586,7 +588,7 @@ class TestFormatExplainGoalForLlm(BaseTest):assert "flat breakdown" in result-class TestFormatAuditUtmForLlm(BaseTest):+class TestFormatAuditUtmForLlm(SimpleTestCase):def _make_response(self, *, campaigns_with_issues=0, results=None, all_utm_events=None):return UtmAuditResponse(total_campaigns=5,@@ -639,7 +641,7 @@ class TestFormatAuditUtmForLlm(BaseTest):assert "unknown_source" in result-class TestFormatEventSuggestionsForLlm(BaseTest):+class TestFormatEventSuggestionsForLlm(SimpleTestCase):def test_empty_candidates_returns_no_candidates_message(self):response = EventSuggestionsResponse(candidates=[], lookback_days=30)result = _format_event_suggestions_for_llm(response)@@ -680,7 +682,7 @@ class TestFormatEventSuggestionsForLlm(BaseTest):assert "already a goal" in result-class TestFormatUtmMappingSuggestionsForLlm(BaseTest):+class TestFormatUtmMappingSuggestionsForLlm(SimpleTestCase):def _make_empty_response(self):return UtmMappingSuggestionsResponse(lookback_days_used=90,diff --git a/products/mcp_store/backend/test/test_api.py b/products/mcp_store/backend/test/test_api.pyindex bb3dd4fe79ae..df6c1346b3a1 100644--- a/products/mcp_store/backend/test/test_api.py+++ b/products/mcp_store/backend/test/test_api.py@@ -69,7 +69,7 @@ POLICY_REQUEST_SERIALIZER_CASES = []-class TestIsValidPosthogCodeCallbackUrl(TestCase):+class TestIsValidPosthogCodeCallbackUrl(SimpleTestCase):@parameterized.expand([("array_scheme", "array://callback", True),diff --git a/products/metrics/backend/tests/test_metric_query_runner.py b/products/metrics/backend/tests/test_metric_query_runner.pyindex 6fa41a41cfee..b1cf5a4604e5 100644--- a/products/metrics/backend/tests/test_metric_query_runner.py+++ b/products/metrics/backend/tests/test_metric_query_runner.py@@ -2,9 +2,11 @@ import datetime as dtfrom typing import Anyfrom zoneinfo import ZoneInfo+import pytestfrom posthog.test.base import APIBaseTest, ClickhouseTestMixinfrom unittest.mock import patch+from django.test import SimpleTestCasefrom django.utils import timezonefrom parameterized import parameterized@@ -31,7 +33,8 @@ from products.metrics.backend.metrics4_samples import METRICS4_CUTOVERfrom products.metrics.backend.tests._seeder import seed_metric, truncate_metrics_tables-class TestAlignToInterval(ClickhouseTestMixin, APIBaseTest):[email protected]("clickhouse_database")+class TestAlignToInterval(ClickhouseTestMixin, SimpleTestCase):@parameterized.expand([(project_timezone, interval)