diff options
author | Patrick Maia and Victor Shyba <pixelated-team+pmaia+vshyba@thoughtworks.com> | 2014-08-26 22:06:43 +0000 |
---|---|---|
committer | Patrick Maia <pmaia@thoughtworks.com> | 2014-08-26 22:27:48 +0000 |
commit | 6592bfad8cb90d7256de949b181ed9d0b684afec (patch) | |
tree | 0541e5a280ea168d4b8603344449916c5c007593 /service/test | |
parent | cf3ea5411adb12dd1bdc12ec01a17b37d974c7c3 (diff) |
extracts tag and status conversion logic
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/adapter/mail_service_test.py | 3 | ||||
-rw-r--r-- | service/test/adapter/pixelated_mail_test.py | 12 | ||||
-rw-r--r-- | service/test/adapter/test_status.py | 35 | ||||
-rw-r--r-- | service/test/adapter/test_tag.py | 46 | ||||
-rw-r--r-- | service/test/test_tags.py | 57 |
5 files changed, 84 insertions, 69 deletions
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 <http://www.gnu.org/licenses/>. +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 <http://www.gnu.org/licenses/>. +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) diff --git a/service/test/test_tags.py b/service/test/test_tags.py deleted file mode 100644 index abd59b20..00000000 --- a/service/test/test_tags.py +++ /dev/null @@ -1,57 +0,0 @@ -# -# 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 pixelated.tags import Tags, Tag - - -class TagTestCase(unittest.TestCase): - - def test_create_tag(self): - tag = Tag('test', True) - self.assertEqual(tag.name, 'test') - - -class TagsTestCase(unittest.TestCase): - - def test_add_tag_to_collection(self): - tag_collection = Tags() - tag_collection.add('test') - self.assertEqual(len(tag_collection), len(Tags()) + 1) - tag_collection.add('test2') - self.assertEqual(len(tag_collection), len(Tags()) + 2) - - def test_no_tag_duplication(self): - tag_collection = Tags() - tag_collection.add('test') - self.assertEqual(len(tag_collection), len(Tags()) + 1) - tag_collection.add('test') - self.assertEqual(len(tag_collection), len(Tags()) + 1) - - def test_find_tag_on_collection(self): - tag_collection = Tags() - tag_collection.add('test') - tag_collection.add('test2') - self.assertEqual(tag_collection.find('test'), Tag('test', True)) - - def test_special_tags_always_exist(self): - special_tags = ['inbox', 'sent', 'drafts', 'trash'] - tag_collection = Tags() - for tag in special_tags: - self.assertIn(Tag(tag, True), tag_collection) - - def test_special_tags_are_default(self): - tags = Tags() - self.assertTrue(tags.find('inbox').default) |