summaryrefslogtreecommitdiff
path: root/service/test/adapter
diff options
context:
space:
mode:
authorPatrick Maia <pmaia@thoughtworks.com>2014-09-17 02:02:28 -0300
committerPatrick Maia <pmaia@thoughtworks.com>2014-09-17 13:53:25 -0300
commit95b0e2e6f834804630bf9d091b156ac68ff20583 (patch)
tree9bff8ebac2134cf23fd2bcd92f1a9500d8dd5ebf /service/test/adapter
parentc272f64293bb0157eb7eb1ebba899935f8ed2c3a (diff)
74 - moves move_to_trash logic to PixelatedMailboxes and adds some tests
Diffstat (limited to 'service/test/adapter')
-rw-r--r--service/test/adapter/mail_service_test.py8
-rw-r--r--service/test/adapter/pixelated_mail_test.py33
-rw-r--r--service/test/adapter/pixelated_mailbox_test.py21
-rw-r--r--service/test/adapter/test_tag_service.py4
4 files changed, 52 insertions, 14 deletions
diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py
index 782e891a..517368e2 100644
--- a/service/test/adapter/mail_service_test.py
+++ b/service/test/adapter/mail_service_test.py
@@ -45,3 +45,11 @@ class TestMailService(unittest.TestCase):
self.mail_service.create_draft(mail)
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)
diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py
index 4292883c..3ba5e659 100644
--- a/service/test/adapter/pixelated_mail_test.py
+++ b/service/test/adapter/pixelated_mail_test.py
@@ -14,10 +14,15 @@
# 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
+import os
import pixelated.support.date
-from pixelated.adapter.pixelated_mail import PixelatedMail
import test_helper
+from pixelated.adapter.pixelated_mail import PixelatedMail
+from pixelated.adapter.tag_service import TagService
+from pixelated.adapter.tag_index import TagIndex
+from pixelated.adapter.tag import Tag
+from mock import Mock
class TestPixelatedMail(unittest.TestCase):
@@ -72,11 +77,10 @@ class TestPixelatedMail(unittest.TestCase):
self.assertEqual('date now', mail.headers['date'])
- def test_update_tags_return_a_set_for_added_tags_and_a_set_for_removed_ones(self):
- pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_headers={'X-tags': '["custom_1", "custom_2"]'}))
- added, removed = pixelated_mail.update_tags(set(['custom_1', 'custom_3']))
- self.assertEquals(set(['custom_3']), added)
- self.assertEquals(set(['custom_2']), removed)
+ def test_update_tags_return_a_set_with_the_current_tags(self):
+ pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_headers={'X-tags': '["custom_1", "custom_2"]'}), Mock())
+ current_tags = pixelated_mail.update_tags(set(['custom_1', 'custom_3']))
+ self.assertEquals(set(['custom_3', 'custom_1']), current_tags)
def test_to_mime_multipart(self):
pixelated.support.date.iso_now = lambda: 'date now'
@@ -126,3 +130,20 @@ class TestPixelatedMail(unittest.TestCase):
mail.mark_as_not_recent()
self.assertEquals(mail.leap_mail.setFlags.call_args[0], (('\\Recent',), -1))
+
+ def test_remove_all_tags(self):
+ mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_headers={'X-Tags': '["skinka", "altoids"]'}), Mock())
+ self.assertEquals(set(['skinka', 'altoids']), mail.tags)
+
+ mail.remove_all_tags()
+ self.assertEquals(set([]), mail.tags)
+
+ def test_update_tags_notifies_tag_service(self):
+ db_path = '/tmp/test_update_tags_notifies_tag_service'
+ tag_service = TagService(TagIndex(db_path))
+ mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(), tag_service)
+
+ mail.update_tags(set(['new_tag']))
+ self.assertIn(Tag('new_tag'), tag_service.all_tags())
+
+ os.remove(db_path + '.db')
diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py
index b4ddb32d..ac9d3f34 100644
--- a/service/test/adapter/pixelated_mailbox_test.py
+++ b/service/test/adapter/pixelated_mailbox_test.py
@@ -14,10 +14,8 @@
# 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 mockito import *
-import leap
-import os
from pixelated.adapter.pixelated_mail import PixelatedMail
+from pixelated.adapter.status import Status
import test_helper
from pixelated.adapter.pixelated_mailbox import PixelatedMailbox
from mockito import *
@@ -42,13 +40,24 @@ class TestPixelatedMailbox(unittest.TestCase):
self.assertNotIn('spam', mailbox.mails()[0].tags)
def test_add_message_to_mailbox(self):
- PixelatedMail.from_email_address = 'pixel@ted.org'
mail = PixelatedMail.from_dict(test_helper.mail_dict())
- mail.to_smtp_format = lambda: 'the mail in smtp format'
+ mail.raw_message = lambda: 'the mail in smtp format'
leap_mailbox_messages = mock()
self.mailbox.leap_mailbox.messages = leap_mailbox_messages
- self.mailbox.add.wrapped_function(self.mailbox, mail)
+ self.mailbox._do_add_async.wrapped_function(self.mailbox, mail)
verify(leap_mailbox_messages).add_msg('the mail in smtp format')
+
+ def test_remove_message_from_mailbox(self):
+ mail = PixelatedMail.from_dict(test_helper.mail_dict())
+ mail.raw_message = lambda: 'the mail in smtp format'
+
+ mail.leap_mail = mock()
+ self.mailbox.leap_mailbox = mock()
+
+ self.mailbox.remove(mail)
+
+ verify(mail.leap_mail).setFlags((Status.PixelatedStatus.DELETED,), 1)
+ verify(self.mailbox.leap_mailbox).expunge()
diff --git a/service/test/adapter/test_tag_service.py b/service/test/adapter/test_tag_service.py
index b3a68c2b..027e6113 100644
--- a/service/test/adapter/test_tag_service.py
+++ b/service/test/adapter/test_tag_service.py
@@ -30,8 +30,8 @@ class TagServiceTest(unittest.TestCase):
self.tag_service = TagService(tag_index=self.tag_index)
def test_index_is_initialized_with_mail_tags_if_empty(self):
- mail_one = PixelatedMail.from_leap_mail(test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}), test_helper.leap_mailbox())
- mail_two = PixelatedMail.from_leap_mail(test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}), test_helper.leap_mailbox())
+ mail_one = PixelatedMail.from_leap_mail(test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}))
+ mail_two = PixelatedMail.from_leap_mail(test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}))
mails = [mail_one, mail_two]
self.tag_service.load_index(mails)