File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1+ from asgiref .sync import sync_to_async
12from unittest import TestCase
23
34from rules .permissions import (
@@ -50,3 +51,17 @@ def test_backend(self):
5051 assert not backend .has_perm (None , "can_edit_book" )
5152 remove_perm ("can_edit_book" )
5253 assert not perm_exists ("can_edit_book" )
54+
55+ async def test_backend_async (self ):
56+ backend = ObjectPermissionBackend ()
57+
58+ await sync_to_async (add_perm )("can_edit_book" , always_true )
59+ assert "can_edit_book" in permissions
60+ assert await backend .ahas_perm (None , "can_edit_book" )
61+ assert await backend .ahas_module_perms (None , "can_edit_book" )
62+ with self .assertRaises (KeyError ):
63+ await sync_to_async (add_perm )("can_edit_book" , always_true )
64+ await sync_to_async (set_perm )("can_edit_book" , always_false )
65+ assert not await backend .ahas_perm (None , "can_edit_book" )
66+ await sync_to_async (remove_perm )("can_edit_book" )
67+ assert not await sync_to_async (perm_exists )("can_edit_book" )
You can’t perform that action at this time.
0 commit comments