@@ -16,43 +16,51 @@ def test_remote_permissions_on_create(foo_permission):
1616
1717@pytest .mark .django_db
1818def test_remote_permission_refresh (foo_type ):
19- rd = RoleDefinition .objects .managed .org_admin
19+ org_admin_rd = RoleDefinition .objects .managed .org_admin
20+ auditor_rd = RoleDefinition .objects .managed .sys_auditor
2021
2122 foo_permission = DABPermission .objects .create (codename = 'foo_foo' , content_type = foo_type )
23+ view_foo = DABPermission .objects .create (codename = 'view_foo' , content_type = foo_type )
2224
2325 # the foo_permission was created after the managed role
2426 # so the role is not explicitly created
25- assert foo_permission not in rd .permissions .all ()
27+ assert foo_permission not in org_admin_rd .permissions .all ()
28+ assert view_foo not in auditor_rd .permissions .all ()
2629
2730 # Loading it requires the refresh call
2831 permission_registry .create_managed_roles (apps , update_perms = True )
29- assert foo_permission in rd .permissions .all ()
32+ assert foo_permission in org_admin_rd .permissions .all ()
33+ assert view_foo in auditor_rd .permissions .all ()
34+
35+ # calling multiple times should be okay
36+ permission_registry .create_managed_roles (apps , update_perms = True )
3037
3138
3239@pytest .mark .django_db
3340def test_remote_permission_load_update_roles ():
3441 rd = RoleDefinition .objects .managed .org_admin
35- DABContentType .objects .load_remote_objects (
36- [
37- {'service' : 'fooland' , 'app_label' : 'foo' , 'model' : 'foo' , 'api_slug' : 'fooland.foo' , 'parent_content_type' : 'shared.organization' },
38- {'service' : 'fooland' , 'app_label' : 'foo' , 'model' : 'bar' , 'api_slug' : 'fooland.bar' , 'parent_content_type' : None },
39- ]
40- )
42+ remote_types = [
43+ {'service' : 'fooland' , 'app_label' : 'foo' , 'model' : 'foo' , 'api_slug' : 'fooland.foo' , 'parent_content_type' : 'shared.organization' },
44+ {'service' : 'fooland' , 'app_label' : 'foo' , 'model' : 'bar' , 'api_slug' : 'fooland.bar' , 'parent_content_type' : None },
45+ ]
46+ DABContentType .objects .load_remote_objects (remote_types )
4147 assert not DABPermission .objects .filter (codename = 'foo_foo' ).exists ()
42- DABPermission .objects .load_remote_objects (
43- [
44- {'codename' : 'foo_foo' , 'content_type' : 'fooland.foo' , 'api_slug' : "fooland.foo_foo" },
45- {'codename' : 'bar_bar' , 'content_type' : 'fooland.bar' , 'api_slug' : "fooland.bar_bar" },
46- ],
47- update_managed = True ,
48- )
48+ remote_perms = [
49+ {'codename' : 'foo_foo' , 'content_type' : 'fooland.foo' , 'api_slug' : "fooland.foo_foo" },
50+ {'codename' : 'bar_bar' , 'content_type' : 'fooland.bar' , 'api_slug' : "fooland.bar_bar" },
51+ ]
52+ DABPermission .objects .load_remote_objects (remote_perms , update_managed = True )
4953 assert DABPermission .objects .filter (codename = 'foo_foo' ).exists ()
5054
5155 foo_permission = DABPermission .objects .get (codename = 'foo_foo' )
5256 bar_permission = DABPermission .objects .get (codename = 'bar_bar' )
5357 assert foo_permission in rd .permissions .all ()
5458 assert bar_permission not in rd .permissions .all () # not child type of organization
5559
60+ # calling twice should be fine
61+ DABContentType .objects .load_remote_objects (remote_types )
62+ DABPermission .objects .load_remote_objects (remote_perms , update_managed = True )
63+
5664
5765@pytest .mark .django_db
5866def test_remote_permission_duplicate_name ():
0 commit comments