forked from yezz123/Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_request.py
37 lines (29 loc) · 976 Bytes
/
test_request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# standard imports
import unittest
# local imports
from src.base import JSON_PRC
from src.interface import (
json_request,
json_response,
json_result,
json_is_response_to,
)
class TestRequest(unittest.TestCase):
def test_request(self):
req = json_request('foo_barBaz')
self.assertEqual(req['jsonrpc'], JSON_PRC.version_string)
self.assertEqual(type(req['id']).__name__, 'str')
self.assertEqual(req['method'], 'foo_barBaz')
self.assertEqual(len(req['params']), 0)
def test_response(self):
res = json_response('foo', 42)
self.assertEqual(res['id'], 'foo')
self.assertEqual(res['result'], 42)
r = json_result(res, None)
self.assertEqual(r, 42)
def test_response_compare(self):
req = json_request('foo_barBaz')
res = json_response(req['id'], 42)
self.assertTrue(json_is_response_to(req, res))
if __name__ == '__main__':
unittest.main()