def test_update_tags_return_a_set_for_current_tags_and_a_set_for_removed(self):
     pixelated_mail = PixelatedMail.from_leap_mail(
         test_helper.leap_mail(leap_flags=[], extra_flags=["tag_custom_1", "tag_custom_2"])
     )
     current_tags, removed_tags = pixelated_mail.update_tags(set([Tag("custom_1"), Tag("custom_3")]))
     self.assertEquals(set([Tag("custom_3"), Tag("custom_1")]), current_tags)
     self.assertEquals(set([Tag("custom_2")]), removed_tags)
    def test_search_for_tags(self):
        # given
        mailbox = test_helper.leap_mailbox(leap_flags=['\\Recent'], extra_flags=['tag_custom_tag'])
        matching_mail = test_helper.leap_mail(uid=6, leap_flags=[], extra_flags=['tag_custom_tag'])
        not_matching_mail = test_helper.leap_mail(uid=6, leap_flags=[], extra_flags=['tag_other'])
        mailbox.messages = [matching_mail, not_matching_mail]
        mailbox.all_tags.return_value = set()
        account = MagicMock()
        account.mailboxes = ['inbox']
        account.getMailbox.return_value = mailbox

        leap_session = MagicMock(account=account)

        # when
        mailservice = MailService(leap_session)
        mails = mailservice.mails({'tags': ['inbox', 'custom_tag']})

        # then
        self.assertEqual(1, len(mails))
        self.assertEqual(set([Tag('custom_tag')]), mails[0].tags)
 def test_non_tags_flags_are_ignored(self):
     pixelated_mail = PixelatedMail.from_leap_mail(
         test_helper.leap_mail(leap_flags=["\\Recent"], extra_flags=["this_is_not_a_tag", "tag_custom_tag"])
     )
     self.assertEquals(set([Tag("custom_tag"), Tag("inbox")]), pixelated_mail.tags)
 def test_custom_tags_containing_our_prefix_are_handled(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_flags=["tag_tag_work_tag_"]))
     self.assertIn(Tag("tag_work_tag_"), pixelated_mail.tags)
 def test_leap_flags_that_are_custom_tags_are_handled(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_flags=["tag_work"]))
     self.assertIn(Tag("work"), pixelated_mail.tags)
 def test_leap_draft_flag_is_translated_to_draft_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Draft"]))
     self.assertIn(Tag("drafts"), pixelated_mail.tags)
 def test_leap_deleted_flag_is_translated_to_trash_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Deleted"]))
     self.assertIn(Tag("trash"), pixelated_mail.tags)
 def test_leap_recent_flag_is_translated_to_inbox_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Recent"]))
     self.assertIn(Tag("inbox"), pixelated_mail.tags)