diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-09-29 16:19:55 -0300 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-09-29 16:19:55 -0300 |
commit | 99d540becb364a46553e0b3e8a6a8933947bd699 (patch) | |
tree | a50b181133f1e436668a938bdf8ebee813b922be /service/integration/__init__.py | |
parent | 4947c0692e7c082a975194bb795a1190cc647fbf (diff) |
moving base soledad test setup to its own class
Diffstat (limited to 'service/integration/__init__.py')
-rw-r--r-- | service/integration/__init__.py | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/service/integration/__init__.py b/service/integration/__init__.py index 88357662..717fa3e9 100644 --- a/service/integration/__init__.py +++ b/service/integration/__init__.py @@ -1,8 +1,37 @@ +# +# 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 json from leap.soledad.client import Soledad +from mockito import mock import os from mock import Mock +import shutil +from pixelated.adapter.mail_service import MailService +import pixelated.user_agent +from pixelated.adapter.pixelated_mail import PixelatedMail +from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes +from pixelated.adapter.soledad_querier import SoledadQuerier + +soledad_test_folder = "soledad-test" + + +class FakeAccount: + def __init__(self): + self.mailboxes = ['INBOX', 'DRAFTS', 'SENT', 'TRASH'] def initialize_soledad(tempdir): @@ -61,4 +90,33 @@ class JSONMailBuilder: return self def build(self): - return json.dumps(self.mail)
\ No newline at end of file + return json.dumps(self.mail) + + +class SoledadTestBase: + + def __init__(self): + pass + + def teardown_soledad(self): + self.soledad.close() + shutil.rmtree(soledad_test_folder) + + def setup_soledad(self): + self.app = pixelated.user_agent.app.test_client() + self.account = FakeAccount() + self.mail_sender = mock() + self.mail_address = "test@pixelated.org" + self.soledad = initialize_soledad(tempdir=soledad_test_folder) + + SoledadQuerier.instance = None + SoledadQuerier.get_instance(soledad=self.soledad) + PixelatedMail.from_email_address = self.mail_address + pixelated_mailboxes = PixelatedMailBoxes(self.account) + pixelated.user_agent.mail_service = MailService(pixelated_mailboxes, self.mail_sender) + + def get_mails_by_tag(self, tag): + return json.loads(self.app.get("/mails?q=tag" + tag).data) + + def post_mail(self, data): + self.app.post('/mails', data=data, content_type="application/json")
\ No newline at end of file |