summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-08-05 14:34:49 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:32 +0200
commit3dfec58b96876514a41abf916f280694f30bb8cd (patch)
treefca92479a77713028ad1b6707879f25306b8798f
parentd2e5af008d012c24716c6515490ea4639b8dd9a1 (diff)
Assert return value for add_mail and that a LeapMail instance is passed to search engine.
-rw-r--r--service/pixelated/adapter/mailstore/searchable_mailstore.py7
-rw-r--r--service/test/unit/adapter/mailstore/test_searchable_mailstore.py37
2 files changed, 35 insertions, 9 deletions
diff --git a/service/pixelated/adapter/mailstore/searchable_mailstore.py b/service/pixelated/adapter/mailstore/searchable_mailstore.py
index ad5fca33..1db34fd9 100644
--- a/service/pixelated/adapter/mailstore/searchable_mailstore.py
+++ b/service/pixelated/adapter/mailstore/searchable_mailstore.py
@@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+from twisted.internet import defer
from pixelated.adapter.mailstore.mailstore import MailStore
@@ -22,6 +23,8 @@ class SearchableMailStore(MailStore):
self._delegate = delegate
self._search_engine = search_engine
+ @defer.inlineCallbacks
def add_mail(self, mailbox_name, mail):
- self._delegate.add_mail(mailbox_name, mail)
- self._search_engine.index_mail(mail)
+ stored_mail = yield self._delegate.add_mail(mailbox_name, mail)
+ self._search_engine.index_mail(stored_mail)
+ defer.returnValue(stored_mail)
diff --git a/service/test/unit/adapter/mailstore/test_searchable_mailstore.py b/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
index 9ba61e32..f486a8e2 100644
--- a/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
@@ -15,24 +15,46 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from email.parser import Parser
import os
-from mockito import verify, mock
+from mockito import verify, mock, when
import pkg_resources
+from twisted.internet import defer
from twisted.trial.unittest import TestCase
+from pixelated.adapter.mailstore.leap_mailstore import LeapMail
from pixelated.adapter.mailstore.searchable_mailstore import SearchableMailStore
from pixelated.adapter.search import SearchEngine
+ANY_MAILBOX = 'INBOX'
+
+
class TestLeapMail(TestCase):
+
+ def setUp(self):
+ super(TestLeapMail, self).setUp()
+ self.search_index = mock(mocked_obj=SearchEngine)
+ self.delegate_mail_store = mock()
+ self.store = SearchableMailStore(self.delegate_mail_store, self.search_index)
+
+ @defer.inlineCallbacks
def test_add_mail_delegates_to_mail_store_and_updates_index(self):
mail = self._load_mail_from_file('mbox00000000')
- search_index = mock(mocked_obj=SearchEngine)
- delegate_mail_store = mock()
- store = SearchableMailStore(delegate_mail_store, search_index)
+ leap_mail = LeapMail('id', ANY_MAILBOX)
+ when(self.delegate_mail_store).add_mail(ANY_MAILBOX, mail).thenReturn(defer.succeed(leap_mail))
- store.add_mail('INBOX', mail)
+ yield self.store.add_mail(ANY_MAILBOX, mail)
- verify(search_index).index_mail(mail)
- verify(delegate_mail_store).add_mail('INBOX', mail)
+ verify(self.delegate_mail_store).add_mail(ANY_MAILBOX, mail)
+ verify(self.search_index).index_mail(leap_mail)
+
+ @defer.inlineCallbacks
+ def test_add_mail_returns_stored_mail(self):
+ mail = self._load_mail_from_file('mbox00000000')
+ leap_mail = LeapMail('id', ANY_MAILBOX)
+ when(self.delegate_mail_store).add_mail(ANY_MAILBOX, mail).thenReturn(defer.succeed(leap_mail))
+
+ result = yield self.store.add_mail(ANY_MAILBOX, mail)
+
+ self.assertEqual(leap_mail, result)
def _load_mail_from_file(self, mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
@@ -40,3 +62,4 @@ class TestLeapMail(TestCase):
with open(mail_file) as f:
mail = Parser().parse(f)
return mail
+