summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/integration/__init__.py60
-rw-r--r--service/integration/mail_fetch_test.py40
2 files changed, 63 insertions, 37 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
diff --git a/service/integration/mail_fetch_test.py b/service/integration/mail_fetch_test.py
index 0b66fe1d..882e9d6f 100644
--- a/service/integration/mail_fetch_test.py
+++ b/service/integration/mail_fetch_test.py
@@ -1,47 +1,15 @@
import unittest
-from flask import json
-from mockito import mock
-from pixelated.adapter.mail_service import MailService
-from pixelated.adapter.pixelated_mail import PixelatedMail
-from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes
-from pixelated.adapter.soledad_querier import SoledadQuerier
-import pixelated.user_agent
-from integration import JSONMailBuilder, initialize_soledad
+from integration import JSONMailBuilder, SoledadTestBase
-class FakeAccount(object):
- def __init__(self):
- self.mailboxes = ['INBOX', 'DRAFTS', 'SENT', 'TRASH']
-
-
-class MailFetchTest(unittest.TestCase):
+class MailFetchTest(unittest.TestCase, SoledadTestBase):
def setUp(self):
- self.soledad_test_folder = "soledad-test"
- 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=self.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)
- pixelated.user_agent.DISABLED_FEATURES = []
+ self.setup_soledad()
def tearDown(self):
- self.soledad.close()
- import shutil
- shutil.rmtree(self.soledad_test_folder)
-
- 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")
+ self.teardown_soledad()
def test_get_mails(self):
mail_one = JSONMailBuilder().with_subject("Mail One").build()