test(permissions): add unit tests for ScopedOwnerAccessPermission and permission helpers
This commit is contained in:
parent
f579400ac5
commit
e81d4339c3
1 changed files with 33 additions and 0 deletions
|
|
@ -103,3 +103,36 @@ class TestTenantAccessIsolation:
|
||||||
assert res_b.status_code == 400
|
assert res_b.status_code == 400
|
||||||
acct_a.refresh_from_db()
|
acct_a.refresh_from_db()
|
||||||
assert acct_a.name == 'Untouchable Account'
|
assert acct_a.name == 'Untouchable Account'
|
||||||
|
|
||||||
|
def test_tenant_permissions_and_helpers(self):
|
||||||
|
# Cover ScopedOwnerAccessPermission lines
|
||||||
|
from openforce.permissions import ScopedOwnerAccessPermission
|
||||||
|
from rest_framework.request import Request
|
||||||
|
from django.test.client import RequestFactory
|
||||||
|
from custom_objects.models import CustomFieldDefinition
|
||||||
|
|
||||||
|
perm = ScopedOwnerAccessPermission()
|
||||||
|
rf = RequestFactory()
|
||||||
|
req = rf.get('/')
|
||||||
|
req.user = self.user_a
|
||||||
|
|
||||||
|
# Object with no owner, assigned_to, or created_by
|
||||||
|
class DummyObj:
|
||||||
|
pass
|
||||||
|
assert not perm.has_object_permission(req, None, DummyObj())
|
||||||
|
|
||||||
|
# Object with assigned_to matching
|
||||||
|
class AssignedObj:
|
||||||
|
assigned_to = self.user_a
|
||||||
|
assert perm.has_object_permission(req, None, AssignedObj())
|
||||||
|
|
||||||
|
# CustomFieldDefinition ownership via custom_object
|
||||||
|
custom_obj_a = CustomObjectDefinition.objects.create(name='TestA_c', label='Test A', created_by=self.user_a)
|
||||||
|
field_a = CustomFieldDefinition.objects.create(custom_object=custom_obj_a, name='fld_a_c', label='Fld A', field_type='text')
|
||||||
|
assert perm.has_object_permission(req, None, field_a)
|
||||||
|
|
||||||
|
# Unauthenticated user
|
||||||
|
class AnonUser:
|
||||||
|
is_authenticated = False
|
||||||
|
req.user = AnonUser()
|
||||||
|
assert not perm.has_permission(req, None)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue