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): skip demo data generation in four core tests (#123478)

Raúl Negrón-Otero1a5541728802
diff --git a/ee/api/test/test_billing.py b/ee/api/test/test_billing.py
index 182b00d9f03a..13284b0e790c 100644
--- a/ee/api/test/test_billing.py
+++ b/ee/api/test/test_billing.py
@@ -809,6 +809,7 @@ class TestBillingAPI(APILicensedTest):
assert res_json["products"][0]["addons"][0]["tiers"][0]["current_amount_usd"] == "0.00"
assert res_json["products"][0]["addons"][0]["tiers"][1]["current_amount_usd"] == "0.00"
+ @patch("posthog.tasks.demo_create_data.create_data_for_demo_team.delay")
@patch("ee.billing.billing_manager.http_session.get")
def test_organization_usage_count_with_demo_project(self, mock_request, *args):
def mock_implementation(url: str, headers: Any = None, params: Any = None) -> MagicMock | Response:
@@ -838,9 +839,9 @@ class TestBillingAPI(APILicensedTest):
self.assertEqual(Team.objects.count(), 1)
response = self.client.post("/api/projects/", {"name": "Test", "is_demo": True})
self.assertEqual(response.status_code, 201)
- self.assertEqual(Team.objects.count(), 3)
+ self.assertEqual(Team.objects.count(), 2)
- demo_team = Team.objects.filter(is_demo=True).first()
+ demo_team = Team.objects.get(organization=self.organization, is_demo=True)
# We create some events for the demo project
with self.settings(USE_TZ=False):
diff --git a/posthog/api/test/test_project.py b/posthog/api/test/test_project.py
index 5a4cedb2366a..f390aaf299af 100644
--- a/posthog/api/test/test_project.py
+++ b/posthog/api/test/test_project.py
@@ -205,7 +205,8 @@ class TestProjectAPI(team_api_test_factory()): # type: ignore
self.assertEqual(response.json()["attr"], "logo_media_id")
self.assertIsNone(self.project.logo_media_id)
- def test_cannot_create_second_demo_project(self):
+ @patch("posthog.tasks.demo_create_data.create_data_for_demo_team.delay")
+ def test_cannot_create_second_demo_project(self, _mock_create_demo_data: MagicMock):
# Create first demo project
Project.objects.create_with_team(
organization=self.organization, name="First Demo", initiating_user=self.user, team_fields={"is_demo": True}
@@ -550,7 +551,8 @@ class TestProjectAPI(team_api_test_factory()): # type: ignore
"You have reached the maximum limit of 2000 projects per organization. Contact support if you'd like access to more projects.",
)
- def test_demo_projects_not_counted_toward_limit(self):
+ @patch("posthog.tasks.demo_create_data.create_data_for_demo_team.delay")
+ def test_demo_projects_not_counted_toward_limit(self, _mock_create_demo_data: MagicMock):
# Set project limit to 2
self.organization.available_product_features = [
{
diff --git a/posthog/api/test/test_signup_demo.py b/posthog/api/test/test_signup_demo.py
index 7a5d9fc7fdf2..35bf7cf047ab 100644
--- a/posthog/api/test/test_signup_demo.py
+++ b/posthog/api/test/test_signup_demo.py
@@ -1,5 +1,6 @@
import pytest
from posthog.test.base import APIBaseTest
+from unittest.mock import MagicMock, patch
from django.contrib import auth
from django.test import override_settings
@@ -83,7 +84,8 @@ class TestDemoSignupAPI(APIBaseTest):
assert user.is_staff is False
self.tearDown()
- def test_social_signup_give_staff_privileges(self, *args):
+ @patch("products.demo.backend.facade.api.MatrixManager.run_on_team")
+ def test_social_signup_give_staff_privileges(self, mock_run_on_team: MagicMock):
assert not User.objects.exists()
assert not Organization.objects.exists()
@@ -104,22 +106,20 @@ class TestDemoSignupAPI(APIBaseTest):
)
user = auth.get_user(self.client)
- master_organization = Organization.objects.filter(id=0).first()
user_organization = Organization.objects.filter(name="Tech R Us").first()
assert response.status_code == status.HTTP_201_CREATED
assert response.json() == {"continue_url": "/complete/google-oauth2/"}
- assert Organization.objects.count() == 2 # Master organization "PostHog" & "Tech R Us"
+ assert Organization.objects.count() == 1
assert User.objects.count() == 1
assert isinstance(user, User)
- assert master_organization is not None
- assert master_organization.name == "PostHog"
assert user_organization is not None
assert user.organization == user_organization
assert user.first_name == "Charlie"
assert user.email == "[email protected]"
assert user.is_active is True
assert user.is_staff is True
+ mock_run_on_team.assert_called_once_with(user.team, user)
def test_social_login_give_staff_privileges(self, *args):
assert not User.objects.exists()