From 6592bfad8cb90d7256de949b181ed9d0b684afec Mon Sep 17 00:00:00 2001 From: Patrick Maia and Victor Shyba Date: Tue, 26 Aug 2014 22:06:43 +0000 Subject: extracts tag and status conversion logic --- service/test/adapter/mail_service_test.py | 3 +- service/test/adapter/pixelated_mail_test.py | 12 ++------ service/test/adapter/test_status.py | 35 ++++++++++++++++++++++ service/test/adapter/test_tag.py | 46 +++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 service/test/adapter/test_status.py create mode 100644 service/test/adapter/test_tag.py (limited to 'service/test/adapter') diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py index d4a0d5c3..86194036 100644 --- a/service/test/adapter/mail_service_test.py +++ b/service/test/adapter/mail_service_test.py @@ -18,8 +18,7 @@ import unittest from pixelated.adapter.mail_service import MailService from mock import Mock, MagicMock, patch import test_helper -from pixelated.tags import Tag - +from pixelated.adapter.tag import Tag class TestMailService(unittest.TestCase): diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py index 308424e0..c7fe9112 100644 --- a/service/test/adapter/pixelated_mail_test.py +++ b/service/test/adapter/pixelated_mail_test.py @@ -16,8 +16,8 @@ import unittest from pixelated.adapter.pixelated_mail import PixelatedMail -from pixelated.tags import Tag -from pixelated.tags import Tags +from pixelated.adapter.tag import Tag +from pixelated.adapter.status import Status import test_helper @@ -35,14 +35,6 @@ class TestPixelatedMail(unittest.TestCase): pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=['\\Draft'])) self.assertIn(Tag('drafts'), pixelated_mail.tags) - def test_leap_seen_flag_is_translated_to_read_status(self): - pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=['\\Seen'])) - self.assertIn('read', pixelated_mail.status) - - def test_leap_answered_flag_is_translated_to_replied_status(self): - pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=['\\Answered'])) - self.assertIn('replied', pixelated_mail.status) - 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) diff --git a/service/test/adapter/test_status.py b/service/test/adapter/test_status.py new file mode 100644 index 00000000..b39d4846 --- /dev/null +++ b/service/test/adapter/test_status.py @@ -0,0 +1,35 @@ +# +# 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 . +import unittest + +from pixelated.adapter.status import Status +import test_helper + + +class TestStatus(unittest.TestCase): + + def test_leap_seen_flag_is_translated_to_read_status(self): + status = Status.from_flag('\\Seen') + self.assertEquals(Status('read'), status) + + def test_leap_answered_flag_is_translated_to_replied_status(self): + status = Status.from_flag('\\Answered') + self.assertEquals(Status('replied'), status) + + def test_bulk_conversion(self): + statuses = Status.from_flags(['\\Answered', '\\Seen', '\\Recent', 'tag_a_custom']) + self.assertEquals(set([Status('read'), Status('replied')]), statuses) + diff --git a/service/test/adapter/test_tag.py b/service/test/adapter/test_tag.py new file mode 100644 index 00000000..30bc1550 --- /dev/null +++ b/service/test/adapter/test_tag.py @@ -0,0 +1,46 @@ +# +# 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 . +import unittest + +from pixelated.adapter.tag import Tag +import test_helper + + +class TestTag(unittest.TestCase): + + def test_leap_recent_flag_is_translated_to_inbox_tag(self): + tag = Tag.from_flag('\\Recent') + self.assertEquals(Tag('inbox'), tag) + + def test_leap_deleted_flag_is_translated_to_trash_tag(self): + tag = Tag.from_flag('\\Deleted') + self.assertEquals(Tag('trash'), tag) + + def test_leap_draft_flag_is_translated_to_draft_tag(self): + tag = Tag.from_flag('\\Draft') + self.assertEquals(Tag('drafts'), tag) + + def test_leap_flags_that_are_custom_tags_are_handled(self): + tag = Tag.from_flag('tag_work') + self.assertEquals(Tag('work'), tag) + + def test_custom_tags_containing_our_prefix_are_handled(self): + tag = Tag.from_flag('tag_tag_work_tag_') + self.assertEquals(Tag('tag_work_tag_'), tag) + + 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) -- cgit v1.2.3