aboutsummaryrefslogtreecommitdiff
path: root/tests/test_collection.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-19 22:12:58 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2016-12-19 22:12:58 +0100
commitc22d66b350db2e213cc916fae4f6207440a9be4f (patch)
treed5863b0eb1b97b154a714dbacecf326655293d9d /tests/test_collection.py
parent1c587b319a308a877608531961491f1dbb79317b (diff)
Create new empty entry, also from the command line
Diffstat (limited to 'tests/test_collection.py')
-rw-r--r--tests/test_collection.py37
1 files changed, 35 insertions, 2 deletions
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)