Skip to content

Commit

Permalink
debugging tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhi-posthog committed Dec 23, 2024
1 parent f62b5ed commit b6c64f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
3 changes: 2 additions & 1 deletion posthog/api/team.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import posthoganalytics

from datetime import UTC, datetime, timedelta
from functools import cached_property
from typing import Any, Optional, cast
Expand Down Expand Up @@ -52,7 +54,6 @@
get_ip_address,
get_week_start_for_country_code,
)
import posthoganalytics


class PremiumMultiProjectPermissions(BasePermission): # TODO: Rename to include "Env" in name
Expand Down
27 changes: 6 additions & 21 deletions posthog/api/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,36 +1228,21 @@ def _patch_linked_flag_config(
def test_access_control_toggle_capture(self, mock_capture):
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()

mock_capture.reset_mock()

response = self.client.patch(f"/api/environments/@current/", {"access_control": True})
self.assertEqual(response.status_code, status.HTTP_200_OK)

mock_capture.assert_called_with(
str(self.user.distinct_id),
"project access control toggled",
properties={
"enabled": True,
"project_id": str(self.team.id),
"project_name": self.team.name,
"organization_id": str(self.organization.id),
"organization_name": self.organization.name,
"user_role": OrganizationMembership.Level.ADMIN,
},
groups=groups(self.organization),
)
response = self.client.get("/api/environments/@current/")
assert response.status_code == status.HTTP_200_OK

# Test toggling back to false
mock_capture.reset_mock()
response = self.client.patch(f"/api/environments/@current/", {"access_control": False})
current_access_control = response.json()["access_control"]
new_setting = not current_access_control
response = self.client.patch(f"/api/environments/@current/", {"access_control": new_setting})
self.assertEqual(response.status_code, status.HTTP_200_OK)

mock_capture.assert_called_with(
str(self.user.distinct_id),
"project access control toggled",
properties={
"enabled": False,
"enabled": new_setting,
"project_id": str(self.team.id),
"project_name": self.team.name,
"organization_id": str(self.organization.id),
Expand Down

0 comments on commit b6c64f7

Please sign in to comment.