Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JSON RPC response parsing #99

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tests to use simple JSON RPC error objects
kacper-ka committed Aug 29, 2018
commit 6311cccb296fdce63c14929349567afd42a697ba
8 changes: 4 additions & 4 deletions jsonrpc/tests/test_jsonrpc1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import sys

from ..exceptions import JSONRPCInvalidRequestException, JSONRPCInvalidResponseException, JSONRPCParseError
from ..exceptions import JSONRPCInvalidRequestException, JSONRPCInvalidResponseException
from ..jsonrpc1 import (
JSONRPC10Request,
JSONRPC10Response,
@@ -490,17 +490,17 @@ def test_from_json_response_result(self):
self.assertEqual(response._id, 0)

def test_from_json_response_error(self):
err = JSONRPCParseError()
error = {'code': 1, 'message': ''}
str_json = json.dumps({
"result": None,
"error": err._data,
"error": error,
"id": 0,
})

response = JSONRPC10Response.from_json(str_json)
self.assertTrue(isinstance(response, JSONRPC10Response))
self.assertIsNone(response.result)
self.assertEqual(response.error, err._data)
self.assertEqual(response.error, error)
self.assertEqual(response._id, 0)

def test_from_json_string_not_dict(self):
8 changes: 4 additions & 4 deletions jsonrpc/tests/test_jsonrpc2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import sys

from ..exceptions import JSONRPCInvalidRequestException, JSONRPCInvalidResponseException, JSONRPCParseError
from ..exceptions import JSONRPCInvalidRequestException, JSONRPCInvalidResponseException
from ..jsonrpc2 import (
JSONRPC20Request,
JSONRPC20BatchRequest,
@@ -768,17 +768,17 @@ def test_from_json_response_result(self):
self.assertEqual(response._id, 0)

def test_from_json_response_error(self):
err = JSONRPCParseError()
error = {'code': 1, 'message': ''}
str_json = json.dumps({
"jsonrpc": "2.0",
"id": 0,
"error": err._data,
"error": error,
})

response = JSONRPC20Response.from_json(str_json)
self.assertIsInstance(response, JSONRPC20Response)
self.assertIsNone(response.result)
self.assertEqual(response.error, err._data)
self.assertEqual(response.error, error)
self.assertEqual(response._id, 0)