diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-08-10 19:23:18 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-08-11 17:00:34 +0200 |
commit | 9ed58715616f5c6341d32c9b0316933d3f2b4a3e (patch) | |
tree | b6196bfce3bff26228afb942f75083b5f8fd9bcd | |
parent | c00e4115f5bd205a0f65224dccd5e889e7cbf3b8 (diff) |
Added test to ensure mail with same content can be added.
- as long as each one has a unique message id
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 2 | ||||
-rw-r--r-- | service/test/integration/test_leap_mailstore.py | 13 | ||||
-rw-r--r-- | service/test/support/integration/util.py | 7 |
3 files changed, 20 insertions, 2 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index a641c35b..1bcab036 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -159,7 +159,7 @@ class LeapMailStore(MailStore): message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg) message.get_wrapper().set_mbox_uuid(mailbox.uuid) - yield message.get_wrapper().create(self.soledad) + yield SoledadMailAdaptor().create_msg(self.soledad, message) # add behavious from insert_mdoc_id from mail.py mail = yield self._leap_message_to_leap_mail(message.get_wrapper().mdoc.doc_id, message, include_body=True) # TODO test that asserts include_body diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py index 61bb3e42..48764194 100644 --- a/service/test/integration/test_leap_mailstore.py +++ b/service/test/integration/test_leap_mailstore.py @@ -70,6 +70,19 @@ class LeapMailStoreTest(SoledadTestBase): self.assertIsNone(deleted_msg) @defer.inlineCallbacks + def test_add_add_mail_twice(self): + yield self.adaptor.initialize_store(self.soledad) + mail = load_mail_from_file('mbox00000000', enforceUniqueMessageId=True) + mail2 = load_mail_from_file('mbox00000000', enforceUniqueMessageId=True) + yield self.mail_store.add_mailbox('INBOX') + + msg1 = yield self.mail_store.add_mail('INBOX', mail.as_string()) + msg2 = yield self.mail_store.add_mail('INBOX', mail2.as_string()) + + self.assertIsNotNone(msg1.ident) + self.assertIsNotNone(msg2.ident) + + @defer.inlineCallbacks def test_get_mailbox_mail_ids(self): mail = load_mail_from_file('mbox00000000') yield self.mail_store.add_mailbox('INBOX') diff --git a/service/test/support/integration/util.py b/service/test/support/integration/util.py index 2049105d..302edeaa 100644 --- a/service/test/support/integration/util.py +++ b/service/test/support/integration/util.py @@ -14,13 +14,18 @@ # 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 email.parser import Parser +from email.utils import make_msgid import os import pkg_resources -def load_mail_from_file(mail_file): +def load_mail_from_file(mail_file, enforceUniqueMessageId=False): 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) + + if enforceUniqueMessageId: + mail.add_header('Message-Id', make_msgid()) + return mail |