add tests
This commit is contained in:
@@ -3,9 +3,10 @@
|
|||||||
## aiohttp
|
## aiohttp
|
||||||
|
|
||||||
```
|
```
|
||||||
from jsonrpc.backend.aiohttp import APIView
|
from jsonrpc.backend.aiohttp import APIHandler
|
||||||
|
|
||||||
app.router.add_view('/api', APIView)
|
handler = APIHandler(jsonrpc)
|
||||||
|
app.router.add_view('/api', APIHandler)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Flask
|
## Flask
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from .. import JSONRPC
|
|||||||
|
|
||||||
pathlib.Path(__file__).parent.resolve()
|
pathlib.Path(__file__).parent.resolve()
|
||||||
|
|
||||||
class APIView:
|
class APIHandler:
|
||||||
def __init__(self, jsonrpc):
|
def __init__(self, jsonrpc):
|
||||||
self.jsonrpc = jsonrpc
|
self.jsonrpc = jsonrpc
|
||||||
|
|
||||||
|
|||||||
2
tests/__init__.py
Normal file
2
tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
__author__ = 'RemiZOffAlex'
|
||||||
|
__email__ = 'remizoffalex@mail.ru'
|
||||||
47
tests/test_jsonrpc.py
Normal file
47
tests/test_jsonrpc.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
__author__ = 'RemiZOffAlex'
|
||||||
|
__email__ = 'remizoffalex@mail.ru'
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from jsonrpc import JSONRPC
|
||||||
|
|
||||||
|
|
||||||
|
jsonrpc = JSONRPC()
|
||||||
|
|
||||||
|
@jsonrpc.method('boo')
|
||||||
|
def index() -> str:
|
||||||
|
return 'Welcome to JSON-RPC'
|
||||||
|
|
||||||
|
class Calc(unittest.TestCase):
|
||||||
|
def test_method_exist(self):
|
||||||
|
self.assertIn('boo', jsonrpc.methods)
|
||||||
|
|
||||||
|
def test_example(self):
|
||||||
|
self.assertEqual(
|
||||||
|
jsonrpc.example('boo'),
|
||||||
|
{'jsonrpc': '2.0', 'method': 'boo', 'id': 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_evaluate(self):
|
||||||
|
request = {'jsonrpc': '2.0', 'method': 'boo', 'id': 1}
|
||||||
|
response = jsonrpc(request)
|
||||||
|
self.assertEqual(
|
||||||
|
response,
|
||||||
|
{'jsonrpc': '2.0', 'result': 'Welcome to JSON-RPC', 'id': 1}
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_error(self):
|
||||||
|
request = {'jsonrpc': '2.0', 'method': 'bla-bla', 'id': 1}
|
||||||
|
response = jsonrpc(request)
|
||||||
|
print(response)
|
||||||
|
self.assertEqual(
|
||||||
|
response,
|
||||||
|
{
|
||||||
|
'jsonrpc': '2.0',
|
||||||
|
'error': {
|
||||||
|
'code': -32601,
|
||||||
|
'message': 'Метод не найден: bla-bla'
|
||||||
|
},
|
||||||
|
'id': 1
|
||||||
|
}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user