From 033e3ab813639b788efc9805f3f06f292886f408 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 19 Oct 2013 20:02:26 +0200 Subject: [PATCH] jsonrpc: Test application error responses again The test was modified to not fail after a refactoring, making it not test what it was intended to test at all. This reverts the changes and updates the test in another way, keeping the original intention. --- tests/utils/jsonrpc_test.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/utils/jsonrpc_test.py b/tests/utils/jsonrpc_test.py index 7abaa512..c6f516bb 100644 --- a/tests/utils/jsonrpc_test.py +++ b/tests/utils/jsonrpc_test.py @@ -34,6 +34,9 @@ class Calculator(object): def _secret(self): return 'Grand Unified Theory' + def fail(self): + raise ValueError('What did you expect?') + class JsonRpcTestBase(unittest.TestCase): def setUp(self): @@ -313,19 +316,26 @@ class JsonRpcBatchTest(JsonRpcTestBase): class JsonRpcSingleCommandErrorTest(JsonRpcTestBase): - def test_application_error_response_is_none(self): + def test_application_error_response(self): request = { 'jsonrpc': '2.0', - 'method': 'core.tracklist.index', - 'params': ['bogus'], + 'method': 'calc.fail', + 'params': [], 'id': 1, } response = self.jrw.handle_data(request) - self.assertIn('result', response) + self.assertNotIn('result', response) - result = response['result'] - self.assertEqual(result, None) + error = response['error'] + self.assertEqual(error['code'], 0) + self.assertEqual(error['message'], 'Application error') + + data = error['data'] + self.assertEqual(data['type'], 'ValueError') + self.assertIn('What did you expect?', data['message']) + self.assertIn('traceback', data) + self.assertIn('Traceback (most recent call last):', data['traceback']) def test_missing_jsonrpc_member_causes_invalid_request_error(self): request = {