diff options
author | Lucas Hoffmann <l-m-h@web.de> | 2017-08-16 08:57:07 +0200 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2017-08-16 09:10:18 +0100 |
commit | f33d3b3ff29e7ec555f8a791e4be3d66cf7ece42 (patch) | |
tree | 99b24e00554285d7d366515001e0062dacf2266e /tests/commands | |
parent | c53fc90c1c71f0f9b0938fdcfc95c67c459b1239 (diff) |
Add tests for SendCommand
These test only check if get_account_by_address is called correctly.
All other parts of `apply()` are left out.
Diffstat (limited to 'tests/commands')
-rw-r--r-- | tests/commands/envelope_test.py | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py index 956e01e2..c59f90ee 100644 --- a/tests/commands/envelope_test.py +++ b/tests/commands/envelope_test.py @@ -17,12 +17,13 @@ """Tests for the alot.commands.envelope module.""" from __future__ import absolute_import -import os import contextlib +import email +import os import shutil import tempfile -import unittest import textwrap +import unittest import mock @@ -355,3 +356,41 @@ class TestSignCommand(unittest.TestCase): self.assertTrue(env.sign) self.assertIs(env.sign_key, mock.sentinel.gpg_key) + + +class TestSendCommand(unittest.TestCase): + + """Tests for the SendCommand class.""" + + mail = textwrap.dedent("""\ + From: foo@example.com + To: bar@example.com + Subject: FooBar + + Foo Bar Baz + """) + + def test_get_account_by_address_with_str(self): + cmd = envelope.SendCommand(mail=self.mail) + account = mock.Mock() + with mock.patch( + 'alot.commands.envelope.settings.get_account_by_address', + mock.Mock(return_value=account)) as get_account_by_address: + cmd.apply(mock.Mock()) + get_account_by_address.assert_called_once_with('foo@example.com', + return_default=True) + # check that the apply did run through till the end. + account.send_mail.assert_called_once_with(self.mail) + + def test_get_account_by_address_with_email_message(self): + mail = email.message_from_string(self.mail) + cmd = envelope.SendCommand(mail=mail) + account = mock.Mock() + with mock.patch( + 'alot.commands.envelope.settings.get_account_by_address', + mock.Mock(return_value=account)) as get_account_by_address: + cmd.apply(mock.Mock()) + get_account_by_address.assert_called_once_with('foo@example.com', + return_default=True) + # check that the apply did run through till the end. + account.send_mail.assert_called_once_with(mail) |