From eb59c286605147442ae54005dc59812f4b086662 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Fri, 19 Sep 2014 11:49:23 -0300 Subject: Now it is possible to add_msg with either raw format (for when changing leap messages to different mailboxes) or smtp_format (when adding a brand new draft) --- service/pixelated/adapter/pixelated_mailbox.py | 9 +++++---- service/pixelated/adapter/pixelated_mailboxes.py | 2 +- service/test/adapter/pixelated_mailbox_test.py | 21 ++++++++++++++++----- service/test/adapter/pixelated_mailboxes_test.py | 8 ++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index a6dc4116..d6bd924b 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -62,14 +62,15 @@ class PixelatedMailbox: if message.ident == mail_id: return message - def add(self, mail): - leap_id = self._do_add_async(mail) + def add(self, mail, use_smtp_format=False): + leap_id = self._do_add_async(mail, use_smtp_format) new_id = gen_pixelated_uid(self.leap_mailbox.mbox, leap_id) return new_id @wait_for(timeout=3.0) - def _do_add_async(self, mail): - return self.leap_mailbox.messages.add_msg(mail.raw_message()) + def _do_add_async(self, mail, use_smtp_format): + raw = mail.to_smtp_format() if use_smtp_format else mail.raw_message() + return self.leap_mailbox.messages.add_msg(raw) def remove(self, mail): mail.leap_mail.setFlags((Status.PixelatedStatus.DELETED,), 1) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index e8d73b24..850db9d9 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -32,7 +32,7 @@ class PixelatedMailBoxes(): def add_draft(self, mail): drafts = self.drafts() - draft_id = drafts.add(mail) + draft_id = drafts.add(mail, use_smtp_format=True) mail.mailbox_name = drafts.mailbox_name mail.uid = draft_id return mail diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py index ac9d3f34..8bff7e68 100644 --- a/service/test/adapter/pixelated_mailbox_test.py +++ b/service/test/adapter/pixelated_mailbox_test.py @@ -21,7 +21,7 @@ from pixelated.adapter.pixelated_mailbox import PixelatedMailbox from mockito import * -class TestPixelatedMailbox(unittest.TestCase): +class PixelatedMailboxTest(unittest.TestCase): def setUp(self): mail_one = test_helper.leap_mail(uid=0, mbox='SENT') leap_mailbox = test_helper.leap_mailbox(messages=[mail_one], mailbox_name='SENT') @@ -39,16 +39,27 @@ class TestPixelatedMailbox(unittest.TestCase): mailbox = PixelatedMailbox(test_helper.leap_mailbox(messages=[recent_leap_mail], mailbox_name='SPAM')) self.assertNotIn('spam', mailbox.mails()[0].tags) - def test_add_message_to_mailbox(self): + def test_add_message_to_mailbox_with_raw_message(self): mail = PixelatedMail.from_dict(test_helper.mail_dict()) - mail.raw_message = lambda: 'the mail in smtp format' + mail.raw_message = lambda: 'raw mail' + + leap_mailbox_messages = mock() + self.mailbox.leap_mailbox.messages = leap_mailbox_messages + + self.mailbox._do_add_async.wrapped_function(self.mailbox, mail, use_smtp_format=False) + + verify(leap_mailbox_messages).add_msg('raw mail') + + def test_add_message_to_mailbox_with_smtp_format(self): + mail = PixelatedMail.from_dict(test_helper.mail_dict()) + mail.to_smtp_format = lambda: 'smtp format mail' leap_mailbox_messages = mock() self.mailbox.leap_mailbox.messages = leap_mailbox_messages - self.mailbox._do_add_async.wrapped_function(self.mailbox, mail) + self.mailbox._do_add_async.wrapped_function(self.mailbox, mail, use_smtp_format=True) - verify(leap_mailbox_messages).add_msg('the mail in smtp format') + verify(leap_mailbox_messages).add_msg('smtp format mail') def test_remove_message_from_mailbox(self): mail = PixelatedMail.from_dict(test_helper.mail_dict()) diff --git a/service/test/adapter/pixelated_mailboxes_test.py b/service/test/adapter/pixelated_mailboxes_test.py index b112905c..e188354e 100644 --- a/service/test/adapter/pixelated_mailboxes_test.py +++ b/service/test/adapter/pixelated_mailboxes_test.py @@ -44,21 +44,21 @@ class PixelatedMailboxesTest(unittest.TestCase): def test_add_draft(self): mail = PixelatedMail() - when(self.drafts_mailbox).add(mail).thenReturn(1) + when(self.drafts_mailbox).add(mail, use_smtp_format=True).thenReturn(1) self.mailboxes.add_draft(mail) - verify(self.drafts_mailbox).add(mail) + verify(self.drafts_mailbox).add(mail, use_smtp_format=True) self.assertEqual('drafts', mail.mailbox_name) self.assertEqual(1, mail.uid) def test_update_draft(self): mail = PixelatedMail() - when(self.drafts_mailbox).add(mail).thenReturn(1) + when(self.drafts_mailbox).add(mail, use_smtp_format=True).thenReturn(1) self.mailboxes.update_draft(mail) - inorder.verify(self.drafts_mailbox).add(mail) + inorder.verify(self.drafts_mailbox).add(mail, use_smtp_format=True) inorder.verify(self.drafts_mailbox).remove(mail) self.assertEqual('drafts', mail.mailbox_name) -- cgit v1.2.3