1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/tests/auth_checks/test_has_perms.py

52 lines
998 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from unittest import mock
from bthlabs_jsonrpc_django import auth_checks
def test_has_perms_regular_user(rf, user):
# Given
request = rf.get('/')
request.user = user
check = auth_checks.has_perms(['can_use_rpc'])
# When
result = check(request)
# Then
assert result is False
def test_has_perms_ok(rf, user):
# Given
request = rf.get('/')
request.user = user
check = auth_checks.has_perms(['can_use_rpc'])
with mock.patch.object(user, 'has_perms') as mock_has_perms:
mock_has_perms.return_value = True
# When
result = check(request)
# Then
assert result is True
mock_has_perms.assert_called_with(['can_use_rpc'])
def test_has_perms_ok_super_user(rf, super_user):
# Given
request = rf.get('/')
request.user = super_user
check = auth_checks.has_perms(['can_use_rpc'])
# When
result = check(request)
# Then
assert result is True