summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mail.py2
-rw-r--r--service/test/integration/mark_as_read_unread_test.py32
-rw-r--r--service/test/support/integration_helper.py2
3 files changed, 30 insertions, 6 deletions
diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py
index ca29687e..1d2080fa 100644
--- a/service/pixelated/adapter/mail.py
+++ b/service/pixelated/adapter/mail.py
@@ -250,7 +250,7 @@ class PixelatedMail(Mail):
def mark_as_read(self):
if Status.SEEN in self.fdoc.content['flags']:
- return
+ return self
self.fdoc.content['flags'].append(Status.SEEN)
self.save()
return self
diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py
index 3f83153d..3bf56dd5 100644
--- a/service/test/integration/mark_as_read_unread_test.py
+++ b/service/test/integration/mark_as_read_unread_test.py
@@ -16,6 +16,7 @@
import unittest
from test.support.integration_helper import MailBuilder, SoledadTestBase
+from pixelated.adapter.status import Status
class MarkAsReadUnreadTest(unittest.TestCase, SoledadTestBase):
@@ -39,7 +40,7 @@ class MarkAsReadUnreadTest(unittest.TestCase, SoledadTestBase):
self.assertIn('read', mails[0].status)
def test_mark_single_as_unread(self):
- input_mail = MailBuilder().with_status('read').build_input_mail()
+ input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail()
self.add_mail_to_inbox(input_mail)
@@ -49,8 +50,8 @@ class MarkAsReadUnreadTest(unittest.TestCase, SoledadTestBase):
self.assertNotIn('read', mails[0].status)
def test_mark_many_mails_as_unread(self):
- input_mail = MailBuilder().with_status('read').build_input_mail()
- input_mail2 = MailBuilder().with_status('read').build_input_mail()
+ input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail()
+ input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail()
self.add_mail_to_inbox(input_mail)
self.add_mail_to_inbox(input_mail2)
@@ -74,7 +75,30 @@ class MarkAsReadUnreadTest(unittest.TestCase, SoledadTestBase):
self.assertNotIn('read', mails[0].status)
self.assertNotIn('read', mails[1].status)
- self.mark_many_as_read([input_mail.ident, input_mail2.ident])
+ response = self.mark_many_as_read([input_mail.ident, input_mail2.ident])
+ self.assertEquals(200, response.status_code)
+
+ mails = self.get_mails_by_tag('inbox')
+
+ self.assertIn('read', mails[0].status)
+ self.assertIn('read', mails[1].status)
+
+ def test_mark_mixed_status_as_read(self):
+ input_mail = MailBuilder().build_input_mail()
+ input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail()
+
+ self.add_mail_to_inbox(input_mail)
+ self.add_mail_to_inbox(input_mail2)
+
+ mails = self.get_mails_by_tag('inbox')
+
+ read_mails = filter(lambda x: 'read' in x.status, mails)
+ unread_mails = filter(lambda x: 'read' not in x.status, mails)
+ self.assertEquals(1, len(unread_mails))
+ self.assertEquals(1, len(read_mails))
+
+ response = self.mark_many_as_read([input_mail.ident, input_mail2.ident])
+ self.assertEquals(200, response.status_code)
mails = self.get_mails_by_tag('inbox')
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index f6b4249e..3667001f 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -212,7 +212,7 @@ class SoledadTestBase:
self.client.post('/mails/unread', data={'idents': json.dumps(idents)})
def mark_many_as_read(self, idents):
- self.client.post('/mails/read', data={'idents': json.dumps(idents)})
+ return self.client.post('/mails/read', data={'idents': json.dumps(idents)})
def add_mail_to_inbox(self, input_mail):
mail = self.mailboxes.inbox().add(input_mail)