aboutsummaryrefslogtreecommitdiff
path: root/tests/test_commands.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r--tests/test_commands.py214
1 files changed, 105 insertions, 109 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py
index d52908a..044caa9 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -4,6 +4,8 @@ import os
import tempfile
import unittest
+import hazwaz.unittest
+
from lesana import command
from . import utils
@@ -40,7 +42,7 @@ class CommandsMixin:
return stream
-class testCommandsSimple(unittest.TestCase, CommandsMixin):
+class testCommandsSimple(hazwaz.unittest.HazwazTestCase, CommandsMixin):
def setUp(self):
self.tmpdir = tempfile.TemporaryDirectory()
utils.copytree(
@@ -48,66 +50,72 @@ class testCommandsSimple(unittest.TestCase, CommandsMixin):
self.tmpdir.name,
dirs_exist_ok=True,
)
+ self.lesana = command.Lesana()
+ for cmd in self.lesana.commands:
+ cmd.editors = [("true", "true")]
# re-index the collection before running each test
args = {
'collection': self.tmpdir.name,
"files": None,
"reset": True,
}
- self._run_command(command.Index(), args)
+ self.run_with_argv(self.lesana, [
+ "lesana",
+ "index",
+ "-c", self.tmpdir.name,
+ "--reset"
+ ])
def tearDown(self):
self.tmpdir.cleanup()
def test_init(self):
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- }
- streams = self._run_command(command.Init(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "init",
+ "-c", self.tmpdir.name,
+ ])
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)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "new",
+ "-c", self.tmpdir.name,
+ ])
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())
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "edit",
+ "-c", self.tmpdir.name,
+ "11189ee4",
+ ])
+ self.assertTrue("11189ee4" 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)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "show",
+ "-c", self.tmpdir.name,
+ "11189ee4"
+ ])
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)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "index",
+ "-c", self.tmpdir.name,
+ "--reset",
+ ])
self.assertEqual(
streams['stdout'].getvalue(),
'Found and indexed 3 entries\n',
@@ -115,32 +123,24 @@ class testCommandsSimple(unittest.TestCase, CommandsMixin):
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,
- 'expand_query_template': False,
- 'all': False,
- }
- streams = self._run_command(command.Search(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "search",
+ "-c", self.tmpdir.name,
+ "Another"
+ ])
self.assertTrue(
'11189ee4' in streams['stdout'].getvalue()
)
self.assertEqual(streams['stderr'].getvalue(), '')
def test_get_values(self):
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- 'template': False,
- 'query': '*',
- 'field': 'position',
- }
- streams = self._run_command(command.GetValues(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "get-values",
+ "-c", self.tmpdir.name,
+ "--field", "position",
+ ])
self.assertIn('somewhere: 2', streams['stdout'].getvalue())
self.assertEqual(streams['stderr'].getvalue(), '')
@@ -155,51 +155,51 @@ class testCommandsSimple(unittest.TestCase, CommandsMixin):
# 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,
- }
- streams = self._run_command(command.Export(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "export",
+ "-c", self.tmpdir.name,
+ "--query", "Another",
+ dest_tmpdir,
+ "templates/from_self.yaml",
+ ])
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)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "rm",
+ "-c", self.tmpdir.name,
+ "11189ee4"
+ ])
self.assertEqual(streams['stdout'].getvalue(), '')
self.assertEqual(streams['stderr'].getvalue(), '')
# and check that the entry has been removed
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- 'eid': '11189ee4',
- 'template': False,
- }
- streams = self._run_command(command.Show(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "show",
+ "-c", self.tmpdir.name,
+ "11189ee4"
+ ])
self.assertEqual(streams['stderr'].getvalue(), '')
+ # TODO: check that the file is no longer there
def test_update(self):
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- 'query': 'Another',
- 'field': 'position',
- 'value': 'here',
- }
- streams = self._run_command(command.Update(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "update",
+ "-c", self.tmpdir.name,
+ "--field", "position",
+ "--value", "here",
+ "Another"
+ ])
self.assertEqual(streams['stdout'].getvalue(), '')
self.assertEqual(streams['stderr'].getvalue(), '')
-class testCommandsComplex(unittest.TestCase, CommandsMixin):
+class testCommandsComplex(hazwaz.unittest.HazwazTestCase, CommandsMixin):
def setUp(self):
self.tmpdir = tempfile.TemporaryDirectory()
utils.copytree(
@@ -207,42 +207,38 @@ class testCommandsComplex(unittest.TestCase, CommandsMixin):
self.tmpdir.name,
dirs_exist_ok=True,
)
+ self.lesana = command.Lesana()
+ for cmd in self.lesana.commands:
+ cmd.editors = [("true", "true")]
# re-index the collection before running each test
- args = {
- 'collection': self.tmpdir.name,
- "files": None,
- "reset": True,
- }
- self._run_command(command.Index(), args)
+ self.run_with_argv(self.lesana, [
+ "lesana",
+ "index",
+ "-c", self.tmpdir.name,
+ "--reset",
+ ])
def tearDown(self):
self.tmpdir.cleanup()
def test_get_values_from_list(self):
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- 'template': False,
- 'query': '*',
- 'field': 'tags',
- }
- streams = self._run_command(command.GetValues(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "get-values",
+ "-c", self.tmpdir.name,
+ "--field", "tags",
+ ])
self.assertIn('this: 1', streams['stdout'].getvalue())
self.assertEqual(streams['stderr'].getvalue(), '')
def test_search_template(self):
- args = {
- 'collection': self.tmpdir.name,
- 'git': True,
- 'template': False,
- 'query': '{{ nice }}',
- 'expand_query_template': True,
- 'offset': None,
- 'pagesize': None,
- 'sort': None,
- 'all': False,
- }
- streams = self._run_command(command.Search(), args)
+ streams = self.run_with_argv(self.lesana, [
+ "lesana",
+ "search",
+ "-c", self.tmpdir.name,
+ "--expand-query-template",
+ "{{ nice }}"
+ ])
self.assertIn('8e9fa1ed', streams['stdout'].getvalue())
self.assertIn('5084bc6e', streams['stdout'].getvalue())
self.assertEqual(streams['stderr'].getvalue(), '')