From c22d66b350db2e213cc916fae4f6207440a9be4f Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 19 Dec 2016 22:12:58 +0100 Subject: Create new empty entry, also from the command line --- tests/test_collection.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/test_collection.py') diff --git a/tests/test_collection.py b/tests/test_collection.py index c54dc32..1bacfd6 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -24,7 +24,7 @@ class testCollectionLoading(unittest.TestCase): self.collection = lesana.Collection('tests/data/simple') self.assertIsNotNone(self.collection.settings) self.assertEqual(self.collection.settings['name'], "Simple lesana collection") - self.assertEqual(len(self.collection.settings['fields']), 3) + self.assertEqual(len(self.collection.settings['fields']), 4) self.collection.update_cache() self.assertIsNotNone(self.collection.cache) @@ -59,7 +59,7 @@ class testEntries(unittest.TestCase): data = ruamel.yaml.load(fp) entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.idterm, 'Q'+data['uid']) - self.assertEqual(len(entry.indexed_fields), 3) + self.assertEqual(len(entry.indexed_fields), 4) fname = '11189ee47ddf4796b718a483b379f976.yaml' uid = '11189ee47ddf4796b718a483b379f976' with open(os.path.join(self.basepath, fname)) as fp: @@ -67,3 +67,36 @@ class testEntries(unittest.TestCase): entry = lesana.Entry(self.collection, data=data, fname=fname) self.assertEqual(entry.idterm, 'Q'+uid) self.assertEqual(len(entry.indexed_fields), 3) + + def test_write_new(self): + new_entry = lesana.Entry(self.collection) + self.collection.save_entries(entries=[new_entry]) + entry_fname = 'tests/data/simple/items/' + new_entry.fname + with open(entry_fname) as fp: + written = ruamel.yaml.load(fp) + self.assertIsInstance(written['quantity'], int) + self.assertIsInstance(written['name'], str) + os.remove(entry_fname) + + +class testComplexCollection(unittest.TestCase): + @classmethod + def setUpClass(self): + self.collection = lesana.Collection('tests/data/complex') + + @classmethod + def tearDownClass(self): + shutil.rmtree(os.path.join(self.collection.basedir, '.lesana')) + + def test_init(self): + self.assertIsNotNone(self.collection.settings) + self.assertEqual( + self.collection.settings['name'], + "Fully featured lesana collection" + ) + self.assertEqual(len(self.collection.settings['fields']), 3) + self.assertIsNotNone(self.collection.stemmer) + + def test_index(self): + self.collection.update_cache() + self.assertIsNotNone(self.collection.cache) -- cgit v1.2.3