summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-09-11 11:19:20 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2019-09-11 11:19:20 +0200
commitc0a33617f9d304933322496c1b7b36f0d3882c1b (patch)
tree0353e2e4bd6144390fcb5ee202484df52da131fa /tests
parent04c28f10c56b36e0754b375e3e1209d472bb9584 (diff)
Move some templating code to the collection instead of commands.
Diffstat (limited to 'tests')
-rw-r--r--tests/data/simple/templates/collection_template.txt4
-rw-r--r--tests/data/simple/templates/trivial_template.txt1
-rw-r--r--tests/test_collection.py17
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/data/simple/templates/collection_template.txt b/tests/data/simple/templates/collection_template.txt
new file mode 100644
index 0000000..8873e1e
--- /dev/null
+++ b/tests/data/simple/templates/collection_template.txt
@@ -0,0 +1,4 @@
+{% for entry in entries %}
+{{ entry.short_id }}: {{ entry.data.name }}
+ {{ entry.data.description }}
+{% endfor %}
diff --git a/tests/data/simple/templates/trivial_template.txt b/tests/data/simple/templates/trivial_template.txt
new file mode 100644
index 0000000..df31f0c
--- /dev/null
+++ b/tests/data/simple/templates/trivial_template.txt
@@ -0,0 +1 @@
+{{ entry }}
diff --git a/tests/test_collection.py b/tests/test_collection.py
index d1d6455..09ff96c 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -145,6 +145,14 @@ class testCollection(unittest.TestCase):
entry = self.collection.entry_from_uid('this is not an uid')
self.assertIsNone(entry)
+ def test_render_collection(self):
+ self.collection = lesana.Collection('tests/data/simple')
+ template = self.collection.get_template(
+ 'tests/data/simple/templates/collection_template.txt'
+ )
+ res = template.render(entries=self.collection.get_all_documents())
+ self.assertIn('11189ee4: Another item', res)
+
class testEntries(unittest.TestCase):
def setUp(self):
@@ -243,6 +251,15 @@ class testEntries(unittest.TestCase):
self.collection.settings['entry_label'] = '{{ uid }}: {{ name }}'
self.assertEqual(str(entry), uid + ': Another item')
+ def test_render_entry(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)
+ uid = entry.uid
+ res = entry.render('tests/data/simple/templates/trivial_template.txt')
+ self.assertIn(uid, res)
+
class testComplexCollection(unittest.TestCase):
@classmethod