From d33b4e0dc75236719d4f7efe0fd92e2a10a04959 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 6 May 2018 19:01:24 -0700 Subject: [PATCH] wip --- tests/test_misc.py | 10 +++++----- tests/util.py | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index a88a8c9..6e2dbb3 100755 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -4,22 +4,22 @@ import unittest import util -class TestVersion(unittest.TestCase): +class TestMisc(unittest.TestCase): def test_version(self): - result = util.invokeNoError('version') + result = util.invoke('version') self.assertEqual(result, 5) def test_upgrade(self): - util.invokeNoError('upgrade') + util.invoke('upgrade') def test_sync(self): - util.invokeNoError('sync') + util.invoke('sync') def test_multi(self): - result = util.invokeNoError( + result = util.invoke( 'multi', { 'actions': [ util.request('version'), diff --git a/tests/util.py b/tests/util.py index ba6d1d1..2657867 100644 --- a/tests/util.py +++ b/tests/util.py @@ -9,11 +9,12 @@ def request(action, params={}, version=5): def invoke(action, params={}, version=5, url='http://localhost:8765'): requestJson = json.dumps(request(action, params, version)) response = json.load(urllib2.urlopen(urllib2.Request(url, requestJson))) - return response['result'], response['error'] - - -def invokeNoError(action, params={}, version=5, url='http://localhost:8765'): - result, error = invoke(action, params, version, url) - if error is not None: - raise Exception(error) - return result + if len(response) != 2: + raise Exception('response has an unexpected number of fields') + if 'error' not in response: + raise Exception('response is missing required error field') + if 'result' not in response: + raise Exception('response is missing required result field') + if response['error'] is not None: + raise Exception(response['error']) + return response['result']