summaryrefslogtreecommitdiff
path: root/tests/test_commands.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-24 20:53:23 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-03-24 20:53:23 +0100
commit43266069fff83e947e6b5fdb48a2dcfd7e77db20 (patch)
treed85106f29bac669457ddaa139ed003c0c77d2ee8 /tests/test_commands.py
parent1014eccda2a99e68aa64fdc11920470a68bab207 (diff)
Run basic tests on all command line commands
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r--tests/test_commands.py119
1 files changed, 117 insertions, 2 deletions
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()