This commit is contained in:
Alex Yatskov 2018-05-06 19:01:24 -07:00
parent fb37ac9f8a
commit d33b4e0dc7
2 changed files with 14 additions and 13 deletions

View File

@ -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'),

View File

@ -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']