From b2334df7a677047749d411dda4cd4cd58474ee8a Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Wed, 15 Oct 2014 16:39:32 +0200 Subject: getting rid of "pixelated" in the names of many classes - redundant --- service/pixelated/adapter/listener.py | 48 --------- service/pixelated/adapter/mail_sender.py | 33 ++++++ service/pixelated/adapter/mailbox.py | 53 +++++++++ .../pixelated/adapter/mailbox_indexer_listener.py | 48 +++++++++ service/pixelated/adapter/mailboxes.py | 68 ++++++++++++ service/pixelated/adapter/pixelated_mail_sender.py | 33 ------ service/pixelated/adapter/pixelated_mailbox.py | 53 --------- service/pixelated/adapter/pixelated_mailboxes.py | 68 ------------ service/pixelated/config/app_factory.py | 12 +-- service/test/functional/features/environment.py | 2 +- service/test/integration/tags_test.py | 2 +- service/test/support/integration_helper.py | 10 +- service/test/unit/adapter/listener_test.py | 54 ---------- service/test/unit/adapter/mail_sender_test.py | 46 ++++++++ service/test/unit/adapter/mail_test.py | 118 +++++++++++++++++++++ .../unit/adapter/mailbox_indexer_listener_test.py | 54 ++++++++++ service/test/unit/adapter/mailbox_test.py | 36 +++++++ service/test/unit/adapter/mailboxes_test.py | 46 ++++++++ .../unit/adapter/pixelated_mail_sender_test.py | 46 -------- service/test/unit/adapter/pixelated_mail_test.py | 118 --------------------- .../test/unit/adapter/pixelated_mailbox_test.py | 36 ------- .../test/unit/adapter/pixelated_mailboxes_test.py | 46 -------- service/test/unit/runserver_test.py | 59 +++++++++++ service/test/unit/user_agent_test.py | 58 ---------- 24 files changed, 574 insertions(+), 573 deletions(-) delete mode 100644 service/pixelated/adapter/listener.py create mode 100644 service/pixelated/adapter/mail_sender.py create mode 100644 service/pixelated/adapter/mailbox.py create mode 100644 service/pixelated/adapter/mailbox_indexer_listener.py create mode 100644 service/pixelated/adapter/mailboxes.py delete mode 100644 service/pixelated/adapter/pixelated_mail_sender.py delete mode 100644 service/pixelated/adapter/pixelated_mailbox.py delete mode 100644 service/pixelated/adapter/pixelated_mailboxes.py delete mode 100644 service/test/unit/adapter/listener_test.py create mode 100644 service/test/unit/adapter/mail_sender_test.py create mode 100644 service/test/unit/adapter/mail_test.py create mode 100644 service/test/unit/adapter/mailbox_indexer_listener_test.py create mode 100644 service/test/unit/adapter/mailbox_test.py create mode 100644 service/test/unit/adapter/mailboxes_test.py delete mode 100644 service/test/unit/adapter/pixelated_mail_sender_test.py delete mode 100644 service/test/unit/adapter/pixelated_mail_test.py delete mode 100644 service/test/unit/adapter/pixelated_mailbox_test.py delete mode 100644 service/test/unit/adapter/pixelated_mailboxes_test.py create mode 100644 service/test/unit/runserver_test.py delete mode 100644 service/test/unit/user_agent_test.py (limited to 'service') diff --git a/service/pixelated/adapter/listener.py b/service/pixelated/adapter/listener.py deleted file mode 100644 index 67d75df7..00000000 --- a/service/pixelated/adapter/listener.py +++ /dev/null @@ -1,48 +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 PCULAR 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 . - - -class MailboxListener(object): - """ Listens for new mails, keeping the index updated """ - - SEARCH_ENGINE = None - - @classmethod - def listen(cls, account, mailbox_name, soledad_querier): - listener = MailboxListener(mailbox_name, soledad_querier) - if listener not in account.getMailbox(mailbox_name).listeners: - account.getMailbox(mailbox_name).addListener(listener) - - def __init__(self, mailbox_name, soledad_querier): - self.mailbox_name = mailbox_name - self.querier = soledad_querier - - def newMessages(self, exists, recent): - indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) - soledad_idents = self.querier.idents_by_mailbox(self.mailbox_name) - - missing_idents = soledad_idents.difference(indexed_idents) - - self.SEARCH_ENGINE.index_mails(self.querier.mails(missing_idents)) - - def __eq__(self, other): - return other and other.mailbox_name == self.mailbox_name - - def __hash__(self): - return self.mailbox_name.__hash__() - - def __repr__(self): - return 'MailboxListener: ' + self.mailbox_name diff --git a/service/pixelated/adapter/mail_sender.py b/service/pixelated/adapter/mail_sender.py new file mode 100644 index 00000000..1802a9d5 --- /dev/null +++ b/service/pixelated/adapter/mail_sender.py @@ -0,0 +1,33 @@ +# +# 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 smtplib + +from pixelated.support.functional import flatten + + +class MailSender(): + def __init__(self, account_email_address, smtp_client=None): + self.account_email_address = account_email_address + self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) + + def sendmail(self, mail): + recipients = flatten([mail.to, mail.cc, mail.bcc]) + + self.smtp_client.sendmail( + self.account_email_address, + recipients, + mail.to_smtp_format() + ) diff --git a/service/pixelated/adapter/mailbox.py b/service/pixelated/adapter/mailbox.py new file mode 100644 index 00000000..b5f2e6ea --- /dev/null +++ b/service/pixelated/adapter/mailbox.py @@ -0,0 +1,53 @@ +# +# 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 . + + +class Mailbox: + + def __init__(self, mailbox_name, querier): + self.mailbox_name = mailbox_name + self.mailbox_tag = mailbox_name.lower() + self.querier = querier + + def mails(self): + _mails = self.querier.all_mails_by_mailbox(self.mailbox_name) + + result = [] + for mail in _mails: + result.append(mail) + return result + + def mails_by_tags(self, tags): + if 'all' in tags or self.mailbox_tag in tags: + return self.mails() + return [mail for mail in self.mails() if len(mail.tags.intersection(tags)) > 0] + + def mail(self, mail_id): + for message in self.mails(): + if message.ident == mail_id: + return message + + def add(self, mail): + return self.querier.create_mail(mail, self.mailbox_name) + + def remove(self, ident): + mail = self.querier.mail(ident) + mail.remove_all_tags() + self.querier.remove_mail(mail) + + @classmethod + def create(cls, mailbox_name, soledad_querier): + return Mailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/mailbox_indexer_listener.py b/service/pixelated/adapter/mailbox_indexer_listener.py new file mode 100644 index 00000000..a7309118 --- /dev/null +++ b/service/pixelated/adapter/mailbox_indexer_listener.py @@ -0,0 +1,48 @@ +# +# 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 PCULAR 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 . + + +class MailboxIndexerListener(object): + """ Listens for new mails, keeping the index updated """ + + SEARCH_ENGINE = None + + @classmethod + def listen(cls, account, mailbox_name, soledad_querier): + listener = MailboxIndexerListener(mailbox_name, soledad_querier) + if listener not in account.getMailbox(mailbox_name).listeners: + account.getMailbox(mailbox_name).addListener(listener) + + def __init__(self, mailbox_name, soledad_querier): + self.mailbox_name = mailbox_name + self.querier = soledad_querier + + def newMessages(self, exists, recent): + indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) + soledad_idents = self.querier.idents_by_mailbox(self.mailbox_name) + + missing_idents = soledad_idents.difference(indexed_idents) + + self.SEARCH_ENGINE.index_mails(self.querier.mails(missing_idents)) + + def __eq__(self, other): + return other and other.mailbox_name == self.mailbox_name + + def __hash__(self): + return self.mailbox_name.__hash__() + + def __repr__(self): + return 'MailboxListener: ' + self.mailbox_name diff --git a/service/pixelated/adapter/mailboxes.py b/service/pixelated/adapter/mailboxes.py new file mode 100644 index 00000000..241a8050 --- /dev/null +++ b/service/pixelated/adapter/mailboxes.py @@ -0,0 +1,68 @@ +# +# 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 pixelated.adapter.mailbox import Mailbox +from pixelated.adapter.mailbox_indexer_listener import MailboxIndexerListener + + +class Mailboxes(): + + def __init__(self, account, soledad_querier): + self.account = account + self.querier = soledad_querier + for mailbox_name in account.mailboxes: + MailboxIndexerListener.listen(self.account, mailbox_name, soledad_querier) + + def _create_or_get(self, mailbox_name): + mailbox_name = mailbox_name.upper() + if mailbox_name not in self.account.mailboxes: + self.account.addMailbox(mailbox_name) + MailboxIndexerListener.listen(self.account, mailbox_name, self.querier) + return Mailbox.create(mailbox_name, self.querier) + + def inbox(self): + return self._create_or_get('INBOX') + + def drafts(self): + return self._create_or_get('DRAFTS') + + def trash(self): + return self._create_or_get('TRASH') + + def sent(self): + return self._create_or_get('SENT') + + def mailboxes(self): + return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] + + def mails_by_tag(self, query_tags): + mails = [] + for mailbox in self.mailboxes(): + mails.extend(mailbox.mails_by_tags(query_tags)) + + return mails + + def move_to_trash(self, mail_id): + mail = self.querier.mail(mail_id) + mail.remove_all_tags() + mail.set_mailbox(self.trash().mailbox_name) + mail.save() + return mail + + def mail(self, mail_id): + for mailbox in self.mailboxes(): + mail = mailbox.mail(mail_id) + if mail: + return mail diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py deleted file mode 100644 index bae86cd2..00000000 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ /dev/null @@ -1,33 +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 smtplib - -from pixelated.support.functional import flatten - - -class PixelatedMailSender(): - def __init__(self, account_email_address, smtp_client=None): - self.account_email_address = account_email_address - self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) - - def sendmail(self, mail): - recipients = flatten([mail.to, mail.cc, mail.bcc]) - - self.smtp_client.sendmail( - self.account_email_address, - recipients, - mail.to_smtp_format() - ) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py deleted file mode 100644 index 283567db..00000000 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ /dev/null @@ -1,53 +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 . - - -class PixelatedMailbox: - - def __init__(self, mailbox_name, querier): - self.mailbox_name = mailbox_name - self.mailbox_tag = mailbox_name.lower() - self.querier = querier - - def mails(self): - _mails = self.querier.all_mails_by_mailbox(self.mailbox_name) - - result = [] - for mail in _mails: - result.append(mail) - return result - - def mails_by_tags(self, tags): - if 'all' in tags or self.mailbox_tag in tags: - return self.mails() - return [mail for mail in self.mails() if len(mail.tags.intersection(tags)) > 0] - - def mail(self, mail_id): - for message in self.mails(): - if message.ident == mail_id: - return message - - def add(self, mail): - return self.querier.create_mail(mail, self.mailbox_name) - - def remove(self, ident): - mail = self.querier.mail(ident) - mail.remove_all_tags() - self.querier.remove_mail(mail) - - @classmethod - def create(cls, mailbox_name, soledad_querier): - return PixelatedMailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py deleted file mode 100644 index 79c007cb..00000000 --- a/service/pixelated/adapter/pixelated_mailboxes.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 . -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.listener import MailboxListener - - -class PixelatedMailBoxes(): - - def __init__(self, account, soledad_querier): - self.account = account - self.querier = soledad_querier - for mailbox_name in account.mailboxes: - MailboxListener.listen(self.account, mailbox_name, soledad_querier) - - def _create_or_get(self, mailbox_name): - mailbox_name = mailbox_name.upper() - if mailbox_name not in self.account.mailboxes: - self.account.addMailbox(mailbox_name) - MailboxListener.listen(self.account, mailbox_name, self.querier) - return PixelatedMailbox.create(mailbox_name, self.querier) - - def inbox(self): - return self._create_or_get('INBOX') - - def drafts(self): - return self._create_or_get('DRAFTS') - - def trash(self): - return self._create_or_get('TRASH') - - def sent(self): - return self._create_or_get('SENT') - - def mailboxes(self): - return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] - - def mails_by_tag(self, query_tags): - mails = [] - for mailbox in self.mailboxes(): - mails.extend(mailbox.mails_by_tags(query_tags)) - - return mails - - def move_to_trash(self, mail_id): - mail = self.querier.mail(mail_id) - mail.remove_all_tags() - mail.set_mailbox(self.trash().mailbox_name) - mail.save() - return mail - - def mail(self, mail_id): - for mailbox in self.mailboxes(): - mail = mailbox.mail(mail_id) - if mail: - return mail diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py index 596046c1..6c9c07fe 100644 --- a/service/pixelated/config/app_factory.py +++ b/service/pixelated/config/app_factory.py @@ -16,12 +16,12 @@ from pixelated.adapter.mail_service import MailService from pixelated.adapter.mail import InputMail -from pixelated.adapter.pixelated_mail_sender import PixelatedMailSender -from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes +from pixelated.adapter.mail_sender import MailSender +from pixelated.adapter.mailboxes import Mailboxes from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.adapter.search import SearchEngine from pixelated.adapter.draft_service import DraftService -from pixelated.adapter.listener import MailboxListener +from pixelated.adapter.mailbox_indexer_listener import MailboxIndexerListener import pixelated.bitmask_libraries.session as LeapSession from pixelated.controllers import * from pixelated.adapter.tag_service import TagService @@ -55,14 +55,14 @@ def create_app(debug_enabled, app): app.config['LEAP_SERVER_NAME']) tag_service = TagService() soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad) - pixelated_mailboxes = PixelatedMailBoxes(leap_session.account, soledad_querier) - pixelated_mail_sender = PixelatedMailSender(leap_session.account_email()) + pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier) + pixelated_mail_sender = MailSender(leap_session.account_email()) mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender, tag_service, soledad_querier) search_engine = SearchEngine() search_engine.index_mails(mail_service.all_mails()) draft_service = DraftService(pixelated_mailboxes) - MailboxListener.SEARCH_ENGINE = search_engine + MailboxIndexerListener.SEARCH_ENGINE = search_engine InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email() home_controller = HomeController() diff --git a/service/test/functional/features/environment.py b/service/test/functional/features/environment.py index 86f43d7f..9b587497 100644 --- a/service/test/functional/features/environment.py +++ b/service/test/functional/features/environment.py @@ -25,7 +25,7 @@ def before_all(context): context.soledad_test_base = SoledadTestBase() context.soledad_test_base.setup_soledad() - context.mailboxes = context.soledad_test_base.pixelated_mailboxes + context.mailboxes = context.soledad_test_base.mailboxes context.app = pixelated.runserver.app context.app.mail_service = context.soledad_test_base.mail_service diff --git a/service/test/integration/tags_test.py b/service/test/integration/tags_test.py index 351713eb..bd22e4b5 100644 --- a/service/test/integration/tags_test.py +++ b/service/test/integration/tags_test.py @@ -49,5 +49,5 @@ class TagsTest(unittest.TestCase, SoledadTestBase): response = self.post_tags(mail.ident, self._tags_json(['DRAFTS'])) self.assertEquals("None of the following words can be used as tags: drafts", response) - mail = self.pixelated_mailboxes.inbox().mail(mail.ident) + mail = self.mailboxes.inbox().mail(mail.ident) self.assertNotIn('drafts', mail.tags) diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py index 8f2b8192..268eb812 100644 --- a/service/test/support/integration_helper.py +++ b/service/test/support/integration_helper.py @@ -25,7 +25,7 @@ from pixelated.adapter.tag_service import TagService from pixelated.adapter.draft_service import DraftService from pixelated.adapter.mail import PixelatedMail, InputMail import pixelated.runserver -from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes +from pixelated.adapter.mailboxes import Mailboxes from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.controllers import * import pixelated.config.app_factory as app_factory @@ -153,11 +153,11 @@ class SoledadTestBase: self._reset_routes(self.client.application) self.soledad_querier = SoledadQuerier(self.soledad) self.account = FakeAccount() - self.pixelated_mailboxes = PixelatedMailBoxes(self.account, self.soledad_querier) + self.mailboxes = Mailboxes(self.account, self.soledad_querier) self.mail_sender = mock() self.tag_service = TagService() - self.draft_service = DraftService(self.pixelated_mailboxes) - self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service, + self.draft_service = DraftService(self.mailboxes) + self.mail_service = MailService(self.mailboxes, self.mail_sender, self.tag_service, self.soledad_querier) self.search_engine = SearchEngine() self.search_engine.index_mails(self.mail_service.all_mails()) @@ -206,7 +206,7 @@ class SoledadTestBase: self.client.post('/mails/unread', data={'idents': json.dumps(idents)}) def add_mail_to_inbox(self, input_mail): - mail = self.pixelated_mailboxes.inbox().add(input_mail) + mail = self.mailboxes.inbox().add(input_mail) mail.update_tags(input_mail.tags) self.search_engine.index_mail(mail) diff --git a/service/test/unit/adapter/listener_test.py b/service/test/unit/adapter/listener_test.py deleted file mode 100644 index e131aebd..00000000 --- a/service/test/unit/adapter/listener_test.py +++ /dev/null @@ -1,54 +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 mockito import * -from pixelated.adapter.listener import MailboxListener - - -class MailboxListenerTest(unittest.TestCase): - def setUp(self): - self.querier = mock() - self.account = mock() - self.account.mailboxes = [] - - def test_add_itself_to_mailbox_listeners(self): - self.account.mailboxes = ['INBOX'] - mailbox = mock() - when(self.account).getMailbox('INBOX').thenReturn(mailbox) - mailbox.listeners = set() - when(mailbox).addListener = lambda x: mailbox.listeners.add(x) - - self.assertNotIn(MailboxListener('INBOX', self.querier), mailbox.listeners) - - MailboxListener.listen(self.account, 'INBOX', self.querier) - - self.assertIn(MailboxListener('INBOX', self.querier), mailbox.listeners) - - def test_reindex_missing_idents(self): - search_engine = mock() - when(search_engine).search('tag:inbox').thenReturn(['ident1', 'ident2']) - - MailboxListener.SEARCH_ENGINE = search_engine - - listener = MailboxListener('INBOX', self.querier) - when(self.querier).idents_by_mailbox('INBOX').thenReturn({'ident1', 'ident2', 'missing_ident'}) - self.querier.used_arguments = [] - self.querier.mails = lambda x: self.querier.used_arguments.append(x) - listener.newMessages(10, 5) - - verify(self.querier, times=1).idents_by_mailbox('INBOX') - self.assertIn({'missing_ident'}, self.querier.used_arguments) diff --git a/service/test/unit/adapter/mail_sender_test.py b/service/test/unit/adapter/mail_sender_test.py new file mode 100644 index 00000000..721d61b7 --- /dev/null +++ b/service/test/unit/adapter/mail_sender_test.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.mail import PixelatedMail +from pixelated.adapter.mail_sender import MailSender +from mockito import * +from test.support import test_helper + + +class MailSenderTest(unittest.TestCase): + def setUp(self): + self.mail_address = "pixelated@pixelated.org" + self.smtp_client = mock() + self.mail_sender = MailSender(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/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py new file mode 100644 index 00000000..20038e96 --- /dev/null +++ b/service/test/unit/adapter/mail_test.py @@ -0,0 +1,118 @@ +# +# 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 pixelated.support.date +from pixelated.adapter.mail import PixelatedMail, InputMail +from mockito import * +from test.support import test_helper + + +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'], []) + + +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): + InputMail.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/unit/adapter/mailbox_indexer_listener_test.py b/service/test/unit/adapter/mailbox_indexer_listener_test.py new file mode 100644 index 00000000..1f28ec7b --- /dev/null +++ b/service/test/unit/adapter/mailbox_indexer_listener_test.py @@ -0,0 +1,54 @@ +# +# 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 mockito import * +from pixelated.adapter.mailbox_indexer_listener import MailboxIndexerListener + + +class MailboxListenerTest(unittest.TestCase): + def setUp(self): + self.querier = mock() + self.account = mock() + self.account.mailboxes = [] + + def test_add_itself_to_mailbox_listeners(self): + self.account.mailboxes = ['INBOX'] + mailbox = mock() + when(self.account).getMailbox('INBOX').thenReturn(mailbox) + mailbox.listeners = set() + when(mailbox).addListener = lambda x: mailbox.listeners.add(x) + + self.assertNotIn(MailboxIndexerListener('INBOX', self.querier), mailbox.listeners) + + MailboxIndexerListener.listen(self.account, 'INBOX', self.querier) + + self.assertIn(MailboxIndexerListener('INBOX', self.querier), mailbox.listeners) + + def test_reindex_missing_idents(self): + search_engine = mock() + when(search_engine).search('tag:inbox').thenReturn(['ident1', 'ident2']) + + MailboxIndexerListener.SEARCH_ENGINE = search_engine + + listener = MailboxIndexerListener('INBOX', self.querier) + when(self.querier).idents_by_mailbox('INBOX').thenReturn({'ident1', 'ident2', 'missing_ident'}) + self.querier.used_arguments = [] + self.querier.mails = lambda x: self.querier.used_arguments.append(x) + listener.newMessages(10, 5) + + verify(self.querier, times=1).idents_by_mailbox('INBOX') + self.assertIn({'missing_ident'}, self.querier.used_arguments) diff --git a/service/test/unit/adapter/mailbox_test.py b/service/test/unit/adapter/mailbox_test.py new file mode 100644 index 00000000..df46d02d --- /dev/null +++ b/service/test/unit/adapter/mailbox_test.py @@ -0,0 +1,36 @@ +# +# 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 import PixelatedMail +from pixelated.adapter.mailbox import Mailbox +from mockito import * +from test.support import test_helper + + +class PixelatedMailboxTest(unittest.TestCase): + def setUp(self): + self.tag_service = mock() + self.querier = mock() + self.mailbox = Mailbox('INBOX', self.querier) + + 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/unit/adapter/mailboxes_test.py b/service/test/unit/adapter/mailboxes_test.py new file mode 100644 index 00000000..cbed4577 --- /dev/null +++ b/service/test/unit/adapter/mailboxes_test.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 mockito import * +from pixelated.adapter.mailbox import Mailbox +from pixelated.adapter.mailboxes import Mailboxes + + +class PixelatedMailboxesTest(unittest.TestCase): + def setUp(self): + + self.querier = mock() + self.account = mock() + self.account.mailboxes = [] + self.drafts_mailbox = mock() + self.drafts_mailbox.mailbox_name = 'drafts' + self.mailboxes = Mailboxes(self.account, self.querier) + self.mailboxes.drafts = lambda: self.drafts_mailbox + + def test_search_for_tags(self): + mailbox = mock() + self.mailboxes.mailboxes = lambda: [mailbox] + + tags_to_search_for = {'tags': ['inbox', 'custom_tag']} + + when(Mailbox).create('INBOX', self.querier).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]) diff --git a/service/test/unit/adapter/pixelated_mail_sender_test.py b/service/test/unit/adapter/pixelated_mail_sender_test.py deleted file mode 100644 index 01de1cb0..00000000 --- a/service/test/unit/adapter/pixelated_mail_sender_test.py +++ /dev/null @@ -1,46 +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 import PixelatedMail -from pixelated.adapter.pixelated_mail_sender import PixelatedMailSender -from mockito import * -from test.support 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/unit/adapter/pixelated_mail_test.py b/service/test/unit/adapter/pixelated_mail_test.py deleted file mode 100644 index 20038e96..00000000 --- a/service/test/unit/adapter/pixelated_mail_test.py +++ /dev/null @@ -1,118 +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 pixelated.support.date -from pixelated.adapter.mail import PixelatedMail, InputMail -from mockito import * -from test.support import test_helper - - -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'], []) - - -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): - InputMail.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/unit/adapter/pixelated_mailbox_test.py b/service/test/unit/adapter/pixelated_mailbox_test.py deleted file mode 100644 index 0a007ba6..00000000 --- a/service/test/unit/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.mail import PixelatedMail -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from mockito import * -from test.support import test_helper - - -class PixelatedMailboxTest(unittest.TestCase): - def setUp(self): - self.tag_service = mock() - self.querier = mock() - self.mailbox = PixelatedMailbox('INBOX', self.querier) - - 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/unit/adapter/pixelated_mailboxes_test.py b/service/test/unit/adapter/pixelated_mailboxes_test.py deleted file mode 100644 index 3ca8cc2f..00000000 --- a/service/test/unit/adapter/pixelated_mailboxes_test.py +++ /dev/null @@ -1,46 +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 mockito import * -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes - - -class PixelatedMailboxesTest(unittest.TestCase): - def setUp(self): - - self.querier = mock() - self.account = mock() - self.account.mailboxes = [] - self.drafts_mailbox = mock() - self.drafts_mailbox.mailbox_name = 'drafts' - self.mailboxes = PixelatedMailBoxes(self.account, self.querier) - self.mailboxes.drafts = lambda: self.drafts_mailbox - - def test_search_for_tags(self): - mailbox = mock() - self.mailboxes.mailboxes = lambda: [mailbox] - - tags_to_search_for = {'tags': ['inbox', 'custom_tag']} - - when(PixelatedMailbox).create('INBOX', self.querier).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]) diff --git a/service/test/unit/runserver_test.py b/service/test/unit/runserver_test.py new file mode 100644 index 00000000..1e735bf7 --- /dev/null +++ b/service/test/unit/runserver_test.py @@ -0,0 +1,59 @@ +# +# 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 sys + +import pixelated.runserver +from mockito import * +import crochet +import pixelated.config.reactor_manager as reactor_manager +import pixelated.adapter.mail +import os +import pixelated.config.app_factory as app_factory + + +class RunserverTest(unittest.TestCase): + + def test_that_default_config_file_is_home_dot_pixelated(self): + orig_config = pixelated.runserver.app.config + try: + when(crochet).setup().thenReturn(None) + when(reactor_manager).start_reactor().thenReturn(None) + when(app_factory).create_app().thenReturn(None) + pixelated.runserver.app.config = mock() + + sys.argv = ['/tmp/does_not_exist'] + pixelated.runserver.setup() + + verify(pixelated.runserver.app.config).from_pyfile(os.path.join(os.environ['HOME'], '.pixelated')) + finally: + pixelated.runserver.app.config = orig_config + + def test_that_config_file_can_be_specified_on_command_line(self): + orig_config = pixelated.runserver.app.config + try: + when(crochet).setup().thenReturn(None) + when(reactor_manager).start_reactor().thenReturn(None) + when(app_factory).create_app().thenReturn(None) + pixelated.runserver.app.config = mock() + + sys.argv = ['/tmp/does_not_exist', '--config', '/tmp/some/config/file'] + pixelated.runserver.setup() + + verify(pixelated.runserver.app.config).from_pyfile('/tmp/some/config/file') + finally: + pixelated.runserver.app.config = orig_config diff --git a/service/test/unit/user_agent_test.py b/service/test/unit/user_agent_test.py deleted file mode 100644 index bd875dcc..00000000 --- a/service/test/unit/user_agent_test.py +++ /dev/null @@ -1,58 +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 sys - -import pixelated.user_agent -from mockito import * -import crochet -import pixelated.config.reactor_manager as reactor_manager -import pixelated.adapter.pixelated_mail -import os - - -class UserAgentTest(unittest.TestCase): - - def test_that_default_config_file_is_home_dot_pixelated(self): - orig_config = pixelated.user_agent.app.config - try: - when(crochet).setup().thenReturn(None) - when(reactor_manager).start_reactor().thenReturn(None) - when(pixelated.user_agent).start_user_agent().thenReturn(None) - pixelated.user_agent.app.config = mock() - - sys.argv = ['/tmp/does_not_exist'] - pixelated.user_agent.setup() - - verify(pixelated.user_agent.app.config).from_pyfile(os.path.join(os.environ['HOME'], '.pixelated')) - finally: - pixelated.user_agent.app.config = orig_config - - def test_that_config_file_can_be_specified_on_command_line(self): - orig_config = pixelated.user_agent.app.config - try: - when(crochet).setup().thenReturn(None) - when(reactor_manager).start_reactor().thenReturn(None) - when(pixelated.user_agent).start_user_agent().thenReturn(None) - pixelated.user_agent.app.config = mock() - - sys.argv = ['/tmp/does_not_exist', '--config', '/tmp/some/config/file'] - pixelated.user_agent.setup() - - verify(pixelated.user_agent.app.config).from_pyfile('/tmp/some/config/file') - finally: - pixelated.user_agent.app.config = orig_config -- cgit v1.2.3