diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-09-30 10:33:13 -0300 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-09-30 10:33:16 -0300 |
commit | c431f219f52f004aebf316283260cfffbddf17c8 (patch) | |
tree | 72e1a3a4c352744550babebfa578151ec19f589b /service | |
parent | e34fc64a13eae3eef4333bc6f4e993fa1891eb81 (diff) |
Fixing move to trash
Diffstat (limited to 'service')
-rw-r--r-- | service/integration/__init__.py | 4 | ||||
-rw-r--r-- | service/integration/delete_mail_test.py | 40 | ||||
-rw-r--r-- | service/integration/tags_test.py | 1 | ||||
-rw-r--r-- | service/pixelated/adapter/mail_service.py | 3 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 6 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 8 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailboxes.py | 7 | ||||
-rw-r--r-- | service/pixelated/adapter/soledad_querier.py | 1 | ||||
-rw-r--r-- | service/test/adapter/mail_service_test.py | 5 | ||||
-rw-r--r-- | service/test/adapter/pixelated_mailbox_test.py | 2 |
10 files changed, 64 insertions, 13 deletions
diff --git a/service/integration/__init__.py b/service/integration/__init__.py index c4e1d0b4..a9991f6f 100644 --- a/service/integration/__init__.py +++ b/service/integration/__init__.py @@ -102,7 +102,6 @@ class MailBuilder: return InputMail.from_dict(self.mail) - class SoledadTestBase: def teardown_soledad(self): @@ -142,6 +141,9 @@ class SoledadTestBase: def post_tags(self, mail_ident, tags_json): return json.loads(self.app.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data) + def delete_mail(self, mail_ident): + self.app.delete('/mail/' + mail_ident) + class ResponseMail: diff --git a/service/integration/delete_mail_test.py b/service/integration/delete_mail_test.py new file mode 100644 index 00000000..e7e08c31 --- /dev/null +++ b/service/integration/delete_mail_test.py @@ -0,0 +1,40 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# 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 integration import MailBuilder, SoledadTestBase + + +class DeleteMailTest(unittest.TestCase, SoledadTestBase): + + def setUp(self): + self.setup_soledad() + + def tearDown(self): + self.teardown_soledad() + + def test_move_mail_to_trash_when_deleting(self): + mail = MailBuilder().with_subject('Mail with tags').build_input_mail() + self.pixelated_mailboxes.inbox().add(mail) + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(1, len(inbox_mails)) + + self.delete_mail(mail.ident) + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(0, len(inbox_mails)) + trash_mails = self.get_mails_by_tag('trash') + self.assertEquals(1, len(trash_mails)) diff --git a/service/integration/tags_test.py b/service/integration/tags_test.py index 8971fac7..a0743b6a 100644 --- a/service/integration/tags_test.py +++ b/service/integration/tags_test.py @@ -32,6 +32,7 @@ class TagsTest(unittest.TestCase, SoledadTestBase): def test_add_tag_to_an_inbox_mail_and_query(self): mail = MailBuilder().with_subject('Mail with tags').build_input_mail() self.pixelated_mailboxes.inbox().add(mail) + self.post_tags(mail.ident, self._tags_json(['INBOX', 'IMPORTANT'])) mails = self.get_mails_by_tag('inbox') diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index 0d3e00f7..c216e7ae 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -74,8 +74,7 @@ class MailService: raise NotImplementedError() def delete_mail(self, mail_id): - _mail = self.mailboxes.mail(mail_id) - return self.mailboxes.move_to_trash(_mail) + return self.mailboxes.move_to_trash(mail_id) def save_draft(self, draft): raise NotImplementedError() diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index b7323af9..3e0f1ee0 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -215,6 +215,12 @@ class PixelatedMail: def save(self): return self.querier.save_mail(self) + def set_mailbox(self, mailbox_name): + self.fdoc.content['mbox'] = mailbox_name + + def set_recent(self): + self.fdoc.content['flags'].append("\\Recent") + def set_from(self, _from): self.headers['From'] = [_from] diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 85d965d1..62ea57e6 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -54,8 +54,16 @@ class PixelatedMailbox: def add(self, mail): self.querier.create_mail(mail, self.mailbox_name) + def add_existing(self, mail_ident): + mail = self.querier.mail(mail_ident) + mail.remove_all_tags() + mail.set_mailbox(self.mailbox_name) + mail.save() + self.add_mailbox_tag_if_not_there(mail) + def remove(self, ident): mail = self.querier.mail(ident) + mail.remove_all_tags() self.querier.remove_mail(mail) @classmethod diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index ff1aa421..aa39a5c4 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -60,11 +60,8 @@ class PixelatedMailBoxes(): self.drafts().remove(ident) return new_mail - def move_to_trash(self, mail): - origin_mailbox = mail.mailbox_name - - new_mail_id = self.trash().add(mail) - self._create_or_get(origin_mailbox).remove(mail) + def move_to_trash(self, mail_id): + new_mail_id = self.trash().add_existing(mail_id) return new_mail_id def mail(self, mail_id): diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py index 7ce7f26d..61bada1a 100644 --- a/service/pixelated/adapter/soledad_querier.py +++ b/service/pixelated/adapter/soledad_querier.py @@ -57,6 +57,7 @@ class SoledadQuerier: # XXX update only what has to be updated self.soledad.put_doc(mail.fdoc) self.soledad.put_doc(mail.hdoc) + self._update_index([mail.fdoc, mail.hdoc]) def create_mail(self, mail, mailbox_name): uid = self._next_uid_for_mailbox(mailbox_name) diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py index 7912241d..549ab05c 100644 --- a/service/test/adapter/mail_service_test.py +++ b/service/test/adapter/mail_service_test.py @@ -55,9 +55,6 @@ class TestMailService(unittest.TestCase): verify(self.mailboxes).add_draft(mail) def test_delete_mail(self): - mail = mock() - when(self.mailboxes).mail(any()).thenReturn(mail) - self.mail_service.delete_mail(1) - verify(self.mailboxes).move_to_trash(mail) + verify(self.mailboxes).move_to_trash(1) diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py index 87f7b4f3..5b1cfae5 100644 --- a/service/test/adapter/pixelated_mailbox_test.py +++ b/service/test/adapter/pixelated_mailbox_test.py @@ -40,7 +40,7 @@ class PixelatedMailboxTest(unittest.TestCase): self.assertNotIn('spam', self.mailbox.mails()[0].tags) def test_remove_message_from_mailbox(self): - mail = PixelatedMail() + mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier) when(self.querier).mail(1).thenReturn(mail) self.mailbox.remove(1) |