: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 core API tests (part 1) (#116219)
Paul D'Ambra218770fcf314
diff --git a/posthog/api/test/test_comment_slack_sync.py b/posthog/api/test/test_comment_slack_sync.pyindex 5fd5e387b5c3..adebd002ef01 100644--- a/posthog/api/test/test_comment_slack_sync.py+++ b/posthog/api/test/test_comment_slack_sync.py@@ -4,6 +4,7 @@ from posthog.test.base import APIBaseTestfrom unittest.mock import MagicMock, patchfrom django.apps import apps+from django.test import SimpleTestCasefrom django.utils import timezonefrom celery.exceptions import Retry@@ -26,7 +27,7 @@ from posthog.tasks.comment_slack_sync import (from products.canvas.backend.facade import testing as canvas_testing-class TestDiscussionCardBlocks(APIBaseTest):+class TestDiscussionCardBlocks(SimpleTestCase):def _card_text(self, body: str) -> str:blocks = _discussion_card_blocks(body_mrkdwn=body, author_name="Ann", item_url="https://app.posthog.com/i/1", item_label="Insight"diff --git a/posthog/api/test/test_comments.py b/posthog/api/test/test_comments.pyindex 959aaa2437b9..76eb4dc26963 100644--- a/posthog/api/test/test_comments.py+++ b/posthog/api/test/test_comments.py@@ -7,6 +7,7 @@ from unittest import mockfrom django.apps import appsfrom django.conf import settings+from django.test import SimpleTestCasefrom django.utils import timezonefrom parameterized import parameterized@@ -2524,7 +2525,7 @@ class TestDiscussionMentionInternalEvents(APIBaseTest, QueryMatchingTest):assert person.id == str(self.user.id)-class TestCommentHelperFunctions(APIBaseTest):+class TestCommentHelperFunctions(SimpleTestCase):@parameterized.expand([("with_slug", "Notebook", "123", "/notebook/abc", "/notebook/abc#panel=discussion"),diff --git a/posthog/api/test/test_event_definition_base.py b/posthog/api/test/test_event_definition_base.pyindex d77f7ec5038e..2b7211a00026 100644--- a/posthog/api/test/test_event_definition_base.py+++ b/posthog/api/test/test_event_definition_base.py@@ -1,6 +1,7 @@-from posthog.test.base import BaseTestfrom unittest.mock import MagicMock+from django.test import SimpleTestCase+from parameterized import parameterizedfrom posthog.api.event_definition_generators.base import EventDefinitionGenerator@@ -22,7 +23,7 @@ class TestGenerator(EventDefinitionGenerator):return "" # Not needed for hash tests-class TestEventDefinitionGeneratorBase(BaseTest):+class TestEventDefinitionGeneratorBase(SimpleTestCase):@parameterized.expand([(diff --git a/posthog/api/test/test_event_definition_typescript.py b/posthog/api/test/test_event_definition_typescript.pyindex dcca81456476..a6b8c15646a2 100644--- a/posthog/api/test/test_event_definition_typescript.py+++ b/posthog/api/test/test_event_definition_typescript.py@@ -15,9 +15,11 @@ from pathlib import Pathfrom typing import Anyimport pytest-from posthog.test.base import APIBaseTest, BaseTest+from posthog.test.base import APIBaseTestfrom unittest.mock import MagicMock, patch+from django.test import SimpleTestCase+from rest_framework import statusfrom posthog.api.event_definition_generators.typescript import TypeScriptGenerator@@ -286,7 +288,7 @@ posthog.capture("a'a\\\\'b\\"c>?>%}}%%>c<[[?${{%}}cake'", {self.snapshot.assert_match(self._strip_dynamic_timestamp(ts_content))-class TestTypeScriptGeneratorOptionalInTypes(BaseTest):+class TestTypeScriptGeneratorOptionalInTypes(SimpleTestCase):def test_optional_in_types_generates_optional_marker(self):generator = TypeScriptGenerator()event = MagicMock()diff --git a/posthog/api/test/test_github.py b/posthog/api/test/test_github.pyindex c5434ea4116e..04670ae1a46d 100644--- a/posthog/api/test/test_github.py+++ b/posthog/api/test/test_github.py@@ -5,7 +5,7 @@ from hashlib import sha256from posthog.test.base import APIBaseTestfrom unittest.mock import MagicMock, patch-from django.test import TestCase, override_settings+from django.test import SimpleTestCase, TestCase, override_settingsfrom django.utils import timezonefrom parameterized import parameterized@@ -693,7 +693,7 @@ class TestProjectSecretAPIKeySecretAlert(APIBaseTest):mock_ff_exposed.assert_called_once()-class TestRelayToEu(TestCase):+class TestRelayToEu(SimpleTestCase):def test_returns_none_when_setting_empty(self):"""Verify no call when GITHUB_SECRET_ALERT_RELAY_URL is None."""with override_settings(GITHUB_SECRET_ALERT_RELAY_URL=None):diff --git a/posthog/api/test/test_organization_domain.py b/posthog/api/test/test_organization_domain.pyindex a18acc91bf47..269d7f9052b4 100644--- a/posthog/api/test/test_organization_domain.py+++ b/posthog/api/test/test_organization_domain.py@@ -3,7 +3,7 @@ from datetime import timedeltafrom zoneinfo import ZoneInfoimport time_machine-from posthog.test.base import APIBaseTest, BaseTest+from posthog.test.base import APIBaseTestfrom unittest.mock import ANY, patchfrom django.test import SimpleTestCase@@ -31,7 +31,7 @@ class FakeDNSResponse:self.response = FakeAnswer(answer)-class TestOrganizationDomains(BaseTest):+class TestOrganizationDomains(SimpleTestCase):def test_continuous_verification_task(self):"""Tests the task that re-verifies domains to ensure ownership is maintained.diff --git a/posthog/api/test/test_team_project_parity.py b/posthog/api/test/test_team_project_parity.pyindex e10e9d6dcd62..940368e4c51f 100644--- a/posthog/api/test/test_team_project_parity.py+++ b/posthog/api/test/test_team_project_parity.py@@ -1,4 +1,4 @@-from posthog.test.base import BaseTest+from django.test import SimpleTestCasefrom rest_framework import viewsets@@ -43,7 +43,7 @@ def _extra_action_names(viewset_class: type[viewsets.GenericViewSet]) -> set[strreturn {action.__name__ for action in viewset_class.get_extra_actions()}-class TestTeamProjectParity(BaseTest):+class TestTeamProjectParity(SimpleTestCase):def test_detail_serializer_is_a_superset_of_team_serializer(self):team_fields = _serializer_field_names(TeamSerializer)project_fields = _serializer_field_names(ProjectBackwardCompatSerializer)diff --git a/posthog/api/test/test_user_integration.py b/posthog/api/test/test_user_integration.pyindex c58d236edecc..061f8ee0a0ef 100644--- a/posthog/api/test/test_user_integration.py+++ b/posthog/api/test/test_user_integration.py@@ -10,7 +10,7 @@ from posthog.test.base import APIBaseTestfrom unittest.mock import MagicMock, patchfrom django.core.cache import cache-from django.test import override_settings+from django.test import SimpleTestCase, override_settingsfrom django.utils import timezoneimport requests@@ -1390,7 +1390,7 @@ class TestUserGitHubIntegrationFromInstallation(APIBaseTest):self.assertEqual(mock_report.call_count, 0)-class TestGithubUserFromCode(APIBaseTest):+class TestGithubUserFromCode(SimpleTestCase):@patch("posthog.egress.transport.transport.requests.request")@patch("posthog.models.integration.github.requests.post")@override_settings(GITHUB_APP_CLIENT_ID="client_id", GITHUB_APP_CLIENT_SECRET="client_secret")diff --git a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt b/posthog/test/repo_invariants/database_free_test_classes_baseline.txtindex fe73db3f3e40..3500102ae066 100644--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt@@ -38,13 +38,7 @@ posthog/admin/test_admin.py::TestOrganizationMemberInlineConfigposthog/admin/test_admin.py::TestPluginAttachmentInlineposthog/api/oauth/test_cimd.py::TestAuthorizationServerMetadataposthog/api/oauth/test_cimd.py::TestFetchCimdMetadata-posthog/api/test/test_comment_slack_sync.py::TestDiscussionCardBlocks-posthog/api/test/test_comments.py::TestCommentHelperFunctionsposthog/api/test/test_csp.py::TestCSPModule-posthog/api/test/test_event_definition_base.py::TestEventDefinitionGeneratorBase-posthog/api/test/test_event_definition_typescript.py::TestTypeScriptGeneratorOptionalInTypes-posthog/api/test/test_github.py::TestRelayToEu-posthog/api/test/test_organization_domain.py::TestOrganizationDomainsposthog/api/test/test_proxy_record_diagnostics.py::TestCheckCaaposthog/api/test/test_proxy_record_diagnostics.py::TestCheckCloudflareposthog/api/test/test_proxy_record_diagnostics.py::TestCheckCname@@ -52,11 +46,9 @@ posthog/api/test/test_proxy_record_diagnostics.py::TestCheckHttpChallengeposthog/api/test/test_proxy_record_diagnostics.py::TestCheckLiveEventposthog/api/test/test_proxy_record_diagnostics.py::TestIsReservedProxyDomainposthog/api/test/test_proxy_record_diagnostics.py::TestIsValidProxyDomain-posthog/api/test/test_team_project_parity.py::TestTeamProjectParityposthog/api/test/test_toolbar_oauth_endpoint_auth.py::TestToolbarOAuthScopesConfigposthog/api/test/test_toolbar_oauth_primitives.py::TestTokenEndpointStatusRemappingposthog/api/test/test_toolbar_oauth_primitives.py::TestToolbarOAuthStateCache-posthog/api/test/test_user_integration.py::TestGithubUserFromCodeposthog/caching/test/test_redis_cluster_keys.py::TestRedisClusterKeySlotsproducts/cdp/backend/templates/avo/test_template_avo.py::TestTemplateMigrationposthog/clickhouse/client/test/test_limit.py::TestRateLimit