summaryrefslogtreecommitdiff
path: root/tests/commands
diff options
context:
space:
mode:
authorThomas Nixon <tom@tomn.co.uk>2018-02-19 23:14:45 +0000
committerThomas Nixon <tom@tomn.co.uk>2018-02-19 23:15:29 +0000
commit021735bdcba6763a5ed42cfce305e0ca33714db4 (patch)
tree4b395105eb7fbe7cd6322224bc06a2198b5984eb /tests/commands
parentdae920e245ab9a539907740f41fac4db3028abe3 (diff)
Move mock ui creation to function.
Diffstat (limited to 'tests/commands')
-rw-r--r--tests/commands/envelope_test.py14
-rw-r--r--tests/commands/global_test.py18
-rw-r--r--tests/commands/utils_tests.py20
3 files changed, 28 insertions, 24 deletions
diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py
index c1b928db..c48a0d91 100644
--- a/tests/commands/envelope_test.py
+++ b/tests/commands/envelope_test.py
@@ -35,6 +35,8 @@ from alot.errors import GPGProblem
from alot.settings.errors import NoMatchingAccount
from alot.settings.manager import SettingsManager
+from .. import utilities
+
# When using an assert from a mock a TestCase method might not use self. That's
# okay.
# pylint: disable=no-self-use
@@ -64,7 +66,7 @@ class TestAttachCommand(unittest.TestCase):
def test_single_path(self):
"""A test for an existing single path."""
- ui = mock.Mock()
+ ui = utilities.make_ui()
with temporary_directory() as d:
testfile = os.path.join(d, 'foo')
@@ -77,7 +79,7 @@ class TestAttachCommand(unittest.TestCase):
def test_user(self):
"""A test for an existing single path prefaced with ~/."""
- ui = mock.Mock()
+ ui = utilities.make_ui()
with temporary_directory() as d:
# This mock replaces expanduser to replace "~/" with a path to the
@@ -96,7 +98,7 @@ class TestAttachCommand(unittest.TestCase):
def test_glob(self):
"""A test using a glob."""
- ui = mock.Mock()
+ ui = utilities.make_ui()
with temporary_directory() as d:
testfile1 = os.path.join(d, 'foo')
@@ -112,7 +114,7 @@ class TestAttachCommand(unittest.TestCase):
def test_no_match(self):
"""A test for a file that doesn't exist."""
- ui = mock.Mock()
+ ui = utilities.make_ui()
with temporary_directory() as d:
cmd = envelope.AttachCommand(path=os.path.join(d, 'doesnt-exist'))
@@ -133,7 +135,7 @@ class TestTagCommands(unittest.TestCase):
:type expected: list(str)
"""
env = Envelope(tags=['one', 'two', 'three'])
- ui = mock.Mock()
+ ui = utilities.make_ui()
ui.current_buffer = mock.Mock()
ui.current_buffer.envelope = env
cmd = envelope.TagCommand(tags=tagstring, action=action)
@@ -177,7 +179,7 @@ class TestSignCommand(unittest.TestCase):
envelope['From'] = 'foo <foo@example.com>'
envelope.sign = mock.sentinel.default
envelope.sign_key = mock.sentinel.default
- ui = mock.Mock(current_buffer=mock.Mock(envelope=envelope))
+ ui = utilities.make_ui(current_buffer=mock.Mock(envelope=envelope))
return envelope, ui
@mock.patch('alot.commands.envelope.crypto.get_key',
diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py
index 96cba2d7..e3d91f8a 100644
--- a/tests/commands/global_test.py
+++ b/tests/commands/global_test.py
@@ -26,6 +26,8 @@ import mock
from alot.commands import globals as g_commands
+from .. import utilities
+
class Stop(Exception):
"""exception for stopping testing of giant unmanagable functions."""
@@ -150,32 +152,32 @@ class TestComposeCommand(unittest.TestCase):
class TestExternalCommand(unittest.TestCase):
def test_no_spawn_no_stdin_success(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'true', refocus=False)
cmd.apply(ui)
ui.notify.assert_not_called()
def test_no_spawn_stdin_success(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u"awk '{ exit $0 }'", stdin=u'0',
refocus=False)
cmd.apply(ui)
ui.notify.assert_not_called()
def test_no_spawn_no_stdin_attached(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'test -t 0', refocus=False)
cmd.apply(ui)
ui.notify.assert_not_called()
def test_no_spawn_stdin_attached(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u"test -t 0", stdin=u'0', refocus=False)
cmd.apply(ui)
ui.notify.assert_called_once_with('', priority='error')
def test_no_spawn_failure(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'false', refocus=False)
cmd.apply(ui)
ui.notify.assert_called_once_with('', priority='error')
@@ -183,7 +185,7 @@ class TestExternalCommand(unittest.TestCase):
@mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
def test_spawn_no_stdin_success(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'true', refocus=False, spawn=True)
cmd.apply(ui)
ui.notify.assert_not_called()
@@ -191,7 +193,7 @@ class TestExternalCommand(unittest.TestCase):
@mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
def test_spawn_stdin_success(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(
u"awk '{ exit $0 }'",
stdin=u'0', refocus=False, spawn=True)
@@ -201,7 +203,7 @@ class TestExternalCommand(unittest.TestCase):
@mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
def test_spawn_failure(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'false', refocus=False, spawn=True)
cmd.apply(ui)
ui.notify.assert_called_once_with('', priority='error')
diff --git a/tests/commands/utils_tests.py b/tests/commands/utils_tests.py
index 5339bbf8..5320aadd 100644
--- a/tests/commands/utils_tests.py
+++ b/tests/commands/utils_tests.py
@@ -78,7 +78,7 @@ class TestGetKeys(unittest.TestCase):
"""Test that getting keys works when all keys are present."""
expected = crypto.get_key(FPR, validate=True, encrypt=True,
signed_only=False)
- ui = mock.Mock()
+ ui = utilities.make_ui()
ids = [FPR]
actual = yield utils._get_keys(ui, ids)
self.assertIn(FPR, actual)
@@ -89,7 +89,7 @@ class TestGetKeys(unittest.TestCase):
"""Test that getting keys works when some keys are missing."""
expected = crypto.get_key(FPR, validate=True, encrypt=True,
signed_only=False)
- ui = mock.Mock()
+ ui = utilities.make_ui()
ids = [FPR, "6F6B15509CF8E59E6E469F327F438280EF8D349F"]
actual = yield utils._get_keys(ui, ids)
self.assertIn(FPR, actual)
@@ -98,7 +98,7 @@ class TestGetKeys(unittest.TestCase):
@inlineCallbacks
def test_get_keys_signed_only(self):
"""Test gettings keys when signed only is required."""
- ui = mock.Mock()
+ ui = utilities.make_ui()
ids = [FPR]
actual = yield utils._get_keys(ui, ids, signed_only=True)
self.assertEqual(actual, {})
@@ -107,7 +107,7 @@ class TestGetKeys(unittest.TestCase):
def test_get_keys_ambiguous(self):
"""Test gettings keys when when the key is ambiguous."""
key = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False)
- ui = mock.Mock()
+ ui = utilities.make_ui()
# Creat a ui.choice object that can satisfy twisted, but can also be
# queried for calls as a mock
@@ -136,7 +136,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_get_keys_from_to(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['To'] = 'ambig@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
@@ -147,7 +147,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_get_keys_from_cc(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['Cc'] = 'ambig@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
@@ -158,7 +158,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_get_partial_keys(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['Cc'] = 'foo@example.com, test@example.com'
yield utils.set_encrypt(ui, envelope)
@@ -169,7 +169,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_get_no_keys(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['To'] = 'foo@example.com'
yield utils.set_encrypt(ui, envelope)
@@ -178,7 +178,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_encrypt_to_self_true(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['From'] = 'test@example.com'
envelope['To'] = 'ambig@example.com'
@@ -193,7 +193,7 @@ class TestSetEncrypt(unittest.TestCase):
@inlineCallbacks
def test_encrypt_to_self_false(self):
- ui = mock.Mock()
+ ui = utilities.make_ui()
envelope = Envelope()
envelope['From'] = 'test@example.com'
envelope['To'] = 'ambig@example.com'