Skip to content

: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.

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.py
index 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 APIBaseTest
from unittest.mock import MagicMock, patch
from django.apps import apps
+from django.test import SimpleTestCase
from django.utils import timezone
from 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.py
index 959aaa2437b9..76eb4dc26963 100644
--- a/posthog/api/test/test_comments.py
+++ b/posthog/api/test/test_comments.py
@@ -7,6 +7,7 @@ from unittest import mock
from django.apps import apps
from django.conf import settings
+from django.test import SimpleTestCase
from django.utils import timezone
from 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.py
index 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 BaseTest
from unittest.mock import MagicMock
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from 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.py
index 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 Path
from typing import Any
import pytest
-from posthog.test.base import APIBaseTest, BaseTest
+from posthog.test.base import APIBaseTest
from unittest.mock import MagicMock, patch
+from django.test import SimpleTestCase
+
from rest_framework import status
from 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.py
index c5434ea4116e..04670ae1a46d 100644
--- a/posthog/api/test/test_github.py
+++ b/posthog/api/test/test_github.py
@@ -5,7 +5,7 @@ from hashlib import sha256
from posthog.test.base import APIBaseTest
from unittest.mock import MagicMock, patch
-from django.test import TestCase, override_settings
+from django.test import SimpleTestCase, TestCase, override_settings
from django.utils import timezone
from 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.py
index 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 timedelta
from zoneinfo import ZoneInfo
import time_machine
-from posthog.test.base import APIBaseTest, BaseTest
+from posthog.test.base import APIBaseTest
from unittest.mock import ANY, patch
from 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.py
index 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 SimpleTestCase
from rest_framework import viewsets
@@ -43,7 +43,7 @@ def _extra_action_names(viewset_class: type[viewsets.GenericViewSet]) -> set[str
return {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.py
index 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 APIBaseTest
from unittest.mock import MagicMock, patch
from django.core.cache import cache
-from django.test import override_settings
+from django.test import SimpleTestCase, override_settings
from django.utils import timezone
import 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.txt
index 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::TestOrganizationMemberInlineConfig
posthog/admin/test_admin.py::TestPluginAttachmentInline
posthog/api/oauth/test_cimd.py::TestAuthorizationServerMetadata
posthog/api/oauth/test_cimd.py::TestFetchCimdMetadata
-posthog/api/test/test_comment_slack_sync.py::TestDiscussionCardBlocks
-posthog/api/test/test_comments.py::TestCommentHelperFunctions
posthog/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::TestOrganizationDomains
posthog/api/test/test_proxy_record_diagnostics.py::TestCheckCaa
posthog/api/test/test_proxy_record_diagnostics.py::TestCheckCloudflare
posthog/api/test/test_proxy_record_diagnostics.py::TestCheckCname
@@ -52,11 +46,9 @@ posthog/api/test/test_proxy_record_diagnostics.py::TestCheckHttpChallenge
posthog/api/test/test_proxy_record_diagnostics.py::TestCheckLiveEvent
posthog/api/test/test_proxy_record_diagnostics.py::TestIsReservedProxyDomain
posthog/api/test/test_proxy_record_diagnostics.py::TestIsValidProxyDomain
-posthog/api/test/test_team_project_parity.py::TestTeamProjectParity
posthog/api/test/test_toolbar_oauth_endpoint_auth.py::TestToolbarOAuthScopesConfig
posthog/api/test/test_toolbar_oauth_primitives.py::TestTokenEndpointStatusRemapping
posthog/api/test/test_toolbar_oauth_primitives.py::TestToolbarOAuthStateCache
-posthog/api/test/test_user_integration.py::TestGithubUserFromCode
posthog/caching/test/test_redis_cluster_keys.py::TestRedisClusterKeySlots
products/cdp/backend/templates/avo/test_template_avo.py::TestTemplateMigration
posthog/clickhouse/client/test/test_limit.py::TestRateLimit