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): reduce database-backed test baseline (#117564)

Paul D'Ambraf39c287ccb71
diff --git a/posthog/api/oauth/test_cimd.py b/posthog/api/oauth/test_cimd.py
index 5b04e5b0e925..b8cd16e0aa4e 100644
--- a/posthog/api/oauth/test_cimd.py
+++ b/posthog/api/oauth/test_cimd.py
@@ -15,7 +15,6 @@ from django.utils.html import escape
import requests
from parameterized import parameterized
-from rest_framework.test import APIClient
from posthog.api.oauth.cimd import (
CIMDFetchError,
@@ -1044,15 +1043,6 @@ class TestCIMDVerificationRejectedCaptureEvent(APIBaseTest):
self.assertEqual(rejected[0].kwargs["properties"]["reason"], "app_url_missing")
-class TestAuthorizationServerMetadata(APIBaseTest):
- def test_advertises_cimd_support(self):
- client = APIClient()
- response = client.get("/.well-known/oauth-authorization-server")
- self.assertEqual(response.status_code, 200)
- data = response.json()
- self.assertTrue(data.get("client_id_metadata_document_supported"))
-
-
@patch("posthog.security.url_validation.resolve_host_ips", return_value={ip_address("93.184.216.34")})
class TestCIMDAuthorizeIntegration(APIBaseTest):
"""Integration tests for the CIMD flow through /oauth/authorize/."""
diff --git a/posthog/api/oauth/test_views.py b/posthog/api/oauth/test_views.py
index c7e284b96daa..f561fcd2926a 100644
--- a/posthog/api/oauth/test_views.py
+++ b/posthog/api/oauth/test_views.py
@@ -5743,6 +5743,7 @@ class TestOAuthAuthorizationServerMetadata(APIBaseTest):
response = self.client.get("/.well-known/oauth-authorization-server")
self.assertEqual(response.status_code, status.HTTP_200_OK)
+ self.assertTrue(response.json()["client_id_metadata_document_supported"])
@override_settings(CLOUD_DEPLOYMENT="US", SITE_URL="https://us.posthog.com")
def test_metadata_includes_region_for_cloud(self):
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 773d78008b60..b74aed525f74 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -1,6 +1,5 @@
ee/clickhouse/models/test/test_dead_letter_queue.py::TestDeadLetterQueue
ee/clickhouse/models/test/test_property.py::TestPropDenormalized
-posthog/api/oauth/test_cimd.py::TestAuthorizationServerMetadata
posthog/clickhouse/test/test_deletion_coverage.py::TestDeletionCoverage
posthog/hogql/database/test/test_postgres_table.py::TestPostgresTablePrimaryKey
posthog/hogql/printer/test/test_sql_injection_defenses.py::TestEscapePreservationOnParserOutput
@@ -13,7 +12,6 @@ posthog/test/test_check_product_migrations.py::TestCheckProductMigrations
products/posthog_ai/scripts/hogql_example/test/test_hogql_example.py::TestRenderHogQLExample
products/streamlit_apps/backend/tests/test_tasks.py::TestAutoRestartCrashedStreamlitSandboxes
products/streamlit_apps/backend/tests/test_tasks.py::TestStopIdleStreamlitSandboxes
-products/surveys/backend/api/test/test_external_surveys.py::TestExternalSurveysURLs
products/web_analytics/dags/tests/test_cache_warming.py::TestFleetQuerySelection
products/web_analytics/dags/tests/test_cache_warming.py::TestSplitWarmableQueries
products/web_analytics/dags/tests/test_cache_warming.py::TestWarmableQueriesCaching
diff --git a/products/surveys/backend/api/test/test_external_surveys.py b/products/surveys/backend/api/test/test_external_surveys.py
index 3b258b2c1aa3..d554f0a0f60d 100644
--- a/products/surveys/backend/api/test/test_external_surveys.py
+++ b/products/surveys/backend/api/test/test_external_surveys.py
@@ -5,10 +5,10 @@ from datetime import UTC, datetime, timedelta
from urllib.parse import parse_qsl
from posthog.test.base import APIBaseTest
-from unittest.mock import patch
+from unittest.mock import MagicMock, patch
from django.core.cache import cache
-from django.test import TestCase, override_settings
+from django.test import SimpleTestCase, override_settings
from parameterized import parameterized
@@ -509,17 +509,17 @@ class TestExternalSurveys(APIBaseTest):
assert response.status_code == 200
-class TestExternalSurveysURLs(TestCase):
+class TestExternalSurveysURLs(SimpleTestCase):
"""Test URL routing for external surveys"""
- def test_survey_url_pattern(self):
+ @patch("products.surveys.backend.api.survey.Survey.objects.select_related")
+ def test_survey_url_pattern(self, mock_select_related: MagicMock) -> None:
"""Test that survey URLs are properly routed"""
- from django.test import Client
-
survey_id = str(uuid.uuid4())
- client = Client()
+ mock_select_related.return_value.get.side_effect = Survey.DoesNotExist
# Test that the URL pattern matches correctly (should return 404 for non-existent survey)
- response = client.get(f"/external_surveys/{survey_id}/")
+ response = self.client.get(f"/external_surveys/{survey_id}/")
# We expect 404 since survey doesn't exist, but URL should be routed correctly
assert response.status_code == 404
+ assert "Survey not available" in response.content.decode()