summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
Diffstat (limited to 'service/test')
-rw-r--r--service/test/integration/mark_as_read_unread_test.py50
-rw-r--r--service/test/support/integration_helper.py11
2 files changed, 60 insertions, 1 deletions
diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py
new file mode 100644
index 00000000..a75e8c92
--- /dev/null
+++ b/service/test/integration/mark_as_read_unread_test.py
@@ -0,0 +1,50 @@
+#
+# 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 test.support.integration_helper import MailBuilder, SoledadTestBase
+
+
+class MarkAsReadTest(unittest.TestCase, SoledadTestBase):
+
+ def setUp(self):
+ self.setup_soledad()
+
+ def tearDown(self):
+ self.teardown_soledad()
+
+ def test_mark_single_as_read(self):
+ input_mail = MailBuilder().build_input_mail()
+ self.add_mail_to_inbox(input_mail)
+
+ mails = self.get_mails_by_tag('inbox')
+ self.assertFalse('read' in mails[0].status)
+
+ self.mark_as_read(input_mail.ident)
+
+ mails = self.get_mails_by_tag('inbox')
+ self.assertTrue('read' in mails[0].status)
+
+ def test_mark_single_as_unread(self):
+ input_mail = MailBuilder().with_status('read').build_input_mail()
+ self.add_mail_to_inbox(input_mail)
+
+ mails = self.get_mails_by_tag('inbox')
+ self.assertIn('read', mails[0].status)
+
+ self.mark_as_unread(input_mail.ident)
+
+ mails = self.get_mails_by_tag('inbox')
+ self.assertNotIn('read', mails[0].status)
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index c9a80624..5975b9e8 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -22,6 +22,7 @@ from mock import Mock
import shutil
from pixelated.adapter.mail_service import MailService
from pixelated.adapter.search import SearchEngine
+from pixelated.adapter.status import Status
from pixelated.adapter.tag_index import TagIndex
from pixelated.adapter.tag_service import TagService
from pixelated.adapter.draft_service import DraftService
@@ -82,7 +83,8 @@ class MailBuilder:
'bcc': ['recipient@bcc.com'],
'subject': 'Hi! This the subject'
},
- 'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n"
+ 'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n",
+ 'status': []
}
def with_body(self, body):
@@ -93,6 +95,10 @@ class MailBuilder:
self.mail['header']['subject'] = subject
return self
+ def with_status(self, status):
+ self.mail['status'].append(Status('read'))
+ return self
+
def with_ident(self, ident):
self.mail['ident'] = ident
return self
@@ -166,6 +172,9 @@ class SoledadTestBase:
def mark_as_read(self, mail_ident):
self.app.post('/mail/' + mail_ident + '/read', content_type="application/json")
+ def mark_as_unread(self, mail_ident):
+ self.app.post('/mail/' + mail_ident + '/unread', content_type="application/json")
+
def add_mail_to_inbox(self, input_mail):
mail = self.pixelated_mailboxes.inbox().add(input_mail)
self.search_engine.index_mail(mail)