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(notifications): move db-free logic tests to a SimpleTestCase file (#113189)

posthog[bot]d5d282210f14
diff --git a/products/notifications/backend/tests/test_logic.py b/products/notifications/backend/tests/test_logic.py
index 691309fa694f..7e888a95bd44 100644
--- a/products/notifications/backend/tests/test_logic.py
+++ b/products/notifications/backend/tests/test_logic.py
@@ -1,4 +1,3 @@
-import pytest
from posthog.test.base import BaseTest
from unittest.mock import patch
@@ -165,11 +164,6 @@ class TestCreateNotification(BaseTest):
assert allowed_user.id in result
assert denied_user.id not in result
- def test_resolve_unknown_target_type_raises(self):
- resolver = RecipientsResolver()
- with pytest.raises(ValueError, match="Unknown target type"):
- resolver.resolve("nonexistent_type", "123", self.team.id) # type: ignore[arg-type]
-
@patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=True)
@patch("products.notifications.backend.logic._publish_to_kafka")
def test_create_notification_invalidates_cache_for_resolved_users(self, mock_publish, mock_ff):
@@ -429,33 +423,6 @@ class TestPublishResourceEdited(BaseTest):
# Editor-state sync only — it must never become an inbox notification.
assert NotificationEvent.objects.count() == 0
- @patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=False)
- @patch("products.notifications.backend.logic.get_producer")
- def test_noops_when_flag_disabled(self, mock_get_producer, mock_ff):
- with self.captureOnCommitCallbacks(execute=True):
- publish_resource_edited(
- team=self.team,
- resource_type="HogFlow",
- resource_id="flow-123",
- updated_at="2026-06-16T00:00:00+00:00",
- )
-
- mock_get_producer.assert_not_called()
-
- @patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=True)
- @patch("products.notifications.backend.logic.get_producer")
- @patch.object(RecipientsResolver, "resolve", return_value=[])
- def test_noops_when_no_recipients(self, mock_resolve, mock_get_producer, mock_ff):
- with self.captureOnCommitCallbacks(execute=True):
- publish_resource_edited(
- team=self.team,
- resource_type="HogFlow",
- resource_id="flow-123",
- updated_at="2026-06-16T00:00:00+00:00",
- )
-
- mock_get_producer.assert_not_called()
-
@patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=True)
@patch("products.notifications.backend.logic.get_producer")
@patch.object(RecipientsResolver, "filter_by_access_control")
diff --git a/products/notifications/backend/tests/test_logic_unit.py b/products/notifications/backend/tests/test_logic_unit.py
new file mode 100644
index 000000000000..5fd5997286b8
--- /dev/null
+++ b/products/notifications/backend/tests/test_logic_unit.py
@@ -0,0 +1,48 @@
+import uuid
+
+import pytest
+from unittest.mock import patch
+
+from django.test import SimpleTestCase
+
+from posthog.models import Team
+
+from products.notifications.backend.logic import publish_resource_edited
+from products.notifications.backend.resolvers import RecipientsResolver
+
+
+class TestRecipientsResolverUnit(SimpleTestCase):
+ def test_resolve_unknown_target_type_raises(self) -> None:
+ with pytest.raises(ValueError, match="Unknown target type"):
+ RecipientsResolver().resolve("nonexistent_type", "123", 1) # type: ignore[arg-type]
+
+
+class TestPublishResourceEditedUnit(SimpleTestCase):
+ def setUp(self) -> None:
+ super().setUp()
+ self.team = Team(id=1, organization_id=uuid.uuid4())
+
+ @patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=False)
+ @patch("products.notifications.backend.logic.get_producer")
+ def test_noops_when_flag_disabled(self, mock_get_producer, mock_ff) -> None:
+ publish_resource_edited(
+ team=self.team,
+ resource_type="HogFlow",
+ resource_id="flow-123",
+ updated_at="2026-06-16T00:00:00+00:00",
+ )
+
+ mock_get_producer.assert_not_called()
+
+ @patch("products.notifications.backend.logic.posthoganalytics.feature_enabled", return_value=True)
+ @patch("products.notifications.backend.logic.get_producer")
+ @patch.object(RecipientsResolver, "resolve", return_value=[])
+ def test_noops_when_no_recipients(self, mock_resolve, mock_get_producer, mock_ff) -> None:
+ publish_resource_edited(
+ team=self.team,
+ resource_type="HogFlow",
+ resource_id="flow-123",
+ updated_at="2026-06-16T00:00:00+00:00",
+ )
+
+ mock_get_producer.assert_not_called()