This commit is contained in:
Alex Yatskov 2018-05-07 14:34:41 -07:00
parent 409245c41b
commit e63f2116cd
3 changed files with 20 additions and 19 deletions

View File

@ -19,21 +19,21 @@ class TestDeckNamesAndIds(unittest.TestCase):
class TestCreateDeck(unittest.TestCase): class TestCreateDeck(unittest.TestCase):
def tearDown(self): def tearDown(self):
util.invoke('deleteDecks', {'decks': ['test']}) util.invoke('deleteDecks', decks=['test'])
def runTest(self): def runTest(self):
util.invoke('createDeck', {'deck': 'test'}) util.invoke('createDeck', deck='test')
self.assertIn('test', util.invoke('deckNames')) self.assertIn('test', util.invoke('deckNames'))
class TestDeleteDecks(unittest.TestCase): class TestDeleteDecks(unittest.TestCase):
def setUp(self): def setUp(self):
util.invoke('createDeck', {'deck': 'test'}) util.invoke('createDeck', deck='test')
def runTest(self): def runTest(self):
util.invoke('deleteDecks', {'decks': ['test']}) util.invoke('deleteDecks', decks=['test'])
self.assertNotIn('test', util.invoke('deckNames')) self.assertNotIn('test', util.invoke('deckNames'))

View File

@ -6,8 +6,7 @@ import util
class TestVersion(unittest.TestCase): class TestVersion(unittest.TestCase):
def runTest(self): def runTest(self):
result = util.invoke('version') self.assertEqual(util.invoke('version'), 5)
self.assertEqual(result, 5)
class TestUpgrade(unittest.TestCase): class TestUpgrade(unittest.TestCase):
@ -23,13 +22,12 @@ class TestSync(unittest.TestCase):
class TestMulti(unittest.TestCase): class TestMulti(unittest.TestCase):
def runTest(self): def runTest(self):
result = util.invoke( result = util.invoke(
'multi', { 'multi',
'actions': [ actions=[
util.request('version'), util.request('version'),
util.request('version'), util.request('version'),
util.request('version') util.request('version')
] ]
}
) )
self.assertEqual(len(result), 3) self.assertEqual(len(result), 3)

View File

@ -1,14 +1,17 @@
import json import json
import urllib2 import urllib2
API_VERSION = 5
def request(action, params={}, version=5): API_URL = 'http://localhost:8765'
return {'action': action, 'params': params, 'version': version}
def invoke(action, params={}, version=5, url='http://localhost:8765'): def request(action, **params):
requestJson = json.dumps(request(action, params, version)) return {'action': action, 'params': params, 'version': API_VERSION}
response = json.load(urllib2.urlopen(urllib2.Request(url, requestJson)))
def invoke(action, **params):
requestJson = json.dumps(request(action, **params))
response = json.load(urllib2.urlopen(urllib2.Request(API_URL, requestJson)))
if len(response) != 2: if len(response) != 2:
raise Exception('response has an unexpected number of fields') raise Exception('response has an unexpected number of fields')
if 'error' not in response: if 'error' not in response: