1
0
This commit is contained in:
2024-01-15 20:20:10 +00:00
parent c75ea4ea9d
commit 38cd64ea9a
87 changed files with 3946 additions and 2040 deletions

View File

@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
# type: ignore
from bthlabs_jsonrpc_core import exceptions
from django.contrib.auth.models import User
from django.test import Client
def test_view(client):
def test_view(client: Client):
# Given
batch = [
{
@@ -48,25 +51,27 @@ def test_view(client):
assert data == expected_result_data
def test_view_empty_response(client, call):
def test_view_empty_response(client: Client, single_call: dict):
# Given
call.pop('id')
single_call.pop('id')
# When
response = client.post('/rpc', data=call, content_type='application/json')
response = client.post(
'/rpc', data=single_call, content_type='application/json',
)
# Then
assert response.status_code == 200
assert response.content == b''
def test_view_with_auth_checks(client, user, call):
def test_view_with_auth_checks(client: Client, user: User, single_call: dict):
# Given
client.force_login(user)
# When
response = client.post(
'/rpc/private', data=call, content_type='application/json',
'/rpc/private', data=single_call, content_type='application/json',
)
# Then
@@ -75,16 +80,17 @@ def test_view_with_auth_checks(client, user, call):
data = response.json()
expected_result_data = {
'jsonrpc': '2.0',
'id': 'system.list_methods',
'id': 'test',
'result': ['system.list_methods'],
}
assert data == expected_result_data
def test_view_with_auth_checks_permission_denied(client, call):
def test_view_with_auth_checks_permission_denied(client: Client,
single_call: dict):
# When
response = client.post(
'/rpc/private', data=call, content_type='application/json',
'/rpc/private', data=single_call, content_type='application/json',
)
# Then