From e63f2116cda8ce15efd9f0281d2950d1b4591498 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 7 May 2018 14:34:41 -0700 Subject: [PATCH] cleanup --- tests/test_decks.py | 8 ++++---- tests/test_misc.py | 16 +++++++--------- tests/util.py | 15 +++++++++------ 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/test_decks.py b/tests/test_decks.py index 835bedc..f71601d 100755 --- a/tests/test_decks.py +++ b/tests/test_decks.py @@ -19,21 +19,21 @@ class TestDeckNamesAndIds(unittest.TestCase): class TestCreateDeck(unittest.TestCase): def tearDown(self): - util.invoke('deleteDecks', {'decks': ['test']}) + util.invoke('deleteDecks', decks=['test']) def runTest(self): - util.invoke('createDeck', {'deck': 'test'}) + util.invoke('createDeck', deck='test') self.assertIn('test', util.invoke('deckNames')) class TestDeleteDecks(unittest.TestCase): def setUp(self): - util.invoke('createDeck', {'deck': 'test'}) + util.invoke('createDeck', deck='test') def runTest(self): - util.invoke('deleteDecks', {'decks': ['test']}) + util.invoke('deleteDecks', decks=['test']) self.assertNotIn('test', util.invoke('deckNames')) diff --git a/tests/test_misc.py b/tests/test_misc.py index 9de5d9e..ad1ea9e 100755 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -6,8 +6,7 @@ import util class TestVersion(unittest.TestCase): def runTest(self): - result = util.invoke('version') - self.assertEqual(result, 5) + self.assertEqual(util.invoke('version'), 5) class TestUpgrade(unittest.TestCase): @@ -23,13 +22,12 @@ class TestSync(unittest.TestCase): class TestMulti(unittest.TestCase): def runTest(self): result = util.invoke( - 'multi', { - 'actions': [ - util.request('version'), - util.request('version'), - util.request('version') - ] - } + 'multi', + actions=[ + util.request('version'), + util.request('version'), + util.request('version') + ] ) self.assertEqual(len(result), 3) diff --git a/tests/util.py b/tests/util.py index 2657867..3435b97 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,14 +1,17 @@ import json import urllib2 - -def request(action, params={}, version=5): - return {'action': action, 'params': params, 'version': version} +API_VERSION = 5 +API_URL = 'http://localhost:8765' -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))) +def request(action, **params): + return {'action': action, 'params': params, 'version': API_VERSION} + + +def invoke(action, **params): + requestJson = json.dumps(request(action, **params)) + response = json.load(urllib2.urlopen(urllib2.Request(API_URL, requestJson))) if len(response) != 2: raise Exception('response has an unexpected number of fields') if 'error' not in response: