Skip to content

Commit a88299e

Browse files
committed
[qa] Document database queries in permission class tests #256
Add assertNumQueries to the organization manager permission test to document the expected database queries triggered by permission and object-level access checks. These queries are intentional and required for security and multi-tenancy, and documenting them helps prevent confusion and accidental regressions. Fixes #256 Please enter the commit message for your changes. Lines starting
1 parent 34d7fa8 commit a88299e

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

tests/testapp/tests/test_permission_classes.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,6 @@ def test_operator_none(self):
3636
response = self.client.get(self.owner_url, **auth)
3737
self.assertEqual(response.status_code, 403)
3838

39-
def test_operator_manager(self):
40-
operator = self._get_operator()
41-
# First user is automatically owner, so created dummy
42-
# user to keep operator as manager only.
43-
self._create_org_user(user=self._get_user(), is_admin=True)
44-
self._create_org_user(user=operator, is_admin=True)
45-
token = self._obtain_auth_token()
46-
auth = dict(HTTP_AUTHORIZATION=f"Bearer {token}")
47-
48-
with self.subTest("Organization Member"):
49-
response = self.client.get(self.member_url, **auth)
50-
self.assertEqual(response.status_code, 200)
51-
52-
# Organization Manager
53-
# Query breakdown for IsOrganizationManager permission check:
54-
# 1 query for IsOrganizationManager.has_permission() checking
55-
# organizations_managed. Remaining queries are for object
56-
# creation/get and object-level permission checks
57-
with self.assertNumQueries(5):
58-
response = self.client.get(self.manager_url, **auth)
59-
self.assertEqual(response.status_code, 200)
60-
61-
with self.subTest("Organization Owner"):
62-
response = self.client.get(self.owner_url, **auth)
63-
self.assertEqual(response.status_code, 403)
64-
65-
6639
def test_operator_manager(self):
6740
operator = self._get_operator()
6841
# First user is automatically owner, so created dummy
@@ -71,17 +44,20 @@ def test_operator_manager(self):
7144
self._create_org_user(user=operator, is_admin=True)
7245
token = self._obtain_auth_token()
7346
auth = dict(HTTP_AUTHORIZATION=f"Bearer {token}")
47+
7448
with self.subTest("Organization Member"):
7549
response = self.client.get(self.member_url, **auth)
7650
self.assertEqual(response.status_code, 200)
77-
with self.subTest("Organization Manager"):
78-
# Query breakdown for IsOrganizationManager permission check:
79-
# 1 query for IsOrganizationManager.has_permission() checking
80-
# organizations_managed. Remaining queries are for object
81-
# creation/get and object-level permission checks
82-
with self.assertNumQueries(5):
83-
response = self.client.get(self.manager_url, **auth)
84-
self.assertEqual(response.status_code, 200)
51+
52+
# Organization Manager
53+
# Query breakdown for IsOrganizationManager permission check:
54+
# 1 query for IsOrganizationManager.has_permission() checking
55+
# organizations_managed. Remaining queries are for object
56+
# creation/get and object-level permission checks
57+
with self.assertNumQueries(4):
58+
response = self.client.get(self.manager_url, **auth)
59+
self.assertEqual(response.status_code, 200)
60+
8561
with self.subTest("Organization Owner"):
8662
response = self.client.get(self.owner_url, **auth)
8763
self.assertEqual(response.status_code, 403)

0 commit comments

Comments
 (0)