From 0bad14f4b0e6dd5128660d94a436463cbe7dc720 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Thu, 9 Oct 2014 12:03:31 +0200 Subject: Changing tests folder structure --- service/test/adapter/__init__.py | 0 service/test/adapter/mail_service_test.py | 60 ---------- service/test/adapter/pixelated_mail_sender_test.py | 45 ------- service/test/adapter/pixelated_mail_test.py | 133 --------------------- service/test/adapter/pixelated_mailbox_test.py | 36 ------ service/test/adapter/pixelated_mailboxes_test.py | 68 ----------- service/test/adapter/tag_index_test.py | 88 -------------- service/test/adapter/test_helper.py | 71 ----------- service/test/adapter/test_status.py | 34 ------ service/test/adapter/test_tag.py | 79 ------------ service/test/adapter/test_tag_service.py | 59 --------- 11 files changed, 673 deletions(-) delete mode 100644 service/test/adapter/__init__.py delete mode 100644 service/test/adapter/mail_service_test.py delete mode 100644 service/test/adapter/pixelated_mail_sender_test.py delete mode 100644 service/test/adapter/pixelated_mail_test.py delete mode 100644 service/test/adapter/pixelated_mailbox_test.py delete mode 100644 service/test/adapter/pixelated_mailboxes_test.py delete mode 100644 service/test/adapter/tag_index_test.py delete mode 100644 service/test/adapter/test_helper.py delete mode 100644 service/test/adapter/test_status.py delete mode 100644 service/test/adapter/test_tag.py delete mode 100644 service/test/adapter/test_tag_service.py (limited to 'service/test/adapter') diff --git a/service/test/adapter/__init__.py b/service/test/adapter/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py deleted file mode 100644 index 549ab05c..00000000 --- a/service/test/adapter/mail_service_test.py +++ /dev/null @@ -1,60 +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 . -import unittest - -from pixelated.adapter.mail_service import MailService -from mockito import * -import pixelated.adapter.soledad_querier - - -class TestMailService(unittest.TestCase): - def setUp(self): - self.querier = mock() - pixelated.adapter.soledad_querier.get_soledad_querier_instance = lambda x, y: self.querier - - self.mailboxes = mock() - self.mailboxes.drafts = lambda: mock() - self.mailboxes.trash = lambda: mock() - self.mailboxes.sent = lambda: mock() - - self.mail_sender = mock() - self.mail_service = MailService(self.mailboxes, self.mail_sender) - - def test_send_mail(self): - mail = "mail" - - self.mail_service.send(1, mail) - - verify(self.mail_sender).sendmail(mail) - - def test_mark_as_read(self): - mail = mock() - when(self.mail_service).mail(any()).thenReturn(mail) - self.mail_service.mark_as_read(1) - - verify(mail).mark_as_read() - - def test_create_draft(self): - mail = '' - - self.mail_service.create_draft(mail) - - verify(self.mailboxes).add_draft(mail) - - def test_delete_mail(self): - self.mail_service.delete_mail(1) - - verify(self.mailboxes).move_to_trash(1) diff --git a/service/test/adapter/pixelated_mail_sender_test.py b/service/test/adapter/pixelated_mail_sender_test.py deleted file mode 100644 index d75aa57c..00000000 --- a/service/test/adapter/pixelated_mail_sender_test.py +++ /dev/null @@ -1,45 +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 . -import unittest -from pixelated.adapter.pixelated_mail import PixelatedMail -from pixelated.adapter.pixelated_mail_sender import PixelatedMailSender -from mockito import * -import test_helper - - -class PixelatedMailSenderTest(unittest.TestCase): - def setUp(self): - self.mail_address = "pixelated@pixelated.org" - self.smtp_client = mock() - self.mail_sender = PixelatedMailSender(self.mail_address, self.smtp_client) - - def test_send_mail_sends_to_To_Cc_and_Bcc(self): - headers = { - 'To': ['to@pixelated.org', 'anotherto@pixelated.org'], - 'Cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], - 'Bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'] - } - - mail = PixelatedMail.from_soledad(*test_helper.leap_mail(extra_headers=headers)) - mail.to_smtp_format = lambda: "mail as smtp string" - - self.mail_sender.sendmail(mail) - - expected_recipients = ['to@pixelated.org', 'anotherto@pixelated.org', 'cc@pixelated.org', - 'anothercc@pixelated.org', - 'bcc@pixelated.org', 'anotherbcc@pixelated.org'] - - verify(self.smtp_client).sendmail(self.mail_address, expected_recipients, "mail as smtp string") diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py deleted file mode 100644 index 28f70afa..00000000 --- a/service/test/adapter/pixelated_mail_test.py +++ /dev/null @@ -1,133 +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 . -import unittest -import os - -import pixelated.support.date -import test_helper -from pixelated.adapter.pixelated_mail import PixelatedMail, InputMail -from pixelated.adapter.tag_service import TagService -from pixelated.adapter.tag_index import TagIndex -from pixelated.adapter.tag import Tag -from mockito import * - - -class TestPixelatedMail(unittest.TestCase): - - def setUp(self): - self.querier = mock() - - def test_parse_date_from_soledad_uses_date_header_if_available(self): - leap_mail_date = 'Wed, 3 Sep 2014 12:36:17 -0300' - leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00" - - leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date}) - - mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier) - - self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format) - - def test_parse_date_from_soledad_fallback_to_received_header_if_date_header_isnt_available(self): - leap_mail_date = "Wed, 03 Sep 2014 13:11:15 -0300" - leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00" - leap_mail_received_header = "by bitmask.local from 127.0.0.1 with ESMTP ;\n " + leap_mail_date - - leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header}) - - mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier) - - self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format) - - def test_update_tags_return_a_set_with_the_current_tags(self): - soledad_docs = test_helper.leap_mail(extra_headers={'X-tags': '["custom_1", "custom_2"]'}) - pixelated_mail = PixelatedMail.from_soledad(*soledad_docs, soledad_querier=self.querier) - - current_tags = pixelated_mail.update_tags({'custom_1', 'custom_3'}) - self.assertEquals({'custom_3', 'custom_1'}, current_tags) - - def test_mark_as_read(self): - mail = PixelatedMail.from_soledad(*test_helper.leap_mail(flags=[]), soledad_querier=self.querier) - - mail.mark_as_read() - - self.assertEquals(mail.fdoc.content['flags'], ['\\Seen']) - - def test_mark_as_not_recent(self): - mail = PixelatedMail.from_soledad(*test_helper.leap_mail(flags=['\\Recent']), soledad_querier=self.querier) - - mail.mark_as_not_recent() - - self.assertEquals(mail.fdoc.content['flags'], []) - - def test_update_tags_notifies_tag_service(self): - db_path = '/tmp/test_update_tags_notifies_tag_service' - TagService.instance = TagService(TagIndex(db_path)) - - mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier) - - mail.update_tags({'new_tag'}) - self.assertIn(Tag('new_tag'), mail.tag_service.all_tags()) - - os.remove(db_path + '.db') - - -class InputMailTest(unittest.TestCase): - mail_dict = lambda x: { - 'body': 'Este \xe9 o corpo', - 'header': { - 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], - 'to': ['to@pixelated.org', 'anotherto@pixelated.org'], - 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'], - 'subject': 'Oi' - }, - 'ident': '', - 'tags': ['sent'] - } - - def test_to_mime_multipart_should_add_blank_fields(self): - pixelated.support.date.iso_now = lambda: 'date now' - - mail_dict = self.mail_dict() - mail_dict['header']['to'] = '' - mail_dict['header']['bcc'] = '' - mail_dict['header']['cc'] = '' - mail_dict['header']['subject'] = '' - - mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart() - - self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n") - self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n") - self.assertNotRegexpMatches(mime_multipart.as_string(), "\nCc: \n") - self.assertNotRegexpMatches(mime_multipart.as_string(), "\nSubject: \n") - - def test_to_mime_multipart(self): - pixelated.support.date.iso_now = lambda: 'date now' - - mime_multipart = InputMail.from_dict(self.mail_dict()).to_mime_multipart() - - self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: to@pixelated.org, anotherto@pixelated.org\n") - self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: cc@pixelated.org, anothercc@pixelated.org\n") - self.assertRegexpMatches(mime_multipart.as_string(), "\nBcc: bcc@pixelated.org, anotherbcc@pixelated.org\n") - self.assertRegexpMatches(mime_multipart.as_string(), "\nDate: date now\n") - self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n") - self.assertRegexpMatches(mime_multipart.as_string(), "\nEste \xe9 o corpo") - - def test_smtp_format(self): - PixelatedMail.from_email_address = 'pixelated@org' - - smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format() - - self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org") diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py deleted file mode 100644 index a6e4a1ab..00000000 --- a/service/test/adapter/pixelated_mailbox_test.py +++ /dev/null @@ -1,36 +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 . -import unittest - -from pixelated.adapter.pixelated_mail import PixelatedMail -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -import test_helper -from mockito import * - - -class PixelatedMailboxTest(unittest.TestCase): - def setUp(self): - self.tag_service = mock() - self.querier = mock() - self.mailbox = PixelatedMailbox('INBOX', self.querier, tag_service=self.tag_service) - - def test_remove_message_from_mailbox(self): - mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier) - when(self.querier).mail(1).thenReturn(mail) - - self.mailbox.remove(1) - - verify(self.querier).remove_mail(mail) diff --git a/service/test/adapter/pixelated_mailboxes_test.py b/service/test/adapter/pixelated_mailboxes_test.py deleted file mode 100644 index dc7243f2..00000000 --- a/service/test/adapter/pixelated_mailboxes_test.py +++ /dev/null @@ -1,68 +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 . -import unittest - -from test.adapter import test_helper -from mockito import * -import pixelated.adapter.soledad_querier - -querier = mock() -global querier -pixelated.adapter.soledad_querier.get_soledad_querier_instance = lambda x, y: querier - -from pixelated.adapter.pixelated_mail import InputMail -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes - - -class PixelatedMailboxesTest(unittest.TestCase): - def setUp(self): - - self.account = mock() - self.drafts_mailbox = mock() - self.drafts_mailbox.mailbox_name = 'drafts' - self.mailboxes = PixelatedMailBoxes(self.account) - self.mailboxes.drafts = lambda: self.drafts_mailbox - - def test_search_for_tags(self): - mailbox = mock() - self.account.mailboxes = ['INBOX'] - tags_to_search_for = {'tags': ['inbox', 'custom_tag']} - - when(PixelatedMailbox).create('INBOX').thenReturn(mailbox) - when(mailbox).mails_by_tags(any(list)).thenReturn(["mail"]) - - mails = self.mailboxes.mails_by_tag(tags_to_search_for['tags']) - - self.assertEqual(1, len(mails)) - self.assertEqual("mail", mails[0]) - - def test_add_draft(self): - mail = InputMail() - when(self.drafts_mailbox).add(mail).thenReturn(1) - - self.mailboxes.add_draft(mail) - - verify(self.drafts_mailbox).add(mail) - - def test_update_draft(self): - mail = test_helper.input_mail() - when(self.drafts_mailbox).add(mail).thenReturn(mail) - - self.mailboxes.update_draft(mail.ident, mail) - - inorder.verify(self.drafts_mailbox).add(mail) - inorder.verify(self.drafts_mailbox).remove(mail.ident) diff --git a/service/test/adapter/tag_index_test.py b/service/test/adapter/tag_index_test.py deleted file mode 100644 index 21564fc5..00000000 --- a/service/test/adapter/tag_index_test.py +++ /dev/null @@ -1,88 +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 . -import unittest -import os -import uuid - -from pixelated.adapter.tag_index import TagIndex -from pixelated.adapter.tag import Tag - - -class TestTagIndex(unittest.TestCase): - - def setUp(self): - self.db_path = '/tmp/test_tag_index_' + str(uuid.uuid4()) - self.tag_index = TagIndex(self.db_path) - - def tearDown(self): - self.tag_index._close_db() - os.remove(self.db_path + '.db') - - def test_get_and_set_works(self): - tag = Tag('a_tag') - self.tag_index.set(tag) - self.assertEquals(tag, self.tag_index.get('a_tag')) - - def test_values_returns_all_values_in_the_index(self): - tag_a = Tag('tag_a') - self.tag_index.set(tag_a) - tag_b = Tag('tag_b') - self.tag_index.set(tag_b) - tag_c = Tag('tag_c') - self.tag_index.set(tag_c) - - self.assertEquals(set([tag_a, tag_b, tag_c]), self.tag_index.values()) - - def test_changes_are_visible_between_instances_using_same_file(self): - tag = Tag('some_tag') - self.tag_index.set(tag) - - other_tag_index = TagIndex(self.db_path) - self.assertIn(tag, other_tag_index.values()) - - def test_add_does_not_replace_existent_tag_with_same_name(self): - tag = Tag('tag', True) - self.tag_index.set(tag) - - same_name_tag = Tag('tag', False) - self.tag_index.add(same_name_tag) - - self.assertEquals(True, self.tag_index.get('tag').default) - - def test_empty_returns_true_if_there_are_no_values(self): - self.assertTrue(self.tag_index.empty()) - - def test_empty_returns_false_if_there_are_values(self): - self.tag_index.set(Tag('tag')) - self.assertFalse(self.tag_index.empty()) - - def test_remove_deletes_the_tag_with_the_given_key_from_the_index(self): - self.tag_index.set(Tag('tag')) - self.tag_index.remove('tag') - self.assertEquals(None, self.tag_index.get('tag')) - - def test_remove_does_not_raises_exception_if_key_is_not_present(self): - self.tag_index.remove('not_there') - - def test_removals_are_visible_between_instances_using_same_file(self): - tag = Tag('some_tag') - self.tag_index.set(tag) - - other_tag_index = TagIndex(self.db_path) - other_tag_index.remove('some_tag') - - self.assertIsNone(self.tag_index.get('some_tag')) diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py deleted file mode 100644 index af0fed95..00000000 --- a/service/test/adapter/test_helper.py +++ /dev/null @@ -1,71 +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 . -from mock import Mock -from datetime import datetime -from pixelated.adapter.pixelated_mail import InputMail - -LEAP_FLAGS = ['\\Seen', - '\\Answered', - '\\Flagged', - '\\Deleted', - '\\Draft', - '\\Recent', - 'List'] - -DEFAULT_HEADERS = {'date': str(datetime.now())} - - -def mail_dict(): - return { - 'header': { - 'to': ['to@pixelated.org', 'anotherto@pixelated.org'], - 'cc': ['cc@pixelated.org', 'anothercc@pixelated.org'], - 'bcc': ['bcc@pixelated.org', 'anotherbcc@pixelated.org'], - 'subject': 'Subject' - }, - 'body': 'Body', - 'ident': '', - 'tags': [] - } - - -class TestDoc: - def __init__(self, content): - self.content = content - - -def leap_mail(uid=0, flags=LEAP_FLAGS, headers=None, extra_headers={}, mbox='INBOX', body='body', - chash='chash'): - fdoc = TestDoc({'flags': flags, 'mbox': mbox, 'type': 'flags', 'uid': uid, 'chash': chash}) - - if headers is None: - headers = {} - if not (headers.get('received') or headers.get('date')): - headers.update(DEFAULT_HEADERS) - headers['headers'] = extra_headers - hdoc = TestDoc(headers) - - bdoc = TestDoc({'raw': body, 'type': 'cnt'}) - - return (fdoc, hdoc, bdoc) - - -def input_mail(): - mail = InputMail() - mail.fdoc = TestDoc({}) - mail._chash = "123" - mail.as_dict = lambda: None - return mail diff --git a/service/test/adapter/test_status.py b/service/test/adapter/test_status.py deleted file mode 100644 index 7f644eca..00000000 --- a/service/test/adapter/test_status.py +++ /dev/null @@ -1,34 +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 . -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'), Status('recent')]), statuses) diff --git a/service/test/adapter/test_tag.py b/service/test/adapter/test_tag.py deleted file mode 100644 index fc14ff49..00000000 --- a/service/test/adapter/test_tag.py +++ /dev/null @@ -1,79 +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 . -import unittest - -from pixelated.adapter.tag import Tag - - -class TestTag(unittest.TestCase): - - def test_from_dict_sets_all_tag_attributes(self): - tag_dict = {'name': 'a_tag', - 'default': False, - 'counts': {'total': 3, - 'read': 1, - 'starred': 1, - 'replied': 1}, - 'mails': [1, 2, 3]} - - tag = Tag.from_dict(tag_dict) - - self.assertEquals(tag_dict['name'], tag.name) - self.assertEquals(tag_dict['default'], tag.default) - self.assertEquals(tag_dict['counts']['total'], tag.total) - # Checks if mail ids are aways restored as set() - self.assertEquals(type(tag.mails), type(set())) - self.assertEquals(set(tag_dict['mails']), tag.mails) - - def test_as_dict_puts_all_tag_attributes_in_the_returning_dict(self): - tag = Tag('some_tag', default=True) - tag.counts = {'total': 0, 'read': 0, 'starred': 0, 'replied': 0} - tag.mails = [1, 2, 3] - - tag_dict = tag.as_dict() - - self.assertEquals(tag.name, tag_dict['name']) - self.assertEquals(tag.default, tag_dict['default']) - self.assertEquals(tag.total, tag_dict['counts']['total']) - self.assertEquals(tag.mails, tag_dict['mails']) - - def test_increments_total_count_and_adds_mails_id_to_mails(self): - tag = Tag('another') - tag.increment(12) - - self.assertIn(12, tag.mails) - self.assertEquals(1, tag.total) - - def test_decrement_does_nothing_if_mail_has_not_the_tag(self): - tag = Tag('tag') - tag.decrement(2000) - - self.assertEquals(0, tag.total) - - def test_increment_does_nothing_if_mail_already_has_the_tag(self): - tag = Tag('tag') - tag.mails = set([12]) - tag.increment(12) - - self.assertEquals(1, tag.total) - - def test_decrements_total_count_and_removes_mails_id_from_mails(self): - tag = Tag('one_more') - tag.mails = set([12]) - tag.decrement(12) - - self.assertNotIn(12, tag.mails) - self.assertEquals(0, tag.total) diff --git a/service/test/adapter/test_tag_service.py b/service/test/adapter/test_tag_service.py deleted file mode 100644 index 5a70e82b..00000000 --- a/service/test/adapter/test_tag_service.py +++ /dev/null @@ -1,59 +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 . - -import unittest -import tempfile -import test_helper -from pixelated.adapter.tag import Tag -from pixelated.adapter.pixelated_mail import PixelatedMail -from pixelated.adapter.tag_index import TagIndex -from pixelated.adapter.tag_service import TagService - - -class TagServiceTest(unittest.TestCase): - def setUp(self): - self.index_file_handler, self.index_file_path = tempfile.mkstemp() - self.tag_index = TagIndex(self.index_file_path) - self.tag_service = TagService(tag_index=self.tag_index) - - def test_index_is_initialized_with_mail_tags_if_empty(self): - mail_one = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'})) - mail_two = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'})) - mails = [mail_one, mail_two] - - self.tag_service.load_index(mails) - - self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash'), Tag('tag_1'), Tag('tag_2')}) - - def test_special_tags_always_exists(self): - self.tag_service.load_index([]) - - self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash')}) - - def test_notify_tags_updated_method_properly_changes_tags_state(self): - mail_ident = 12 - tag = Tag('one_tag') - tag.increment(mail_ident) - self.tag_service.load_index([]) - self.tag_service.tag_index.set(tag) - - self.assertEquals(0, self.tag_service.tag_index.get('inbox').total) - self.assertEquals(1, self.tag_service.tag_index.get('one_tag').total) - - self.tag_service.notify_tags_updated({'inbox'}, {'one_tag'}, mail_ident) - - self.assertEquals(1, self.tag_service.tag_index.get('inbox').total) - self.assertIsNone(self.tag_service.tag_index.get('one_tag')) -- cgit v1.2.3