summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2014-09-29 18:43:16 -0300
committerDuda Dornelles <ddornell@thoughtworks.com>2014-09-29 18:43:16 -0300
commite34fc64a13eae3eef4333bc6f4e993fa1891eb81 (patch)
tree553c38cb4cc280ac1183732cfc032c0117a97d0c /service
parente29d92b6fbf651d967271820e5f4bcde6ba47d39 (diff)
adding integration test to add tag
Diffstat (limited to 'service')
-rw-r--r--service/integration/__init__.py19
-rw-r--r--service/integration/drafts_test.py12
-rw-r--r--service/integration/tags_test.py43
-rw-r--r--service/pixelated/adapter/pixelated_mailboxes.py3
4 files changed, 67 insertions, 10 deletions
diff --git a/service/integration/__init__.py b/service/integration/__init__.py
index 22643b95..c4e1d0b4 100644
--- a/service/integration/__init__.py
+++ b/service/integration/__init__.py
@@ -24,7 +24,7 @@ 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_mail import PixelatedMail, InputMail
from pixelated.adapter.pixelated_mailboxes import PixelatedMailBoxes
from pixelated.adapter.soledad_querier import SoledadQuerier
@@ -71,7 +71,7 @@ def initialize_soledad(tempdir):
return _soledad
-class JSONMailBuilder:
+class MailBuilder:
def __init__(self):
self.mail = {
'header': {
@@ -95,9 +95,13 @@ class JSONMailBuilder:
self.mail['ident'] = ident
return self
- def build(self):
+ def build_json(self):
return json.dumps(self.mail)
+ def build_input_mail(self):
+ return InputMail.from_dict(self.mail)
+
+
class SoledadTestBase:
@@ -135,6 +139,9 @@ class SoledadTestBase:
response = json.loads(self.app.put('/mails', data=data, content_type="application/json").data)
return response['ident']
+ def post_tags(self, mail_ident, tags_json):
+ return json.loads(self.app.post('/mail/' + mail_ident + '/tags', data=tags_json, content_type="application/json").data)
+
class ResponseMail:
@@ -151,4 +158,8 @@ class ResponseMail:
@property
def ident(self):
- return self.mail_dict['ident'] \ No newline at end of file
+ return self.mail_dict['ident']
+
+ @property
+ def tags(self):
+ return self.mail_dict['tags'] \ No newline at end of file
diff --git a/service/integration/drafts_test.py b/service/integration/drafts_test.py
index a3ecbb2a..749b1ad3 100644
--- a/service/integration/drafts_test.py
+++ b/service/integration/drafts_test.py
@@ -14,7 +14,7 @@
# 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
+from integration import MailBuilder, SoledadTestBase
class DraftsTest(unittest.TestCase, SoledadTestBase):
@@ -26,7 +26,7 @@ class DraftsTest(unittest.TestCase, SoledadTestBase):
self.teardown_soledad()
def test_post_creates_a_draft_when_data_has_no_ident(self):
- mail = JSONMailBuilder().with_subject('A new draft').build()
+ mail = MailBuilder().with_subject('A new draft').build_json()
self.post_mail(mail)
mails = self.get_mails_by_tag('drafts')
@@ -34,11 +34,11 @@ class DraftsTest(unittest.TestCase, SoledadTestBase):
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 = MailBuilder().with_subject('First draft').build_json()
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()
+ second_draft = MailBuilder().with_subject('Second draft').with_ident(first_draft_ident).build_json()
self.post_mail(second_draft)
sent_mails = self.get_mails_by_tag('sent')
@@ -49,11 +49,11 @@ class DraftsTest(unittest.TestCase, SoledadTestBase):
self.assertEquals(0, len(drafts))
def test_update_draft(self):
- draft = JSONMailBuilder().with_subject('First draft').build()
+ draft = MailBuilder().with_subject('First draft').build_json()
create_draft_response = self.post_mail(draft)
draft_ident = create_draft_response.ident
- updated_draft = JSONMailBuilder().with_subject('First draft edited').with_ident(draft_ident).build()
+ updated_draft = MailBuilder().with_subject('First draft edited').with_ident(draft_ident).build_json()
self.put_mail(updated_draft)
drafts = self.get_mails_by_tag('drafts')
diff --git a/service/integration/tags_test.py b/service/integration/tags_test.py
new file mode 100644
index 00000000..8971fac7
--- /dev/null
+++ b/service/integration/tags_test.py
@@ -0,0 +1,43 @@
+#
+# 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
+import unittest
+from integration import MailBuilder, SoledadTestBase
+
+
+class TagsTest(unittest.TestCase, SoledadTestBase):
+
+ def setUp(self):
+ self.setup_soledad()
+
+ def tearDown(self):
+ self.teardown_soledad()
+
+ def _tags_json(self, tags):
+ return json.dumps({'newtags': tags})
+
+ def test_add_tag_to_an_inbox_mail_and_query(self):
+ mail = MailBuilder().with_subject('Mail with tags').build_input_mail()
+ self.pixelated_mailboxes.inbox().add(mail)
+ self.post_tags(mail.ident, self._tags_json(['INBOX', 'IMPORTANT']))
+
+ mails = self.get_mails_by_tag('inbox')
+ self.assertEquals({'inbox', 'important'}, set(mails[0].tags))
+
+ mails = self.get_mails_by_tag('important')
+ self.assertEquals('Mail with tags', mails[0].subject)
+
+
diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py
index acfdf8fd..ff1aa421 100644
--- a/service/pixelated/adapter/pixelated_mailboxes.py
+++ b/service/pixelated/adapter/pixelated_mailboxes.py
@@ -27,6 +27,9 @@ class PixelatedMailBoxes():
self.account.addMailbox(mailbox_name)
return PixelatedMailbox.create(mailbox_name)
+ def inbox(self):
+ return self._create_or_get('INBOX')
+
def drafts(self):
return self._create_or_get('DRAFTS')