diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2017-08-16 18:48:13 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2017-08-16 21:00:16 +0100 |
commit | 249b907bca672ccac3777a411c3c492eefecfc61 (patch) | |
tree | 56bc961ed8ebe8258896633ecf0f3f605ee79766 /tests/commands | |
parent | f67d3ac2bca0dd0dda6d5998ed1131d5b383f995 (diff) |
use @inlineCallbacks in tests for asynchronous methods
This decorates test methods that internally call a `cmd.apply()`,
which represents asynchronous code that returns a `twisted.deferred`.
Diffstat (limited to 'tests/commands')
-rw-r--r-- | tests/commands/envelope_test.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py index c59f90ee..55cb61cb 100644 --- a/tests/commands/envelope_test.py +++ b/tests/commands/envelope_test.py @@ -23,7 +23,9 @@ import os import shutil import tempfile import textwrap -import unittest + +from twisted.trial import unittest +from twisted.internet.defer import inlineCallbacks import mock @@ -370,18 +372,20 @@ class TestSendCommand(unittest.TestCase): Foo Bar Baz """) + @inlineCallbacks 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()) + yield 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) + @inlineCallbacks def test_get_account_by_address_with_email_message(self): mail = email.message_from_string(self.mail) cmd = envelope.SendCommand(mail=mail) @@ -389,7 +393,7 @@ class TestSendCommand(unittest.TestCase): 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()) + yield 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. |