Squashed commit of the following:
commit cb509e8f75e3dcdbc66327be4bfbf6661aa084b5 Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 22:06:28 2013 +0100 Cut down 'import' statements to only modules actually used. commit 0ea255115e095e31af5a991e9cce2b5b15cb496d Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 22:00:06 2013 +0100 * Add getCollectionManager() so that the whole process can share the same ThreadingCollectionManager object. * Got the RestApp actually working! commit 00997bab600b13d4b430ed2c2839b1d2232f55ed Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 21:04:58 2013 +0100 Got the sync_app working again (more or less) commit 459c69566bb92d2c0195a384e067d98c059bdea7 Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 19:47:40 2013 +0100 Started implementing test for the RESTful callbacks that PrepECN is going to need. commit 7ffbac793f9bf45ab9056c1de475422b8742e107 Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 17:19:06 2013 +0100 Started work on a WSGI app for RESTful access to Anki based on Bibliobird code here: https://raw.github.com/dsnopek/bbcom/master/AnkiServer/AnkiServer/deck.py commit 8820411388ce0c2b7b14769c614c22c675d2dbdd Author: David Snopek <dsnopek@gmail.com> Date: Fri Jul 12 15:03:56 2013 +0100 * Seperated the collection and threading code. * Implemented a new interface to interact with the collections, which will hopefully be more transparent and testable.
This commit is contained in:
69
tests/test_rest_app.py
Normal file
69
tests/test_rest_app.py
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import AnkiServer
|
||||
from AnkiServer.apps.rest_app import CollectionHandlerGroup, DeckHandlerGroup
|
||||
|
||||
import anki
|
||||
import anki.storage
|
||||
|
||||
class CollectionTestBase(unittest.TestCase):
|
||||
"""Parent class for tests that need a collection set up and torn down."""
|
||||
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self.collection_path = os.path.join(self.temp_dir, 'collection.anki2');
|
||||
self.collection = anki.storage.Collection(self.collection_path)
|
||||
|
||||
def tearDown(self):
|
||||
self.collection.close()
|
||||
self.collection = None
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
class CollectionHandlerGroupTest(CollectionTestBase):
|
||||
def setUp(self):
|
||||
super(CollectionHandlerGroupTest, self).setUp()
|
||||
self.handler = CollectionHandlerGroup()
|
||||
|
||||
def execute(self, name, data):
|
||||
ids = ['collection_name']
|
||||
func = getattr(self.handler, name)
|
||||
return func(self.collection, data, ids)
|
||||
|
||||
def test_list_decks(self):
|
||||
data = {}
|
||||
ret = self.execute('list_decks', data)
|
||||
|
||||
# It contains only the 'Default' deck
|
||||
self.assertEqual(len(ret), 1)
|
||||
self.assertEqual(ret[0]['name'], 'Default')
|
||||
|
||||
def test_select_deck(self):
|
||||
data = {'deck_id': '1'}
|
||||
ret = self.execute('select_deck', data)
|
||||
self.assertEqual(ret, None);
|
||||
|
||||
class DeckHandlerGroupTest(CollectionTestBase):
|
||||
def setUp(self):
|
||||
super(DeckHandlerGroupTest, self).setUp()
|
||||
self.handler = DeckHandlerGroup()
|
||||
|
||||
def execute(self, name, data):
|
||||
ids = ['collection_name', '1']
|
||||
func = getattr(self.handler, name)
|
||||
return func(self.collection, data, ids)
|
||||
|
||||
def test_next_card(self):
|
||||
ret = self.execute('next_card', {})
|
||||
self.assertEqual(ret, None)
|
||||
|
||||
# TODO: add a note programatically
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user