summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-05-21 13:01:23 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2017-05-21 13:01:23 +0200
commit4fe7b851d6ffc86d70577407774532921403ac8d (patch)
tree6fd510543f610d2745c7e36d62b94e73ca86f13e
parent95f32e6c767a03bc1b16bcd5a596b77cb49de9e4 (diff)
Fix creation of an entry with uid but no filename
-rw-r--r--lesana/collection.py3
-rw-r--r--tests/test_collection.py24
2 files changed, 26 insertions, 1 deletions
diff --git a/lesana/collection.py b/lesana/collection.py
index 5b80d3b..d3715d1 100644
--- a/lesana/collection.py
+++ b/lesana/collection.py
@@ -26,7 +26,8 @@ class Entry(object):
self.uid, ext = os.path.splitext(os.path.basename(self.fname))
else:
self.uid = uuid.uuid4().hex
- self.fname = self.uid + '.yaml'
+ if not self.fname:
+ self.fname = self.uid + '.yaml'
def __str__(self):
label = self.collection.settings.get('entry_label', None)
diff --git a/tests/test_collection.py b/tests/test_collection.py
index bcd45e7..891a439 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -164,6 +164,30 @@ class testEntries(unittest.TestCase):
'{uid}: {name}'.format(uid=uid, name='Another item')
)
+ def test_entry_creation_uid_but_no_filename(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ data['uid'] = '11189ee47ddf4796b718a483b379f976'
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertEqual(entry.fname, fname)
+
+ def test_entry_creation_no_uid_no_filename(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data)
+ self.assertIsNotNone(entry.uid)
+ self.assertIsNotNone(entry.fname)
+
+ def test_entry_creation_filename_but_no_uid(self):
+ fname = '11189ee47ddf4796b718a483b379f976.yaml'
+ uid = '11189ee47ddf4796b718a483b379f976'
+ with open(os.path.join(self.basepath, fname)) as fp:
+ data = ruamel.yaml.safe_load(fp)
+ entry = lesana.Entry(self.collection, data=data, fname=fname)
+ self.assertEqual(entry.uid, uid)
+
class testComplexCollection(unittest.TestCase):
@classmethod