diff options
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/adapter/mail_service_test.py | 4 | ||||
-rw-r--r-- | service/test/adapter/pixelated_mailbox_test.py | 23 | ||||
-rw-r--r-- | service/test/adapter/test_helper.py | 3 | ||||
-rw-r--r-- | service/test/adapter/test_tag.py | 17 |
4 files changed, 34 insertions, 13 deletions
diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py index 7c928ec4..6972f6f6 100644 --- a/service/test/adapter/mail_service_test.py +++ b/service/test/adapter/mail_service_test.py @@ -24,10 +24,10 @@ from pixelated.adapter.pixelated_mailbox import PixelatedMailbox class TestMailService(unittest.TestCase): - @patch.object(MailService, 'set_flags', return_value=None) + @patch.object(MailService, '_set_mail_flags', return_value=None) def test_custom_tags_get_created_if_not_exists(self, mockSetFlags): MailService._open_leap_session = lambda self: None - MailService.mailbox = PixelatedMailbox(Mock(messages=[test_helper.leap_mail(uid=6, leap_flags=['\\Recent'])])) + MailService.mailbox = PixelatedMailbox(test_helper.leap_mailbox(leap_flags=['\\Recent'])) MailService.account = Mock(return_value=MagicMock()) mailservice = MailService('username', 'password', 'leap_server') diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py index 33cac5b9..1047eed4 100644 --- a/service/test/adapter/pixelated_mailbox_test.py +++ b/service/test/adapter/pixelated_mailbox_test.py @@ -15,8 +15,6 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import unittest -from pixelated.adapter.mail_service import MailService -from mock import Mock, MagicMock, patch import test_helper from pixelated.adapter.tag import Tag from pixelated.adapter.pixelated_mailbox import PixelatedMailbox @@ -24,13 +22,20 @@ from pixelated.adapter.pixelated_mailbox import PixelatedMailbox class TestPixelatedMailbox(unittest.TestCase): - @patch.object(MailService, 'set_flags', return_value=None) - def test_retrieve_all_tags_from_mailbox(self, mockSetFlags): - MailService._open_leap_session = lambda self: None + def test_retrieve_all_tags_from_mailbox(self): leap_flags = ['\\Deleted', '\\Draft', '\\Recent', 'tag_custom', 'should_ignore_all_from_here', 'List'] - MailService.mailbox = PixelatedMailbox(test_helper.leap_mailbox(leap_flags=leap_flags)) - MailService.account = Mock(return_value=MagicMock()) + mailbox = PixelatedMailbox(test_helper.leap_mailbox(leap_flags=leap_flags)) - mailservice = MailService('username', 'password', 'leap_server') + self.assertEquals(set([Tag('trash'), Tag('inbox'), Tag('drafts'), Tag('custom')]), mailbox.all_tags()) - self.assertEquals(set([Tag('trash'), Tag('inbox'), Tag('drafts'), Tag('custom')]), mailservice.all_tags()) + def test_new_tags_are_added_to_mailbox(self): + leap_flags = ['\\Deleted', 'tag_custom_one', 'tag_custom_two'] + leap_mailbox_mock = test_helper.leap_mailbox(leap_flags=leap_flags) + mailbox = PixelatedMailbox(leap_mailbox_mock) + tags = [Tag('custom_one'), Tag('custom_three')] + mailbox.update_tags(tags) + + expected = set(('\\Deleted', 'tag_custom_one', 'tag_custom_two', 'tag_custom_three')) + actual_args = set(leap_mailbox_mock.setFlags.call_args[0][0]) + + self.assertEquals(expected, actual_args) diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py index ae4bf887..5362b029 100644 --- a/service/test/adapter/test_helper.py +++ b/service/test/adapter/test_helper.py @@ -35,4 +35,5 @@ def leap_mail(uid=0, leap_flags=LEAP_FLAGS, extra_flags=[], headers={'date': str def leap_mailbox(leap_flags=LEAP_FLAGS, extra_flags=[]): flags = leap_flags + extra_flags - return Mock(getFlags=Mock(return_value=flags)) + return Mock(getFlags=Mock(return_value=flags), + messages=[leap_mail(uid=6, leap_flags=[], extra_flags=[])]) diff --git a/service/test/adapter/test_tag.py b/service/test/adapter/test_tag.py index 30bc1550..b9b502d4 100644 --- a/service/test/adapter/test_tag.py +++ b/service/test/adapter/test_tag.py @@ -16,7 +16,6 @@ import unittest from pixelated.adapter.tag import Tag -import test_helper class TestTag(unittest.TestCase): @@ -44,3 +43,19 @@ class TestTag(unittest.TestCase): def test_bulk_conversion(self): tags = Tag.from_flags(['\\Answered', '\\Seen', '\\Recent', 'tag_a_custom', 'List']) self.assertEquals(set([Tag('inbox'), Tag('a_custom')]), tags) + + def test_inbox_tag_is_translated_to_leap_recent_flag(self): + flag = Tag('inbox').to_flag() + self.assertEquals('\\Recent', flag) + + def test_trash_tag_is_translated_to_leap_deleted_flag(self): + flag = Tag('trash').to_flag() + self.assertEquals('\\Deleted', flag) + + def test_drafts_tag_is_translated_to_leap_draft_flag(self): + flag = Tag('drafts').to_flag() + self.assertEquals('\\Draft', flag) + + def test_custom_tag_has_prefix_when_translated_to_flag(self): + flag = Tag('work').to_flag() + self.assertEquals('tag_work', flag) |