summaryrefslogtreecommitdiff
path: root/service/test/unit/adapter/mailstore
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-08-05 17:14:58 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:32 +0200
commitcc84a89c5c4b3d48b0ef8767c40fa34ef542bccf (patch)
treefb7fe5ef283bb60f1bbe4df4e36a78a87216fc71 /service/test/unit/adapter/mailstore
parent3dfec58b96876514a41abf916f280694f30bb8cd (diff)
implemented add, delete and update of mails in searchable mail store.
Diffstat (limited to 'service/test/unit/adapter/mailstore')
-rw-r--r--service/test/unit/adapter/mailstore/test_searchable_mailstore.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/service/test/unit/adapter/mailstore/test_searchable_mailstore.py b/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
index f486a8e2..ef3190e2 100644
--- a/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_searchable_mailstore.py
@@ -19,6 +19,7 @@ from mockito import verify, mock, when
import pkg_resources
from twisted.internet import defer
from twisted.trial.unittest import TestCase
+from pixelated.adapter.mailstore import MailStore
from pixelated.adapter.mailstore.leap_mailstore import LeapMail
from pixelated.adapter.mailstore.searchable_mailstore import SearchableMailStore
from pixelated.adapter.search import SearchEngine
@@ -32,7 +33,7 @@ class TestLeapMail(TestCase):
def setUp(self):
super(TestLeapMail, self).setUp()
self.search_index = mock(mocked_obj=SearchEngine)
- self.delegate_mail_store = mock()
+ self.delegate_mail_store = mock(mocked_obj=MailStore)
self.store = SearchableMailStore(self.delegate_mail_store, self.search_index)
@defer.inlineCallbacks
@@ -56,10 +57,36 @@ class TestLeapMail(TestCase):
self.assertEqual(leap_mail, result)
+ @defer.inlineCallbacks
+ def test_delete_mail_delegates_to_mail_store_and_updates_index(self):
+ when(self.delegate_mail_store).delete_mail('mail id').thenReturn(defer.succeed(None))
+ when(self.search_index).remove_from_index('mail id').thenReturn(defer.succeed(None))
+
+ yield self.store.delete_mail('mail id')
+
+ verify(self.delegate_mail_store).delete_mail('mail id')
+ verify(self.search_index).remove_from_index('mail id')
+
+ @defer.inlineCallbacks
+ def test_update_mail_delegates_to_mail_store_and_updates_index(self):
+ leap_mail = LeapMail('id', ANY_MAILBOX)
+
+ yield self.store.update_mail(leap_mail)
+
+ verify(self.delegate_mail_store).update_mail(leap_mail)
+ verify(self.search_index).index_mail(leap_mail)
+
+ @defer.inlineCallbacks
+ def test_other_methods_are_delegated(self):
+ mail = LeapMail('mail id', ANY_MAILBOX)
+ when(self.delegate_mail_store).get_mail('mail id').thenReturn(defer.succeed(mail), defer.succeed(mail))
+ result = yield self.store.get_mail('mail id')
+
+ self.assertEqual(mail, result)
+
def _load_mail_from_file(self, mail_file):
mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset')
mail_file = os.path.join(mailset_dir, 'new', mail_file)
with open(mail_file) as f:
mail = Parser().parse(f)
return mail
-