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 5) (#116235)

Paul D'Ambra2910278508a8
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 79d3ea4994a5..fe73db3f3e40 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -191,34 +191,10 @@ products/mcp_store/backend/test/test_api.py::TestIsValidPosthogCodeCallbackUrl
products/metrics/backend/tests/test_metric_query_runner.py::TestAlignToInterval
products/posthog_ai/eval_harness/test/test_acp_log.py::TestSandboxedTraceCaptureParser
products/posthog_ai/scripts/hogql_example/test/test_hogql_example.py::TestRenderHogQLExample
-products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py::TestClickhousePathsEdgeValidation
-products/product_analytics/backend/hogql_queries/trends/test/test_breakdown_limits.py::TestBreakdownValueTruncation
products/revenue_analytics/backend/test/test_joins.py::TestGetCustomerRevenueViewName
-products/skills/backend/api/test/test_community_skills.py::TestSkillTemplateRendering
-products/slack_app/backend/tests/test_followup_forwarding.py::TestEventLevelDedupe
-products/slack_app/backend/tests/test_fork_thread.py::TestForkMenuBlock
-products/slack_app/backend/tests/test_posthog_code_interactivity.py::TestExtractAlertSnoozeHints
-products/slack_app/backend/tests/test_workspace_claims.py::TestDoesOtherRegionClaimWorkspace
-products/streamlit_apps/backend/tests/test_app_runtime.py::TestGetOtelLogsConfig
-products/streamlit_apps/backend/tests/test_app_runtime.py::TestSandboxCallbackUrl
-products/streamlit_apps/backend/tests/test_app_runtime.py::TestWaitForHealth
products/streamlit_apps/backend/tests/test_tasks.py::TestAutoRestartCrashedStreamlitSandboxes
products/streamlit_apps/backend/tests/test_tasks.py::TestStopIdleStreamlitSandboxes
-products/streamlit_apps/backend/tests/test_zip_validator.py::TestValidateZip
products/surveys/backend/api/test/test_external_surveys.py::TestExternalSurveysURLs
-products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py::TestGetStopReason
-products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py::TestSteerDeclineReason
-products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py::TestExtractTextFromMessagePayload
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestBuildImportedMcpServerConfigs
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestBuildSandboxEnvironmentVariablesGateway
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestGetImportedMcpServerConfigs
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestGetRelayedMcpServerNames
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestGetSandboxGitHubToken
-products/tasks/backend/temporal/process_task/tests/test_utils.py::TestMcpServerConfigToDict
-products/tasks/backend/temporal/slack_relay/tests/test_activities.py::TestSplitTextForSlack
-products/tasks/backend/tests/test_agentsh.py::TestBuildAuditQueryCommand
-products/tasks/backend/tests/test_agentsh.py::TestBuildExecPrefix
-products/tasks/backend/tests/test_agentsh.py::TestGenerateConfigYaml
products/tasks/backend/tests/test_api.py::TestTaskRunRedisStreamKeepalive
products/tasks/backend/tests/test_api.py::TestUsageLimitResponse
products/tasks/backend/tests/test_facade.py::TestAppendLogAgentActivity
diff --git a/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py
index 5ab028fbecdd..4429fe43432b 100644
--- a/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py
+++ b/products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner_ee.py
@@ -16,7 +16,7 @@ from posthog.test.base import (
)
from unittest.mock import MagicMock
-from django.test import TestCase, override_settings
+from django.test import SimpleTestCase, override_settings
from django.utils import timezone
from parameterized import parameterized
@@ -3758,7 +3758,7 @@ class TestClickhousePathsFunnelSource(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(self._run_paths_query(funnel_source, funnel_path_type, funnel_step), expected)
-class TestClickhousePathsEdgeValidation(TestCase):
+class TestClickhousePathsEdgeValidation(SimpleTestCase):
BASIC_PATH = [("1_a", "2_b"), ("2_b", "3_c"), ("3_c", "4_d")] # a->b->c->d
BASIC_PATH_2 = [("1_x", "2_y"), ("2_y", "3_z")] # x->y->z
diff --git a/products/product_analytics/backend/hogql_queries/trends/test/test_breakdown_limits.py b/products/product_analytics/backend/hogql_queries/trends/test/test_breakdown_limits.py
index 5414fa8f2bab..884cd4f313e6 100644
--- a/products/product_analytics/backend/hogql_queries/trends/test/test_breakdown_limits.py
+++ b/products/product_analytics/backend/hogql_queries/trends/test/test_breakdown_limits.py
@@ -1,4 +1,4 @@
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from posthog.hogql import ast
from posthog.hogql.constants import BREAKDOWN_VALUE_MAX_LENGTH
@@ -6,7 +6,7 @@ from posthog.hogql.constants import BREAKDOWN_VALUE_MAX_LENGTH
from products.product_analytics.backend.hogql_queries.trends.breakdown import Breakdown
-class TestBreakdownValueTruncation(BaseTest):
+class TestBreakdownValueTruncation(SimpleTestCase):
def test_replace_null_values_transform_includes_left_truncation(self):
node = ast.Field(chain=["properties", "$browser"])
result = Breakdown.get_replace_null_values_transform(node)
diff --git a/products/skills/backend/api/test/test_community_skills.py b/products/skills/backend/api/test/test_community_skills.py
index 2caf4e961648..e48a04017fa8 100644
--- a/products/skills/backend/api/test/test_community_skills.py
+++ b/products/skills/backend/api/test/test_community_skills.py
@@ -4,6 +4,8 @@ import pytest
from posthog.test.base import APIBaseTest
from unittest.mock import patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from rest_framework import status
@@ -510,7 +512,7 @@ class TestCommunitySkillFeatureFlagGate(APIBaseTest):
self.assertEqual(response.status_code, expected_status, response.content)
-class TestSkillTemplateRendering(APIBaseTest):
+class TestSkillTemplateRendering(SimpleTestCase):
@parameterized.expand(
[
("no metadata", None, False),
diff --git a/products/slack_app/backend/tests/test_followup_forwarding.py b/products/slack_app/backend/tests/test_followup_forwarding.py
index 0f778dafb8d4..c57e8a1345a3 100644
--- a/products/slack_app/backend/tests/test_followup_forwarding.py
+++ b/products/slack_app/backend/tests/test_followup_forwarding.py
@@ -4,7 +4,7 @@ from unittest import TestCase as UnitTestCase
from unittest.mock import MagicMock, patch
from django.apps import apps
-from django.test import TestCase
+from django.test import SimpleTestCase, TestCase
from parameterized import parameterized
from slack_sdk.errors import SlackApiError
@@ -1564,7 +1564,7 @@ class TestEnforcePostHogCodeBillingQuotaActivity(TestCase):
mock_slack_instance.client.chat_postMessage.assert_not_called()
-class TestEventLevelDedupe(TestCase):
+class TestEventLevelDedupe(SimpleTestCase):
"""Verify that the workflow ID format supports event-level deduplication."""
def test_same_event_id_produces_same_workflow_id(self):
diff --git a/products/slack_app/backend/tests/test_fork_thread.py b/products/slack_app/backend/tests/test_fork_thread.py
index 40ad6990881d..75af72673526 100644
--- a/products/slack_app/backend/tests/test_fork_thread.py
+++ b/products/slack_app/backend/tests/test_fork_thread.py
@@ -3,7 +3,7 @@ import json
from unittest.mock import MagicMock, patch
from django.core.cache import cache
-from django.test import TestCase
+from django.test import SimpleTestCase, TestCase
from parameterized import parameterized
from rest_framework.test import APIClient
@@ -296,7 +296,7 @@ class TestForkMenuDispatch(TestCase):
mock_connect.assert_not_called()
-class TestForkMenuBlock(TestCase):
+class TestForkMenuBlock(SimpleTestCase):
def test_menu_is_a_bare_overflow_element_carrying_the_integration(self):
# Bare, not wrapped in an `actions` block, so it can be the footer's accessory
# and share its line. The integration in the option value is what lets the
diff --git a/products/slack_app/backend/tests/test_posthog_code_interactivity.py b/products/slack_app/backend/tests/test_posthog_code_interactivity.py
index b1648b0628da..d6dd6efaed6f 100644
--- a/products/slack_app/backend/tests/test_posthog_code_interactivity.py
+++ b/products/slack_app/backend/tests/test_posthog_code_interactivity.py
@@ -9,7 +9,7 @@ import time_machine
from unittest.mock import MagicMock, patch
from django.core.cache import cache
-from django.test import TestCase, override_settings
+from django.test import SimpleTestCase, TestCase, override_settings
from parameterized import parameterized
from rest_framework.test import APIClient
@@ -1040,7 +1040,7 @@ class TestHandleInsightAlertSnoozeGuards(TestCase):
mock_requests_post.assert_not_called()
-class TestExtractAlertSnoozeHints(TestCase):
+class TestExtractAlertSnoozeHints(SimpleTestCase):
def _payload(self, value: str) -> dict:
return {"actions": [{"action_id": "insight_alert_snooze", "value": value}]}
diff --git a/products/slack_app/backend/tests/test_workspace_claims.py b/products/slack_app/backend/tests/test_workspace_claims.py
index 82e69538dc76..98bed7cd01c4 100644
--- a/products/slack_app/backend/tests/test_workspace_claims.py
+++ b/products/slack_app/backend/tests/test_workspace_claims.py
@@ -136,7 +136,7 @@ class TestSlackWorkspaceClaimsView(TestCase):
@override_settings(DEBUG=False)
-class TestDoesOtherRegionClaimWorkspace(TestCase):
+class TestDoesOtherRegionClaimWorkspace(SimpleTestCase):
"""The caller-side helper. Constructs and signs the request, parses the response, and
deliberately returns None on any transport / format failure so the caller falls back to
local handling instead of silently dropping the event.
diff --git a/products/streamlit_apps/backend/tests/test_app_runtime.py b/products/streamlit_apps/backend/tests/test_app_runtime.py
index 0fa614f69581..1d2248ec857a 100644
--- a/products/streamlit_apps/backend/tests/test_app_runtime.py
+++ b/products/streamlit_apps/backend/tests/test_app_runtime.py
@@ -5,7 +5,7 @@ from io import BytesIO
from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
-from django.test import override_settings
+from django.test import SimpleTestCase, override_settings
from django.utils import timezone
from parameterized import parameterized
@@ -543,7 +543,7 @@ class TestAppRuntimeRestartApp(BaseTest):
service.start_app(app)
-class TestWaitForHealth(BaseTest):
+class TestWaitForHealth(SimpleTestCase):
def test_returns_true_on_200(self):
from products.streamlit_apps.backend.logic.app_runtime import _wait_for_health
@@ -808,7 +808,7 @@ class TestBuildSandboxConfig(BaseTest):
assert f"posthog.app_id={app.id}" in attrs
-class TestGetOtelLogsConfig(BaseTest):
+class TestGetOtelLogsConfig(SimpleTestCase):
@parameterized.expand(
[
("dev_or_self_hosted", False, None, "https://example.ngrok.io/i/v1/logs", "phc_local"),
@@ -931,7 +931,7 @@ class TestAppRuntimeConnectUrl(BaseTest):
assert record.status == StreamlitAppSandbox.Status.STOPPED
-class TestSandboxCallbackUrl(BaseTest):
+class TestSandboxCallbackUrl(SimpleTestCase):
"""Docker sandboxes reach the host via host.docker.internal (applied to
SITE_URL by DockerSandbox), so they must ignore the STREAMLIT_SANDBOX_CALLBACK_URL
tunnel override that only Modal needs. Honoring a stale tunnel here points a
diff --git a/products/streamlit_apps/backend/tests/test_zip_validator.py b/products/streamlit_apps/backend/tests/test_zip_validator.py
index 4dda83c4f9f4..181fd1043959 100644
--- a/products/streamlit_apps/backend/tests/test_zip_validator.py
+++ b/products/streamlit_apps/backend/tests/test_zip_validator.py
@@ -1,7 +1,7 @@
import zipfile
from io import BytesIO
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from products.streamlit_apps.backend.logic.zip_validator import MAX_ZIP_SIZE, validate_zip
@@ -15,7 +15,7 @@ def _make_zip(files: dict[str, str]) -> BytesIO:
return buf
-class TestValidateZip(BaseTest):
+class TestValidateZip(SimpleTestCase):
def test_valid_zip_with_app_py(self):
zf = _make_zip({"app.py": "import streamlit as st"})
result = validate_zip(zf)
diff --git a/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py b/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
index 7a1a48f740f2..ddf1ec8dbe2f 100644
--- a/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/tests/test_send_followup_to_sandbox.py
@@ -3,6 +3,8 @@ from uuid import uuid4
from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
+from django.test import SimpleTestCase
+
from parameterized import parameterized
from temporalio.testing import ActivityEnvironment
@@ -22,7 +24,7 @@ from products.tasks.backend.temporal.process_task.activities.send_followup_to_sa
)
-class TestGetStopReason(BaseTest):
+class TestGetStopReason(SimpleTestCase):
def test_returns_result_stop_reason_when_present(self):
self.assertEqual(_get_stop_reason({"result": {"stopReason": "max_tokens"}}), "max_tokens")
@@ -35,7 +37,7 @@ class TestGetStopReason(BaseTest):
self.assertEqual(_get_stop_reason({"result": "ok"}), "end_turn")
-class TestSteerDeclineReason(BaseTest):
+class TestSteerDeclineReason(SimpleTestCase):
@parameterized.expand(
[
("startup_turn", {"result": {"steered": False, "reason": "startup_turn"}}, "startup_turn"),
diff --git a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py
index 41c88f4c369f..d03bfc00114b 100644
--- a/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py
+++ b/products/tasks/backend/temporal/process_task/tests/test_forward_pending_message.py
@@ -6,7 +6,7 @@ from typing import ClassVar
from unittest.mock import Mock, patch
from django.apps import apps
-from django.test import TestCase
+from django.test import SimpleTestCase, TestCase
from django.utils import timezone
from parameterized import parameterized
@@ -446,7 +446,7 @@ class TestForwardPendingUserMessage(TestCase):
_extract_text_from_message_payload = _module._extract_text_from_message_payload
-class TestExtractTextFromMessagePayload(TestCase):
+class TestExtractTextFromMessagePayload(SimpleTestCase):
"""Guards the ``text-after-last-tool_use`` rule that keeps interim narrative
("Let me pull DAU…") out of the Slack reply while preserving the final answer."""
diff --git a/products/tasks/backend/temporal/process_task/tests/test_utils.py b/products/tasks/backend/temporal/process_task/tests/test_utils.py
index 48b51eecb76b..ea7aa244eea2 100644
--- a/products/tasks/backend/temporal/process_task/tests/test_utils.py
+++ b/products/tasks/backend/temporal/process_task/tests/test_utils.py
@@ -442,7 +442,7 @@ class TestMcpExcludeTools(SimpleTestCase):
assert mcp_exclude_tools_from_state(None) == []
-class TestMcpServerConfigToDict(TestCase):
+class TestMcpServerConfigToDict(SimpleTestCase):
def test_description_is_serialized_for_the_sandbox(self) -> None:
# The agent server drops keys the schema doesn't declare, so an unserialized
# description never reaches the agent's tool search.
@@ -891,7 +891,7 @@ class TestSlackTaskRunActorUser(TestCase):
assert get_task_run_credential_user(task, state) == creator
-class TestGetSandboxGitHubToken(TestCase):
+class TestGetSandboxGitHubToken(SimpleTestCase):
@parameterized.expand(
[
("cached_token_wins", "ghu_cached", True, "ghu_user", None, "ghu_cached"),
@@ -1185,7 +1185,7 @@ class TestGitHubCredentialSourceHelpers(TestCase):
assert result == "ghs_team"
-class TestBuildImportedMcpServerConfigs(TestCase):
+class TestBuildImportedMcpServerConfigs(SimpleTestCase):
def test_returns_empty_for_none_empty_or_non_list(self):
assert build_imported_mcp_server_configs(None, set()) == []
assert build_imported_mcp_server_configs([], {"posthog"}) == []
@@ -1243,7 +1243,7 @@ class TestBuildImportedMcpServerConfigs(TestCase):
assert [c.name for c in configs] == ["Grafana"]
-class TestGetImportedMcpServerConfigs(TestCase):
+class TestGetImportedMcpServerConfigs(SimpleTestCase):
"""The claude-only adapter gate — codex-acp hard-fails a session on any unreachable MCP server
and the sandbox does no reachability pruning, so imported servers must not enter a codex run."""
@@ -1263,7 +1263,7 @@ class TestGetImportedMcpServerConfigs(TestCase):
assert get_imported_mcp_server_configs(self._task_run("codex"), set()) == []
-class TestGetRelayedMcpServerNames(TestCase):
+class TestGetRelayedMcpServerNames(SimpleTestCase):
@staticmethod
def _task_run(relayed_mcp_servers):
return MagicMock(relayed_mcp_servers=relayed_mcp_servers)
@@ -1346,7 +1346,7 @@ _CTX, _TASK = _gateway_ctx_task()
"products.tasks.backend.temporal.process_task.utils.get_sandbox_api_url",
return_value="https://us.posthog.com",
)
-class TestBuildSandboxEnvironmentVariablesGateway(TestCase):
+class TestBuildSandboxEnvironmentVariablesGateway(SimpleTestCase):
def setUp(self) -> None:
super().setUp()
self.enterContext(patch("products.tasks.backend.temporal.process_task.utils.record_gateway_routing"))
diff --git a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py b/products/tasks/backend/temporal/slack_relay/tests/test_activities.py
index adaa397c658d..35cb50c01b77 100644
--- a/products/tasks/backend/temporal/slack_relay/tests/test_activities.py
+++ b/products/tasks/backend/temporal/slack_relay/tests/test_activities.py
@@ -5,7 +5,7 @@ import unittest
from unittest.mock import patch
from django.db import DatabaseError
-from django.test import TestCase, override_settings
+from django.test import SimpleTestCase, TestCase, override_settings
from parameterized import parameterized
from slack_sdk.errors import SlackApiError
@@ -786,7 +786,7 @@ class TestAppendUnconfirmedAttachmentNotice(unittest.TestCase):
assert result == text
-class TestSplitTextForSlack(TestCase):
+class TestSplitTextForSlack(SimpleTestCase):
# The splitter takes its limit from the caller and behaves the same at any size, so these
# cases use a small one to keep the fixtures small. Production passes the markdown block cap.
_LIMIT = 3500
diff --git a/products/tasks/backend/tests/test_agentsh.py b/products/tasks/backend/tests/test_agentsh.py
index 34b7d414a4c0..8c750d5130ad 100644
--- a/products/tasks/backend/tests/test_agentsh.py
+++ b/products/tasks/backend/tests/test_agentsh.py
@@ -26,7 +26,7 @@ from products.tasks.backend.logic.services.agentsh import (
)
-class TestGenerateConfigYaml(TestCase):
+class TestGenerateConfigYaml(SimpleTestCase):
def test_has_ptrace_enabled_with_full_trace(self):
config = yaml.safe_load(generate_config_yaml())
self.assertTrue(config["sandbox"]["ptrace"]["enabled"])
@@ -525,7 +525,7 @@ class TestBashEnvScript(SimpleTestCase):
self.assertNotEqual(result.returncode, 0)
-class TestBuildAuditQueryCommand(TestCase):
+class TestBuildAuditQueryCommand(SimpleTestCase):
def test_references_audit_db(self):
cmd = build_audit_query_command()
self.assertIn(AGENTSH_AUDIT_DB, cmd)
@@ -545,7 +545,7 @@ class TestBuildAuditQueryCommand(TestCase):
self.assertTrue(any(part.startswith("SELECT ts_unix_ns") for part in parts))
-class TestBuildExecPrefix(TestCase):
+class TestBuildExecPrefix(SimpleTestCase):
def test_returns_correct_format(self):
self.assertEqual(
build_exec_prefix(),