summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-18 18:30:28 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-18 18:30:28 -0300
commite3871a45b584e8dcb633ba314e1ab1b8593c636b (patch)
treebd31d6c59ec2f68a549f456bb0c6dfd238d7dee2
parentbe4779cd40af81136aa85e65bbe8b3e4432f2783 (diff)
Adding update_draft to mailboxes
-rw-r--r--service/pixelated/adapter/pixelated_mail.py7
-rw-r--r--service/pixelated/adapter/pixelated_mailboxes.py8
-rw-r--r--service/test/adapter/pixelated_mailboxes_test.py18
3 files changed, 26 insertions, 7 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index af82eb7f..5c3025b6 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -26,11 +26,13 @@ from email.MIMEText import MIMEText
class PixelatedMail:
def __init__(self):
- self.body = ''
+ self.body = None
self.headers = {}
self.status = []
self.security_casing = {}
self.tags = []
+ self.mailbox_name = None
+ self.uid = None
@staticmethod
def from_leap_mail(leap_mail, tag_service=TagService.get_instance()):
@@ -149,9 +151,6 @@ class PixelatedMail:
mime_multipart['From'] = PixelatedMail.from_email_address
return mime_multipart.as_string()
- def set_ident(self, mailbox_name, uid):
- self.ident = gen_pixelated_uid(mailbox_name, uid)
-
@staticmethod
def from_dict(mail_dict):
return from_dict(mail_dict)
diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py
index e8b302a7..e8d73b24 100644
--- a/service/pixelated/adapter/pixelated_mailboxes.py
+++ b/service/pixelated/adapter/pixelated_mailboxes.py
@@ -33,9 +33,15 @@ class PixelatedMailBoxes():
def add_draft(self, mail):
drafts = self.drafts()
draft_id = drafts.add(mail)
- mail.set_ident(drafts.mailbox_name, draft_id)
+ mail.mailbox_name = drafts.mailbox_name
+ mail.uid = draft_id
return mail
+ def update_draft(self, mail):
+ new_mail = self.add_draft(mail)
+ self.drafts().remove(mail)
+ return new_mail
+
def move_to_trash(self, mail):
mail.remove_all_tags()
origin_mailbox = mail.mailbox_name
diff --git a/service/test/adapter/pixelated_mailboxes_test.py b/service/test/adapter/pixelated_mailboxes_test.py
index 15606b51..b112905c 100644
--- a/service/test/adapter/pixelated_mailboxes_test.py
+++ b/service/test/adapter/pixelated_mailboxes_test.py
@@ -14,6 +14,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/>.
import unittest
+from pixelated.adapter.pixelated_mail import PixelatedMail
from pixelated.adapter.pixelated_mailbox import PixelatedMailbox
from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes
@@ -42,10 +43,23 @@ class PixelatedMailboxesTest(unittest.TestCase):
self.assertEqual("mail", mails[0])
def test_add_draft(self):
- mail = mock()
+ mail = PixelatedMail()
when(self.drafts_mailbox).add(mail).thenReturn(1)
self.mailboxes.add_draft(mail)
verify(self.drafts_mailbox).add(mail)
- verify(mail).set_ident('drafts', 1)
+ 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)
+
+ self.mailboxes.update_draft(mail)
+
+ inorder.verify(self.drafts_mailbox).add(mail)
+ inorder.verify(self.drafts_mailbox).remove(mail)
+
+ self.assertEqual('drafts', mail.mailbox_name)
+ self.assertEqual(1, mail.uid)