Tomek Wójcik
c75ea4ea9d
* `bthlabs-jsonrpc-aiohttp` v1.0.0 * `bthlabs-jsonrpc-core` v1.0.0 * `bthlabs-jsonrpc-django` v1.0.0
52 lines
998 B
Python
52 lines
998 B
Python
# -*- 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
|