Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add tests to get_permissions_user_has_not

IKarbowiakc316f39f7826
diff --git a/tests/api/test_account_utils.py b/tests/api/test_account_utils.py
index 94154e23c5..ac2ebc8f99 100644
--- a/tests/api/test_account_utils.py
+++ b/tests/api/test_account_utils.py
@@ -1,4 +1,8 @@
-from saleor.graphql.account.utils import can_user_manage_group
+from saleor.core.permissions import AccountPermissions, OrderPermissions
+from saleor.graphql.account.utils import (
+ can_user_manage_group,
+ get_permissions_user_has_not,
+)
def test_can_manage_group_user_without_permissions(
@@ -35,3 +39,31 @@ def test_can_manage_group_user_superuser(
):
result = can_user_manage_group(admin_user, permission_group_manage_users)
assert result
+
+
+def test_get_permissions_user_has_not_user_has_all_permissions(
+ staff_user, permission_manage_orders, permission_manage_users
+):
+ staff_user.user_permissions.add(permission_manage_orders, permission_manage_users)
+ result = get_permissions_user_has_not(
+ staff_user, [AccountPermissions.MANAGE_USERS, OrderPermissions.MANAGE_ORDERS]
+ )
+ assert not result
+
+
+def test_get_permissions_user_has_not_user_does_not_have_all_permissions(
+ staff_user, permission_manage_orders, permission_manage_users
+):
+ staff_user.user_permissions.add(permission_manage_orders)
+ result = get_permissions_user_has_not(
+ staff_user, [AccountPermissions.MANAGE_USERS, OrderPermissions.MANAGE_ORDERS]
+ )
+ assert result == [AccountPermissions.MANAGE_USERS]
+
+
+def test_get_permissions_user_has_not_user_without_permissions(
+ staff_user, permission_manage_orders, permission_manage_users
+):
+ permissions = [AccountPermissions.MANAGE_USERS, OrderPermissions.MANAGE_ORDERS]
+ result = get_permissions_user_has_not(staff_user, permissions)
+ assert result == permissions