Skip to content

Commit 60689b6

Browse files
CristopherH95federicobond
authored andcommitted
Add async test case
1 parent 7f4bc62 commit 60689b6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/testsuite/test_permissions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from asgiref.sync import sync_to_async
12
from unittest import TestCase
23

34
from 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")

0 commit comments

Comments
 (0)