0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/api/test/test_dashboard.py
Michael Matloka d5d497f11f
Migrate dashboard-related logics to be project-based (#6623)
* Migrate dashboard-related logics to be project-based

* Update test_personal_api_keys.py

* Update dashboard.py

* Update test_dashboard.py

* Make mypy happy
2021-10-25 16:16:55 +02:00

50 lines
2.3 KiB
Python

from rest_framework import status
from ee.api.test.base import APILicensedTest
from ee.models.explicit_team_membership import ExplicitTeamMembership
from posthog.models import OrganizationMembership
from posthog.models.dashboard import Dashboard
class TestDashboardEnterpriseAPI(APILicensedTest):
def setUp(self):
super().setUp()
self.team.access_control = True
self.team.save()
def test_retrieve_dashboard_forbidden_for_project_outsider(self):
self.organization_membership.level = OrganizationMembership.Level.MEMBER
self.organization_membership.save()
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_retrieve_dashboard_forbidden_for_org_admin(self):
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_retrieve_dashboard_allowed_for_project_member(self):
self.organization_membership.level = OrganizationMembership.Level.MEMBER
self.organization_membership.save()
ExplicitTeamMembership.objects.create(team=self.team, parent_membership=self.organization_membership)
dashboard = Dashboard.objects.create(
team=self.team, name="private dashboard", created_by=self.user, tags=["deprecated"]
)
response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}")
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_shared_dashboard_in_private_project(self):
self.client.logout()
Dashboard.objects.create(
team=self.team, share_token="testtoken", name="public dashboard", is_shared=True,
)
response = self.client.get("/shared_dashboard/testtoken")
self.assertEqual(response.status_code, status.HTTP_200_OK)