summaryrefslogtreecommitdiff
path: root/tests/commands
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2017-07-05 10:27:07 +0200
committerLucas Hoffmann <l-m-h@web.de>2017-07-11 20:58:34 +0200
commit1fd8fba0459e44eb05a4eff73b03856d12b79006 (patch)
tree1546374f7e2a131eb690151c8e25989dc3b15955 /tests/commands
parent929af13fe7d931ced28c84229d115183659ce977 (diff)
Add tests for new commands
The test file is also renamed.
Diffstat (limited to 'tests/commands')
-rw-r--r--tests/commands/envelope_test.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py
index cd6684a8..67caef02 100644
--- a/tests/commands/envelope_test.py
+++ b/tests/commands/envelope_test.py
@@ -26,6 +26,7 @@ import unittest
import mock
from alot.commands import envelope
+from alot.db.envelope import Envelope
# When using an assert from a mock a TestCase method might not use self. That's
# okay.
@@ -110,3 +111,49 @@ class TestAttachCommand(unittest.TestCase):
cmd = envelope.AttachCommand(path=os.path.join(d, 'doesnt-exist'))
cmd.apply(ui)
ui.notify.assert_called()
+
+
+class TestTagCommands(unittest.TestCase):
+
+ def _test(self, tagstring, action, expected):
+ """Common steps for envelope.TagCommand tests
+
+ :param tagstring: the string to pass to the TagCommand
+ :type tagstring: str
+ :param action: the action to pass to the TagCommand
+ :type action: str
+ :param expected: the expected output to assert in the test
+ :type expected: list(str)
+ """
+ env = Envelope(tags=['one', 'two', 'three'])
+ ui = mock.Mock()
+ ui.current_buffer = mock.Mock()
+ ui.current_buffer.envelope = env
+ cmd = envelope.TagCommand(tags=tagstring, action=action)
+ cmd.apply(ui)
+ actual = env.tags
+ self.assertListEqual(sorted(actual), sorted(expected))
+
+ def test_add_new_tags(self):
+ self._test(u'four', 'add', ['one', 'two', 'three', 'four'])
+
+ def test_adding_existing_tags_has_no_effect(self):
+ self._test(u'one', 'add', ['one', 'two', 'three'])
+
+ def test_remove_existing_tags(self):
+ self._test(u'one', 'remove', ['two', 'three'])
+
+ def test_remove_non_existing_tags_has_no_effect(self):
+ self._test(u'four', 'remove', ['one', 'two', 'three'])
+
+ def test_set_tags(self):
+ self._test(u'a,b,c', 'set', ['a', 'b', 'c'])
+
+ def test_toggle_will_remove_existing_tags(self):
+ self._test(u'one', 'toggle', ['two', 'three'])
+
+ def test_toggle_will_add_new_tags(self):
+ self._test(u'four', 'toggle', ['one', 'two', 'three', 'four'])
+
+ def test_toggle_can_remove_and_add_in_one_run(self):
+ self._test(u'one,four', 'toggle', ['two', 'three', 'four'])