0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/api/test/test_team.py
Michael Matloka 5d5ede19e4
Fix REST hook firing (#2894)
* Fix REST hooks being only fired if project has webhook

* Fix firing more

* Actually still filter but also for Zapier

* Don't .only() Team in EE process_event to optimize REST hook firing

* Fix REST hook duplication in EE

* Update test_process_event.py

* Debug

* Revert "Debug"

This reverts commit 6d4c9f754d.

* Fix organization-less teams partly

* Fix more organization-less teams

* Fix moar organization-less teams

* Explicitly bootstrap org without user in tests

* Fix org bootstrap

* Fix typing

* Fix bootstrap usage

* Update test_process_event.py

* Fix num queries

* Add test_action_on_perform_hook_fired_once

* Fix Action.objects.create call

* Don't test hook firing as it's offloaded to worker
2021-01-12 13:09:27 +01:00

40 lines
2.0 KiB
Python

from ee.api.test.base import APILicensedTest
from posthog.models.organization import Organization, OrganizationMembership
from posthog.models.team import Team
from posthog.models.user import User
class TestTeamEnterpriseAPI(APILicensedTest):
def test_create_team(self):
response = self.client.post("/api/projects/", {"name": "Test"})
self.assertEqual(response.status_code, 201)
self.assertEqual(Team.objects.count(), 2)
response_data = response.json()
self.assertEqual(response_data.get("name"), "Test")
self.assertEqual(self.organization.teams.count(), 2)
def test_delete_team_own_second(self):
team = Team.objects.create(organization=self.organization)
response = self.client.delete(f"/api/projects/{team.id}")
self.assertEqual(response.status_code, 204)
self.assertEqual(Team.objects.filter(organization=self.organization).count(), 1)
def test_no_delete_team_not_administrating_organization(self):
self.organization_membership.level = OrganizationMembership.Level.MEMBER
self.organization_membership.save()
team = Team.objects.create(organization=self.organization)
response = self.client.delete(f"/api/projects/{team.id}")
self.assertEqual(response.status_code, 403)
self.assertEqual(Team.objects.filter(organization=self.organization).count(), 2)
def test_no_delete_team_not_belonging_to_organization(self):
team_1 = Organization.objects.bootstrap(None)[2]
response = self.client.delete(f"/api/projects/{team_1.id}")
self.assertEqual(response.status_code, 404)
self.assertTrue(Team.objects.filter(id=team_1.id).exists())
organization, _, _ = User.objects.bootstrap("X", "someone@x.com", "qwerty", "Someone")
team_2 = Team.objects.create(organization=organization)
response = self.client.delete(f"/api/projects/{team_2.id}")
self.assertEqual(response.status_code, 404)
self.assertEqual(Team.objects.filter(organization=organization).count(), 2)