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 model tests (part 1) (#116220)

Paul D'Ambra92a6af616991
diff --git a/posthog/models/property/test/test_property_behavioral_validation.py b/posthog/models/property/test/test_property_behavioral_validation.py
index e429059bb79f..936018da2630 100644
--- a/posthog/models/property/test/test_property_behavioral_validation.py
+++ b/posthog/models/property/test/test_property_behavioral_validation.py
@@ -1,11 +1,11 @@
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from parameterized import parameterized
from posthog.models.property import BehavioralPropertyType, Property
-class TestBehavioralPropertyDateRangeValidation(BaseTest):
+class TestBehavioralPropertyDateRangeValidation(SimpleTestCase):
"""Validation of the explicit_datetime / explicit_datetime_to combo on behavioral cohort filters."""
def _build(self, **overrides) -> Property:
@@ -80,7 +80,7 @@ class TestBehavioralPropertyDateRangeValidation(BaseTest):
)
-class TestBehavioralPropertyValueAlias(BaseTest):
+class TestBehavioralPropertyValueAlias(SimpleTestCase):
"""Some cohort filter generators store "performed_event_multiple_times" instead of
BehavioralPropertyType.PERFORMED_EVENT_MULTIPLE's canonical "performed_event_multiple".
The alias must resolve to that type's validation rules, not just skip validation."""
@@ -106,7 +106,7 @@ class TestBehavioralPropertyValueAlias(BaseTest):
self._build(time_value=3650, time_interval="day")
-class TestBehavioralPropertyBytecodeCondition(BaseTest):
+class TestBehavioralPropertyBytecodeCondition(SimpleTestCase):
"""The realtime-cohort builder can express an unbounded "did this person ever do X"
condition purely via compiled bytecode/conditionHash, with no time_value/time_interval/
explicit_datetime set. That's a deliberately unbounded condition, not a malformed one."""
diff --git a/posthog/models/property/test/test_property_parse_value.py b/posthog/models/property/test/test_property_parse_value.py
index 213a47fdb9ac..2b951d68b59a 100644
--- a/posthog/models/property/test/test_property_parse_value.py
+++ b/posthog/models/property/test/test_property_parse_value.py
@@ -1,13 +1,13 @@
from typing import Any
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from parameterized import parameterized
from posthog.models.property import Property
-class TestPropertyParseValue(BaseTest):
+class TestPropertyParseValue(SimpleTestCase):
"""Test the Property._parse_value method to ensure it handles all edge cases correctly."""
@parameterized.expand(
diff --git a/posthog/models/resource_transfer/test/test_visitors.py b/posthog/models/resource_transfer/test/test_visitors.py
index 303a2bcad6b2..5044103639ab 100644
--- a/posthog/models/resource_transfer/test/test_visitors.py
+++ b/posthog/models/resource_transfer/test/test_visitors.py
@@ -1,8 +1,6 @@
from types import SimpleNamespace
from typing import Any
-from posthog.test.base import BaseTest
-
from django.test import SimpleTestCase
from parameterized import parameterized
@@ -42,7 +40,7 @@ def _experiment_like_resource(**overrides):
return SimpleNamespace(**base)
-class TestExtractActionIds(BaseTest):
+class TestExtractActionIds(SimpleTestCase):
@parameterized.expand(
[
(
@@ -134,7 +132,7 @@ class TestExtractActionIds(BaseTest):
assert InsightVisitor._extract_action_ids(filters, query) == expected
-class TestExtractCohortIds(BaseTest):
+class TestExtractCohortIds(SimpleTestCase):
@parameterized.expand(
[
(
@@ -242,7 +240,7 @@ class TestExtractCohortIds(BaseTest):
assert InsightVisitor._extract_cohort_ids(filters, query) == expected
-class TestRewriteActionIdInFilters(BaseTest):
+class TestRewriteActionIdInFilters(SimpleTestCase):
@parameterized.expand(
[
(
@@ -279,7 +277,7 @@ class TestRewriteActionIdInFilters(BaseTest):
assert InsightVisitor._rewrite_action_id_in_filters(filters, old_pk, new_pk) == expected
-class TestRewriteActionIdInQuery(BaseTest):
+class TestRewriteActionIdInQuery(SimpleTestCase):
@parameterized.expand(
[
(
@@ -338,7 +336,7 @@ class TestRewriteActionIdInQuery(BaseTest):
assert InsightVisitor._rewrite_action_id_in_query(query, old_pk, new_pk) == expected
-class TestRewriteCohortIdInFilters(BaseTest):
+class TestRewriteCohortIdInFilters(SimpleTestCase):
@parameterized.expand(
[
(
@@ -399,7 +397,7 @@ class TestRewriteCohortIdInFilters(BaseTest):
assert InsightVisitor._rewrite_cohort_id_in_filters(filters, old_pk, new_pk) == expected
-class TestRewriteCohortIdInQuery(BaseTest):
+class TestRewriteCohortIdInQuery(SimpleTestCase):
@parameterized.expand(
[
(
@@ -487,7 +485,7 @@ class TestRewriteCohortIdInQuery(BaseTest):
assert InsightVisitor._rewrite_cohort_id_in_query(query, old_pk, new_pk) == expected
-class TestCohortExtractCohortIds(BaseTest):
+class TestCohortExtractCohortIds(SimpleTestCase):
@parameterized.expand(
[
(
@@ -581,7 +579,7 @@ class TestCohortExtractCohortIds(BaseTest):
assert CohortVisitor._extract_cohort_ids(filters) == expected
-class TestCohortExtractActionIds(BaseTest):
+class TestCohortExtractActionIds(SimpleTestCase):
@parameterized.expand(
[
(
@@ -746,7 +744,7 @@ class TestCohortExtractActionIds(BaseTest):
assert CohortVisitor._extract_action_ids(filters) == expected
-class TestCohortRewriteCohortIdInFilters(BaseTest):
+class TestCohortRewriteCohortIdInFilters(SimpleTestCase):
@parameterized.expand(
[
(
@@ -842,7 +840,7 @@ class TestCohortRewriteCohortIdInFilters(BaseTest):
assert CohortVisitor._rewrite_cohort_id_in_filters(filters, old_pk, new_pk) == expected
-class TestCohortRewriteActionIdInFilters(BaseTest):
+class TestCohortRewriteActionIdInFilters(SimpleTestCase):
@parameterized.expand(
[
(
@@ -1306,7 +1304,7 @@ class TestExperimentSavedMetricVisitorDynamicEdges(SimpleTestCase):
assert ExperimentSavedMetricVisitor.get_dynamic_edges(metric_list) == []
-class TestSurveyVisitorConditionsCohorts(BaseTest):
+class TestSurveyVisitorConditionsCohorts(SimpleTestCase):
@parameterized.expand(
[
(
diff --git a/posthog/models/scoping/test_scoping.py b/posthog/models/scoping/test_scoping.py
index 171550955ab4..0d4c6d916765 100644
--- a/posthog/models/scoping/test_scoping.py
+++ b/posthog/models/scoping/test_scoping.py
@@ -1,5 +1,6 @@
import pytest
-from posthog.test.base import BaseTest
+
+from django.test import SimpleTestCase
from parameterized import parameterized
@@ -13,7 +14,7 @@ from posthog.models.scoping import (
)
-class TestContextVar(BaseTest):
+class TestContextVar(SimpleTestCase):
def test_default_is_none(self):
assert get_current_team_id() is None
@@ -40,7 +41,7 @@ class TestContextVar(BaseTest):
assert get_current_team_id() is None
-class TestTeamScopeContextManager(BaseTest):
+class TestTeamScopeContextManager(SimpleTestCase):
@parameterized.expand(
[
(1,),
@@ -86,7 +87,7 @@ class TestTeamScopeContextManager(BaseTest):
assert get_current_team_id() is None
-class TestUnscopedContextManager(BaseTest):
+class TestUnscopedContextManager(SimpleTestCase):
def test_clears_team_id(self):
with team_scope(42, canonical=True):
assert get_current_team_id() == 42
@@ -120,7 +121,7 @@ class TestUnscopedContextManager(BaseTest):
assert get_current_team_id() == 99
-class TestWithTeamScopeDecorator(BaseTest):
+class TestWithTeamScopeDecorator(SimpleTestCase):
def test_sets_team_id_from_kwarg(self):
"""Decorator extracts team_id from keyword argument."""
captured_team_id = None
diff --git a/posthog/models/test/test_activity_logging.py b/posthog/models/test/test_activity_logging.py
index f49810a32919..f6f6cc559caa 100644
--- a/posthog/models/test/test_activity_logging.py
+++ b/posthog/models/test/test_activity_logging.py
@@ -1,6 +1,6 @@
from typing import cast
-from django.test import TestCase
+from django.test import SimpleTestCase
from posthog.models.activity_logging.activity_log import AuditableScope, Change, describe_change, dict_changes_between
@@ -8,7 +8,7 @@ from products.dashboards.backend.models.dashboard import Dashboard
from products.dashboards.backend.models.dashboard_tile import DashboardTile
-class TeatActivityLog(TestCase):
+class TeatActivityLog(SimpleTestCase):
def test_dict_changes_between(self):
changes = dict_changes_between(
model_type="Plugin",
diff --git a/posthog/models/test/test_entity_model.py b/posthog/models/test/test_entity_model.py
index fac4af4db4d8..a352532aaf39 100644
--- a/posthog/models/test/test_entity_model.py
+++ b/posthog/models/test/test_entity_model.py
@@ -1,10 +1,10 @@
-from django.test import TestCase
+from django.test import SimpleTestCase
from posthog.constants import TREND_FILTER_TYPE_ACTIONS, TREND_FILTER_TYPE_EVENTS
from posthog.models.entity import Entity
-class TestEntity(TestCase):
+class TestEntity(SimpleTestCase):
def test_can_init_without_id(self):
entity = Entity({"type": TREND_FILTER_TYPE_EVENTS}) # This is an "All events" entity
diff --git a/posthog/models/test/test_event_model.py b/posthog/models/test/test_event_model.py
index 820fa41347f0..ab7c307896c8 100644
--- a/posthog/models/test/test_event_model.py
+++ b/posthog/models/test/test_event_model.py
@@ -16,7 +16,7 @@ from posthog.models.property.util import build_selector_regex
from posthog.test.test_journeys import journeys_for
-class TestSelectors(BaseTest):
+class TestSelectors(SimpleTestCase):
def test_selector_splitting(self):
selector1 = Selector("div > span > a")
selector2 = Selector("div span > a")
diff --git a/posthog/models/test/test_missing_person_model.py b/posthog/models/test/test_missing_person_model.py
index edd0d85f2c58..1125c33c0f58 100644
--- a/posthog/models/test/test_missing_person_model.py
+++ b/posthog/models/test/test_missing_person_model.py
@@ -1,11 +1,11 @@
from uuid import UUID
-from posthog.test.base import BaseTest
+from django.test import SimpleTestCase
from posthog.models.person.missing_person import MissingPerson
-class TestMissingPersonModel(BaseTest):
+class TestMissingPersonModel(SimpleTestCase):
def test_generates_deterministic_uuid(self):
assert MissingPerson(1, "test").uuid == UUID("246f7a43-5507-564f-b687-793ee3c2dd79")
assert MissingPerson(2, "test").uuid == UUID("00ce873a-549c-548e-bbec-cc804a385dd8")
diff --git a/posthog/models/test/test_utils.py b/posthog/models/test/test_utils.py
index 4475fda2744c..c7623eff14a4 100644
--- a/posthog/models/test/test_utils.py
+++ b/posthog/models/test/test_utils.py
@@ -2,9 +2,8 @@ import math
from random import Random
from uuid import UUID
-from posthog.test.base import BaseTest
-
from django.core.exceptions import ValidationError
+from django.test import SimpleTestCase
from parameterized import parameterized
@@ -26,7 +25,7 @@ from posthog.models.utils import (
)
-class TestUUIDv7(BaseTest):
+class TestUUIDv7(SimpleTestCase):
def test_has_version_of_7(self):
self.assertEqual(uuid7().version, 7)
@@ -43,7 +42,7 @@ class TestUUIDv7(BaseTest):
self.assertEqual(uuid, UUID("019030b3-ef68-7a3b-8006-671a1c80317f"))
-class TestValidateRateLimit(BaseTest):
+class TestValidateRateLimit(SimpleTestCase):
def test_rate_limit(self):
with self.assertRaises(ValidationError):
validate_rate_limit("1/week")
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 04328e746f68..7efbc059cc9f 100644
--- a/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
+++ b/posthog/test/repo_invariants/database_free_test_classes_baseline.txt
@@ -125,32 +125,7 @@ posthog/kafka_client/test/test_client.py::KafkaClientRoundtripTestCase
posthog/management/commands/test/test_analyze_migration_risk.py::TestAnalyzeMigrationRisk
posthog/management/commands/test/test_base_hypercache_command.py::TestVerificationResultsErrorReporting
posthog/management/commands/test/test_survey_cohort_bytecode_stl.py::TestBytecodeWalker
-posthog/models/property/test/test_property_behavioral_validation.py::TestBehavioralPropertyBytecodeCondition
-posthog/models/property/test/test_property_behavioral_validation.py::TestBehavioralPropertyDateRangeValidation
-posthog/models/property/test/test_property_behavioral_validation.py::TestBehavioralPropertyValueAlias
-posthog/models/property/test/test_property_parse_value.py::TestPropertyParseValue
-posthog/models/resource_transfer/test/test_visitors.py::TestCohortExtractActionIds
-posthog/models/resource_transfer/test/test_visitors.py::TestCohortExtractCohortIds
-posthog/models/resource_transfer/test/test_visitors.py::TestCohortRewriteActionIdInFilters
-posthog/models/resource_transfer/test/test_visitors.py::TestCohortRewriteCohortIdInFilters
-posthog/models/resource_transfer/test/test_visitors.py::TestExtractActionIds
-posthog/models/resource_transfer/test/test_visitors.py::TestExtractCohortIds
-posthog/models/resource_transfer/test/test_visitors.py::TestRewriteActionIdInFilters
-posthog/models/resource_transfer/test/test_visitors.py::TestRewriteActionIdInQuery
-posthog/models/resource_transfer/test/test_visitors.py::TestRewriteCohortIdInFilters
-posthog/models/resource_transfer/test/test_visitors.py::TestRewriteCohortIdInQuery
-posthog/models/resource_transfer/test/test_visitors.py::TestSurveyVisitorConditionsCohorts
-posthog/models/scoping/test_scoping.py::TestContextVar
-posthog/models/scoping/test_scoping.py::TestTeamScopeContextManager
-posthog/models/scoping/test_scoping.py::TestUnscopedContextManager
-posthog/models/scoping/test_scoping.py::TestWithTeamScopeDecorator
posthog/models/test/integration/test_oauth.py::TestYouTubeAnalyticsIntegrationModel
-posthog/models/test/test_activity_logging.py::TeatActivityLog
-posthog/models/test/test_entity_model.py::TestEntity
-posthog/models/test/test_event_model.py::TestSelectors
-posthog/models/test/test_missing_person_model.py::TestMissingPersonModel
-posthog/models/test/test_utils.py::TestUUIDv7
-posthog/models/test/test_utils.py::TestValidateRateLimit
posthog/models/tophog/test/test_tophog_queries.py::TestTopHogQueries
posthog/personhog_client/test_interceptor.py::TestClientNameInterceptor
posthog/personhog_client/test_interceptor.py::TestConsistencyHeaderInterceptor