Skip to content

Commit

Permalink
Test for internal error.
Browse files Browse the repository at this point in the history
  • Loading branch information
aodag committed May 5, 2011
1 parent 177b86f commit fb903f0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pyramid_rpc/tests/test_jsonrpc.py
Expand Up @@ -79,6 +79,23 @@ def test_jsonrpc_endpoint_parse_error(self):
data = json.loads(response.body)
self.assertEqual(data['error']['code'], -32700)

def test_jsonrpc_endpoint_internal_error(self):
from pyramid.interfaces import IViewClassifier
def error_view(request):
raise Exception
rpc_iface = self._registerRouteRequest('JSON-RPC')
self._registerView(error_view, 'error', IViewClassifier, rpc_iface, None)

jsonrpc_endpoint = self._makeOne()
request = self._makeDummyRequest()
request.body = ErrorJSONBody
request.content_length = len(request.body)
request.matched_route = DummyRoute('JSON-RPC')
response = jsonrpc_endpoint(request)
data = json.loads(response.body)
self.assertEqual(data['error']['code'], -32603)


DummyJSONBody = """{
"jsonrpc": "2.0",
"id": null,
Expand All @@ -87,6 +104,14 @@ def test_jsonrpc_endpoint_parse_error(self):
}
"""

ErrorJSONBody = """{
"jsonrpc": "2.0",
"id": null,
"method": "error",
"params": [13]
}
"""

class DummyRoute:
def __init__(self, route_name):
self.name = route_name
Expand Down

0 comments on commit fb903f0

Please sign in to comment.