1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/tests/executor/test_DjangoExecutor.py
Tomek Wójcik c75ea4ea9d Initial public releases
* `bthlabs-jsonrpc-aiohttp` v1.0.0
* `bthlabs-jsonrpc-core` v1.0.0
* `bthlabs-jsonrpc-django` v1.0.0
2022-06-04 10:41:53 +02:00

68 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
from unittest import mock
from bthlabs_jsonrpc_core import exceptions
import pytest
from bthlabs_jsonrpc_django import executor
@pytest.fixture
def fake_can_call():
return mock.Mock()
def test_init(rf, fake_can_call):
# Given
request = rf.get('/')
# When
result = executor.DjangoExecutor(request, fake_can_call)
# Then
assert result.request == request
assert result.can_call == fake_can_call
def test_enrich_args(rf, fake_can_call):
# Given
request = rf.get('/')
the_executor = executor.DjangoExecutor(request, fake_can_call)
# When
result = the_executor.enrich_args(['spam'])
# Then
assert result == [request, 'spam']
def test_before_call(rf, fake_can_call):
# Given
request = rf.get('/')
the_executor = executor.DjangoExecutor(request, fake_can_call)
# When
the_executor.before_call('test', ['spam'], {'spam': True})
# Then
fake_can_call.assert_called_with(request, 'test', ['spam'], {'spam': True})
def test_before_call_access_denied(rf, fake_can_call):
# Given
fake_can_call.return_value = False
request = rf.get('/')
the_executor = executor.DjangoExecutor(request, fake_can_call)
# When
try:
the_executor.before_call('test', ['spam'], {'spam': True})
except Exception as exception:
assert isinstance(exception, exceptions.JSONRPCAccessDeniedError)
else:
assert False, 'No exception raised?'