summaryrefslogtreecommitdiff
path: root/service/integration
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-29 18:00:52 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-29 18:00:52 -0300
commit7fa4661018272edaf11109efdb9ff834d365f3ab (patch)
tree158f090a915d99c6314b412035a42c1d810f6d29 /service/integration
parent99d540becb364a46553e0b3e8a6a8933947bd699 (diff)
Testing drafts in integration, fixing a bug where the sent wasnt leaving the drafts mailbox
Diffstat (limited to 'service/integration')
-rw-r--r--service/integration/__init__.py50
-rw-r--r--service/integration/drafts_test.py53
-rw-r--r--service/integration/mail_fetch_test.py25
3 files changed, 92 insertions, 36 deletions
diff --git a/service/integration/__init__.py b/service/integration/__init__.py
index 717fa3e9..aff5cec0 100644
--- a/service/integration/__init__.py
+++ b/service/integration/__init__.py
@@ -21,6 +21,8 @@ import os
from mock import Mock
import shutil
from pixelated.adapter.mail_service import MailService
+from pixelated.adapter.tag_index import TagIndex
+from pixelated.adapter.tag_service import TagService
import pixelated.user_agent
from pixelated.adapter.pixelated_mail import PixelatedMail
from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes
@@ -89,34 +91,60 @@ class JSONMailBuilder:
self.mail['header']['subject'] = subject
return self
+ def with_ident(self, ident):
+ self.mail['ident'] = ident
+ return self
+
def build(self):
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)
+ self.mail_address = "test@pixelated.org"
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)
+
+ self.app = pixelated.user_agent.app.test_client()
+ self.account = FakeAccount()
+ self.mail_sender = mock()
+ self.tag_index = TagIndex(os.path.join(soledad_test_folder, 'tag_index'))
+ self.tag_service = TagService(self.tag_index)
+ self.pixelated_mailboxes = PixelatedMailBoxes(self.account)
+ self.mail_service = MailService(self.pixelated_mailboxes, self.mail_sender, self.tag_service)
+
+ pixelated.user_agent.mail_service = self.mail_service
def get_mails_by_tag(self, tag):
- return json.loads(self.app.get("/mails?q=tag" + tag).data)
+ response = json.loads(self.app.get("/mails?q=tag:" + tag).data)
+ return [ResponseMail(m) for m in response['mails']]
def post_mail(self, data):
- self.app.post('/mails', data=data, content_type="application/json") \ No newline at end of file
+ response = json.loads(self.app.post('/mails', data=data, content_type="application/json").data)
+ return ResponseMail(response)
+
+
+class ResponseMail:
+
+ def __init__(self, mail_dict):
+ self.mail_dict = mail_dict
+
+ @property
+ def subject(self):
+ return self.headers['subject']
+
+ @property
+ def headers(self):
+ return self.mail_dict['header']
+
+ @property
+ def ident(self):
+ return self.mail_dict['ident'] \ No newline at end of file
diff --git a/service/integration/drafts_test.py b/service/integration/drafts_test.py
new file mode 100644
index 00000000..1f1712a8
--- /dev/null
+++ b/service/integration/drafts_test.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 <http://www.gnu.org/licenses/>.
+import unittest
+from integration import JSONMailBuilder, SoledadTestBase
+
+
+class DraftsTest(unittest.TestCase, SoledadTestBase):
+
+ def setUp(self):
+ self.setup_soledad()
+
+ def tearDown(self):
+ self.teardown_soledad()
+
+ def test_post_creates_a_draft_when_data_has_no_ident(self):
+ mail = JSONMailBuilder().with_subject('A new draft').build()
+
+ self.post_mail(mail)
+ mails = self.get_mails_by_tag('drafts')
+
+ self.assertEquals('A new draft', mails[0].subject)
+
+ def test_post_sends_mail_and_deletes_previous_draft_when_data_has_ident(self):
+ first_draft = JSONMailBuilder().with_subject('First draft').build()
+ first_draft_response = self.post_mail(first_draft)
+ first_draft_ident = first_draft_response.ident
+
+ second_draft = JSONMailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build()
+ self.post_mail(second_draft)
+
+ sent_mails = self.get_mails_by_tag('sent')
+ drafts = self.get_mails_by_tag('drafts')
+
+ import pdb;pdb.set_trace()
+
+ self.assertEquals(1, len(sent_mails))
+ self.assertEquals('Second draft', sent_mails[0].subject)
+ self.assertEquals(0, len(drafts))
+
+
diff --git a/service/integration/mail_fetch_test.py b/service/integration/mail_fetch_test.py
deleted file mode 100644
index 882e9d6f..00000000
--- a/service/integration/mail_fetch_test.py
+++ /dev/null
@@ -1,25 +0,0 @@
-import unittest
-
-from integration import JSONMailBuilder, SoledadTestBase
-
-
-class MailFetchTest(unittest.TestCase, SoledadTestBase):
-
- def setUp(self):
- self.setup_soledad()
-
- def tearDown(self):
- self.teardown_soledad()
-
- def test_get_mails(self):
- mail_one = JSONMailBuilder().with_subject("Mail One").build()
- mail_two = JSONMailBuilder().with_subject("Mail Two").build()
-
- self.post_mail(mail_one)
- self.post_mail(mail_two)
-
- response = self.get_mails_by_tag("drafts")
-
- # ordered by creation date
- self.assertEquals(u'Mail Two', response['mails'][0]['header']['subject'])
- self.assertEquals(u'Mail One', response['mails'][1]['header']['subject'])