summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/simple/templates/from_self.yaml3
-rw-r--r--tests/test_commands.py119
2 files changed, 120 insertions, 2 deletions
diff --git a/tests/data/simple/templates/from_self.yaml b/tests/data/simple/templates/from_self.yaml
new file mode 100644
index 0000000..f4c535f
--- /dev/null
+++ b/tests/data/simple/templates/from_self.yaml
@@ -0,0 +1,3 @@
+name: {{ name | to_yaml }}
+description: {{ description | to_yaml }}
+position: {{ position | to_yaml }}
diff --git a/tests/test_commands.py b/tests/test_commands.py
index c948d69..92b603f 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1,9 +1,11 @@
import contextlib
import io
+import os
import tempfile
import unittest
from lesana import command
+from . import utils
class Args:
@@ -22,7 +24,12 @@ class Args:
class testCommands(unittest.TestCase):
def setUp(self):
- self.collection_dir = tempfile.TemporaryDirectory()
+ self.tmpdir = tempfile.TemporaryDirectory()
+ utils.copytree(
+ 'tests/data/simple',
+ self.tmpdir.name,
+ dirs_exist_ok=True,
+ )
def tearDown(self):
pass
@@ -44,13 +51,121 @@ class testCommands(unittest.TestCase):
def test_init(self):
args = {
- 'collection': self.collection_dir.name,
+ 'collection': self.tmpdir.name,
'git': True,
}
streams = self._run_command(command.Init(), args)
self.assertEqual(streams['stdout'].getvalue(), '')
self.assertEqual(streams['stderr'].getvalue(), '')
+ def test_new(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ }
+ streams = self._run_command(command.New(), args)
+ self.assertEqual(len(streams['stdout'].getvalue()), 33)
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_edit(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'eid': '11189ee4',
+ }
+ streams = self._run_command(command.Edit(), args)
+ self.assertTrue(args['eid'] in streams['stdout'].getvalue())
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_show(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'eid': '11189ee4',
+ 'template': False,
+ }
+ streams = self._run_command(command.Show(), args)
+ self.assertTrue(
+ 'name: Another item' in streams['stdout'].getvalue()
+ )
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_index(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'files': None,
+ 'reset': True,
+ }
+ streams = self._run_command(command.Index(), args)
+ self.assertEqual(
+ streams['stdout'].getvalue(),
+ 'Found and indexed 3 entries\n',
+ )
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_search(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'template': False,
+ 'query': 'Another',
+ 'offset': None,
+ 'pagesize': None,
+ 'sort': None,
+ 'all': False,
+ }
+ streams = self._run_command(command.Search(), args)
+ self.assertTrue(
+ '11189ee4' in streams['stdout'].getvalue()
+ )
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_export(self):
+ dest_tmpdir = tempfile.TemporaryDirectory()
+ utils.copytree(
+ 'tests/data/simple',
+ dest_tmpdir.name,
+ dirs_exist_ok=True,
+ )
+ # TODO: make finding the templates less prone to breaking and
+ # then remove the cwd change from here
+ old_cwd = os.getcwd()
+ os.chdir(self.tmpdir.name)
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'template': 'templates/from_self.yaml',
+ 'query': 'Another',
+ 'destination': dest_tmpdir.name,
+ }
+ streams = self._run_command(command.Export(), args)
+ os.chdir(old_cwd)
+ self.assertEqual(streams['stdout'].getvalue(), '')
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_remove(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'entries': '11189ee4',
+ }
+ streams = self._run_command(command.Remove(), args)
+ self.assertEqual(streams['stdout'].getvalue(), '')
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
+ def test_update(self):
+ args = {
+ 'collection': self.tmpdir.name,
+ 'git': True,
+ 'query': 'Another',
+ 'field': 'position',
+ 'value': 'here',
+ }
+ streams = self._run_command(command.Update(), args)
+ self.assertEqual(streams['stdout'].getvalue(), '')
+ self.assertEqual(streams['stderr'].getvalue(), '')
+
if __name__ == '__main__':
unittest.main()