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 product backend tests (part 2) (#116232)

Paul D'Ambra7eaec025d326
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 a997d59a3f6a..04328e746f68 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -86,12 +86,6 @@ 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
-products/cdp/backend/templates/customerio/test_template_customerio.py::TestTemplateMigration
-products/cdp/backend/templates/hubspot/test_template_hubspot.py::TestTemplateMigration
-products/cdp/backend/templates/posthog/test_template_posthog.py::TestTemplateMigration
-products/cdp/backend/templates/rudderstack/test_template_rudderstack.py::TestTemplateMigration
-products/cdp/backend/templates/salesforce/test_template_salesforce.py::TestTemplateMigration
-products/cdp/backend/templates/sendgrid/test_template_sendgrid.py::TestTemplateMigration
posthog/clickhouse/client/test/test_limit.py::TestRateLimit
posthog/clickhouse/test/test_deletion_coverage.py::TestDeletionCoverage
posthog/clickhouse/test/test_query_tagging.py::TestAddFallbackQueryTags
@@ -272,18 +266,6 @@ products/business_knowledge/backend/tests/test_logic.py::TestChunker
products/business_knowledge/backend/tests/test_url_ingest.py::TestFetchUrl
products/business_knowledge/backend/tests/test_url_ingest.py::TestNormalizeUrl
products/business_knowledge/backend/tests/test_url_ingest.py::TestParseHtml
-products/cohorts/backend/models/test/test_cohort_membership.py::TestDeleteCohortMembersBulkMaxIterations
-products/cohorts/backend/models/test/test_util.py::TestGetFriendlyErrorMessage
-products/conversations/backend/api/tests/test_cache.py::TestCacheKeyGeneration
-products/conversations/backend/api/tests/test_cache.py::TestMessagesCacheOperations
-products/conversations/backend/api/tests/test_cache.py::TestTicketsCacheOperations
-products/conversations/backend/api/tests/test_cache.py::TestUnreadCountCacheOperations
-products/conversations/backend/api/tests/test_email_endpoints.py::TestBuildProxyKwargs
-products/conversations/backend/api/tests/test_restore.py::TestBuildRestoreUrl
-products/conversations/backend/api/tests/test_slack_multi_channel.py::TestConfiguredSupportChannels
-products/conversations/backend/api/tests/test_teams_multi_channel.py::TestConfiguredSupportChannelIds
-products/conversations/backend/api/tests/test_teams_shared_channel_polling.py::TestGraphMessageToActivity
-products/conversations/backend/api/tests/test_teams_shared_channel_polling.py::TestGraphReplyToActivity
products/conversations/backend/api/tests/test_teams_token_storage.py::TestTrustedTeamsServiceUrl
products/dashboards/backend/api/test/test_experiment_widgets.py::TestExperimentWidgetConfigs
products/dashboards/backend/api/test/test_run_widgets.py::TestWidgetRegistry
diff --git a/products/cdp/backend/templates/customerio/test_template_customerio.py b/products/cdp/backend/templates/customerio/test_template_customerio.py
index eb4181815982..3916cad4204e 100644
--- a/products/cdp/backend/templates/customerio/test_template_customerio.py
+++ b/products/cdp/backend/templates/customerio/test_template_customerio.py
@@ -1,5 +1,6 @@
import pytest
-from posthog.test.base import BaseTest
+
+from django.test import SimpleTestCase
from products.cdp.backend.models.plugin import PluginConfig
from products.cdp.backend.templates.customerio.template_customerio import (
@@ -157,7 +158,7 @@ class TestTemplateCustomerio(BaseHogFunctionTemplateTest):
assert e.value.message == "Error from customer.io api: 400: {'error': 'error'}"
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"host": "track.customer.io",
diff --git a/products/cdp/backend/templates/hubspot/test_template_hubspot.py b/products/cdp/backend/templates/hubspot/test_template_hubspot.py
index 0f76e778cd70..847f499a6c97 100644
--- a/products/cdp/backend/templates/hubspot/test_template_hubspot.py
+++ b/products/cdp/backend/templates/hubspot/test_template_hubspot.py
@@ -1,5 +1,6 @@
import pytest
-from posthog.test.base import BaseTest
+
+from django.test import SimpleTestCase
from products.cdp.backend.models.plugin import PluginConfig
from products.cdp.backend.templates.helpers import BaseHogFunctionTemplateTest
@@ -398,7 +399,7 @@ class TestTemplateHubspotEvent(BaseHogFunctionTemplateTest):
)
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"hubspotAccessToken": "toky",
diff --git a/products/cdp/backend/templates/posthog/test_template_posthog.py b/products/cdp/backend/templates/posthog/test_template_posthog.py
index 436e10a03f9b..85470505283a 100644
--- a/products/cdp/backend/templates/posthog/test_template_posthog.py
+++ b/products/cdp/backend/templates/posthog/test_template_posthog.py
@@ -1,4 +1,4 @@
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from products.cdp.backend.models.plugin import PluginConfig
from products.cdp.backend.templates.helpers import BaseHogFunctionTemplateTest
@@ -50,7 +50,7 @@ class TestTemplatePosthog(BaseHogFunctionTemplateTest):
assert self.get_mock_fetch_calls()[0][1]["body"]["properties"] == {"additional": "value"}
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"host": "us.i.example.com",
diff --git a/products/cdp/backend/templates/rudderstack/test_template_rudderstack.py b/products/cdp/backend/templates/rudderstack/test_template_rudderstack.py
index 1b1acd0256f3..838eb91b6613 100644
--- a/products/cdp/backend/templates/rudderstack/test_template_rudderstack.py
+++ b/products/cdp/backend/templates/rudderstack/test_template_rudderstack.py
@@ -1,4 +1,4 @@
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from products.cdp.backend.models.plugin import PluginConfig
from products.cdp.backend.templates.helpers import BaseHogFunctionTemplateTest
@@ -111,7 +111,7 @@ class TestTemplateRudderstack(BaseHogFunctionTemplateTest):
assert self.get_mock_fetch_calls()[0][1]["body"]["batch"][0]["type"] == expected_action
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"dataPlaneUrl": "us.i.example.com",
diff --git a/products/cdp/backend/templates/salesforce/test_template_salesforce.py b/products/cdp/backend/templates/salesforce/test_template_salesforce.py
index 0ca771e96160..3e096fa77ba6 100644
--- a/products/cdp/backend/templates/salesforce/test_template_salesforce.py
+++ b/products/cdp/backend/templates/salesforce/test_template_salesforce.py
@@ -1,5 +1,6 @@
import pytest
-from posthog.test.base import BaseTest
+
+from django.test import SimpleTestCase
from parameterized import parameterized
@@ -248,7 +249,7 @@ class TestTemplateSalesforceLookup(BaseHogFunctionTemplateTest):
assert self.get_mock_fetch_calls() == []
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"eventsToInclude": "a,b",
diff --git a/products/cdp/backend/templates/sendgrid/test_template_sendgrid.py b/products/cdp/backend/templates/sendgrid/test_template_sendgrid.py
index 36d4a6592d1c..50af144179c5 100644
--- a/products/cdp/backend/templates/sendgrid/test_template_sendgrid.py
+++ b/products/cdp/backend/templates/sendgrid/test_template_sendgrid.py
@@ -1,4 +1,4 @@
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from products.cdp.backend.models.plugin import PluginConfig
from products.cdp.backend.templates.helpers import BaseHogFunctionTemplateTest
@@ -90,7 +90,7 @@ class TestTemplateSendgrid(BaseHogFunctionTemplateTest):
)
-class TestTemplateMigration(BaseTest):
+class TestTemplateMigration(SimpleTestCase):
def get_plugin_config(self, config: dict):
_config = {
"sendgridApiKey": "SENDGRID_API_KEY",
diff --git a/products/cohorts/backend/models/test/test_cohort_membership.py b/products/cohorts/backend/models/test/test_cohort_membership.py
index 9a58f71677c1..cfe487769bbb 100644
--- a/products/cohorts/backend/models/test/test_cohort_membership.py
+++ b/products/cohorts/backend/models/test/test_cohort_membership.py
@@ -3,6 +3,8 @@
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from posthog.exceptions import ClickHouseAtCapacity
@@ -381,7 +383,7 @@ class TestDeleteCohortMembersBulk(BaseTest):
get_active_fake().assert_not_called("delete_cohort_members_bulk")
-class TestDeleteCohortMembersBulkMaxIterations(BaseTest):
+class TestDeleteCohortMembersBulkMaxIterations(SimpleTestCase):
def test_stops_after_max_iterations(self):
from unittest.mock import MagicMock
diff --git a/products/cohorts/backend/models/test/test_util.py b/products/cohorts/backend/models/test/test_util.py
index 5c764734d0b6..6bdc97a6676e 100644
--- a/products/cohorts/backend/models/test/test_util.py
+++ b/products/cohorts/backend/models/test/test_util.py
@@ -1283,7 +1283,7 @@ class TestParseErrorCode(BaseTest):
raise ValueError(f"Unknown exception type: {exception_type}")
-class TestGetFriendlyErrorMessage(BaseTest):
+class TestGetFriendlyErrorMessage(SimpleTestCase):
@parameterized.expand(
[
(CohortErrorCode.CAPACITY, "system was busy"),
diff --git a/products/conversations/backend/api/tests/test_cache.py b/products/conversations/backend/api/tests/test_cache.py
index 2185609f8bc2..975d0555a96e 100644
--- a/products/conversations/backend/api/tests/test_cache.py
+++ b/products/conversations/backend/api/tests/test_cache.py
@@ -1,7 +1,7 @@
from unittest.mock import patch
from django.core.cache import cache
-from django.test import SimpleTestCase, TestCase
+from django.test import SimpleTestCase
from products.conversations.backend.cache import (
MESSAGES_CACHE_TTL,
@@ -40,7 +40,7 @@ class TestIdentityTicketsCacheNamespace(SimpleTestCase):
assert get_identity_tickets_cache_namespace(team_id=1) is None
-class TestCacheKeyGeneration(TestCase):
+class TestCacheKeyGeneration(SimpleTestCase):
def test_messages_cache_key_without_after(self):
key = get_messages_cache_key(team_id=1, ticket_id="abc-123")
assert key == "conversations:messages:1:abc-123:initial"
@@ -62,7 +62,7 @@ class TestCacheKeyGeneration(TestCase):
assert key == "conversations:unread_count:42"
-class TestMessagesCacheOperations(TestCase):
+class TestMessagesCacheOperations(SimpleTestCase):
@patch("products.conversations.backend.cache.cache")
def test_get_cached_messages_returns_cached_data(self, mock_cache):
mock_cache.get.return_value = {"messages": []}
@@ -123,7 +123,7 @@ class TestMessagesCacheOperations(TestCase):
invalidate_messages_cache(team_id=1, ticket_id="abc")
-class TestTicketsCacheOperations(TestCase):
+class TestTicketsCacheOperations(SimpleTestCase):
@patch("products.conversations.backend.cache.cache")
def test_get_cached_tickets_returns_cached_data(self, mock_cache):
mock_cache.get.return_value = {"results": [], "has_more": False}
@@ -187,7 +187,7 @@ class TestTicketsCacheOperations(TestCase):
invalidate_tickets_cache(team_id=1, widget_session_id="session")
-class TestUnreadCountCacheOperations(TestCase):
+class TestUnreadCountCacheOperations(SimpleTestCase):
@patch("products.conversations.backend.cache.cache")
def test_get_cached_unread_count_returns_cached_data(self, mock_cache):
mock_cache.get.return_value = 5
diff --git a/products/conversations/backend/api/tests/test_email_endpoints.py b/products/conversations/backend/api/tests/test_email_endpoints.py
index 807b215906f4..0ec237854efc 100644
--- a/products/conversations/backend/api/tests/test_email_endpoints.py
+++ b/products/conversations/backend/api/tests/test_email_endpoints.py
@@ -6,7 +6,7 @@ from unittest.mock import MagicMock, call, patch
from django.core.cache import cache
from django.core.files.uploadedfile import SimpleUploadedFile
-from django.test import Client
+from django.test import Client, SimpleTestCase
from django.utils import timezone
from parameterized import parameterized
@@ -1632,7 +1632,7 @@ class TestEmailInboundRegionRouting(MailgunWebhookTestMixin, BaseTest):
mock_forward.assert_not_called()
-class TestBuildProxyKwargs(BaseTest):
+class TestBuildProxyKwargs(SimpleTestCase):
"""Unit tests for _build_proxy_kwargs multipart fallback."""
def test_raw_body_available(self):
diff --git a/products/conversations/backend/api/tests/test_restore.py b/products/conversations/backend/api/tests/test_restore.py
index 1c7bc9115d9d..e23b16cea16d 100644
--- a/products/conversations/backend/api/tests/test_restore.py
+++ b/products/conversations/backend/api/tests/test_restore.py
@@ -4,6 +4,7 @@ from datetime import timedelta
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase
from django.utils import timezone
from parameterized import parameterized
@@ -727,7 +728,7 @@ class TestRestoreAPI(BaseTest):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
-class TestBuildRestoreUrl(BaseTest):
+class TestBuildRestoreUrl(SimpleTestCase):
"""Tests for _build_restore_url helper function."""
def test_build_restore_url_simple(self):
diff --git a/products/conversations/backend/api/tests/test_slack_multi_channel.py b/products/conversations/backend/api/tests/test_slack_multi_channel.py
index fd122db07e3a..d8a1a4437069 100644
--- a/products/conversations/backend/api/tests/test_slack_multi_channel.py
+++ b/products/conversations/backend/api/tests/test_slack_multi_channel.py
@@ -1,6 +1,8 @@
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from products.conversations.backend.models import Ticket
@@ -8,7 +10,7 @@ from products.conversations.backend.models.constants import Channel, ChannelDeta
from products.conversations.backend.slack import _configured_support_channels, handle_support_message
-class TestConfiguredSupportChannels(BaseTest):
+class TestConfiguredSupportChannels(SimpleTestCase):
@parameterized.expand(
[
("empty_settings", {}, set()),
diff --git a/products/conversations/backend/api/tests/test_teams_multi_channel.py b/products/conversations/backend/api/tests/test_teams_multi_channel.py
index ec39fd83d1fa..8daf8a44bb71 100644
--- a/products/conversations/backend/api/tests/test_teams_multi_channel.py
+++ b/products/conversations/backend/api/tests/test_teams_multi_channel.py
@@ -1,6 +1,8 @@
from posthog.test.base import BaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from products.conversations.backend.models import Ticket
@@ -8,7 +10,7 @@ from products.conversations.backend.models.constants import Channel, ChannelDeta
from products.conversations.backend.teams import _configured_support_channel_ids, handle_teams_message
-class TestConfiguredSupportChannelIds(BaseTest):
+class TestConfiguredSupportChannelIds(SimpleTestCase):
@parameterized.expand(
[
("empty_settings", {}, set()),
diff --git a/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py b/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py
index 26abd9acdb9c..066706c2b07f 100644
--- a/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py
+++ b/products/conversations/backend/api/tests/test_teams_shared_channel_polling.py
@@ -3,6 +3,8 @@ from typing import Any
from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from products.conversations.backend.models import (
@@ -74,7 +76,7 @@ def _channel_verify_resp() -> MagicMock:
return _resp(json_data={"id": CHANNEL_ID, "membershipType": "shared"})
-class TestGraphMessageToActivity(BaseTest):
+class TestGraphMessageToActivity(SimpleTestCase):
@parameterized.expand(
[
("normal_message", _graph_message(), True),
@@ -97,7 +99,7 @@ class TestGraphMessageToActivity(BaseTest):
self.assertEqual(activity["channelData"]["channel"]["id"], CHANNEL_ID)
-class TestGraphReplyToActivity(BaseTest):
+class TestGraphReplyToActivity(SimpleTestCase):
@parameterized.expand(
[
("normal_reply", _graph_message(reply_to_id="root-1"), True),