summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisa Junger <ljunger@thoughtworks.com>2014-10-14 14:29:36 +0200
committerLisa Junger <ljunger@thoughtworks.com>2014-10-14 14:33:45 +0200
commit23503fcdf83fe1437bcd164c79d75cf56c08bade (patch)
tree8b01995d7ba8b23d876139f5780b00931fdbde9e
parent9446c8df4627b8f5955def0fd86c9bf1924255fe (diff)
Issue #12 - Bulk mark as unread
-rw-r--r--service/pixelated/adapter/pixelated_mail.py5
-rw-r--r--service/test/integration/mark_as_read_unread_test.py20
-rw-r--r--service/test/support/integration_helper.py3
3 files changed, 22 insertions, 6 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py
index fabb1ab4..8b07e996 100644
--- a/service/pixelated/adapter/pixelated_mail.py
+++ b/service/pixelated/adapter/pixelated_mail.py
@@ -262,8 +262,9 @@ class PixelatedMail:
return self
def mark_as_unread(self):
- self.fdoc.content['flags'].remove(Status.PixelatedStatus.SEEN)
- self.save()
+ if Status.PixelatedStatus.SEEN in self.fdoc.content['flags']:
+ self.fdoc.content['flags'].remove(Status.PixelatedStatus.SEEN)
+ self.save()
return self
def mark_as_not_recent(self):
diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py
index a75e8c92..cdac78d5 100644
--- a/service/test/integration/mark_as_read_unread_test.py
+++ b/service/test/integration/mark_as_read_unread_test.py
@@ -30,21 +30,33 @@ class MarkAsReadTest(unittest.TestCase, SoledadTestBase):
self.add_mail_to_inbox(input_mail)
mails = self.get_mails_by_tag('inbox')
- self.assertFalse('read' in mails[0].status)
+ self.assertNotIn('read', mails[0].status)
self.mark_as_read(input_mail.ident)
mails = self.get_mails_by_tag('inbox')
- self.assertTrue('read' in mails[0].status)
+ self.assertIn('read', 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)
+ self.mark_as_unread(input_mail.ident)
+
mails = self.get_mails_by_tag('inbox')
- self.assertIn('read', mails[0].status)
+ self.assertNotIn('read', mails[0].status)
- self.mark_as_unread(input_mail.ident)
+ 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()
+
+ self.add_mail_to_inbox(input_mail)
+ self.add_mail_to_inbox(input_mail2)
+
+ self.mark_many_as_unread([input_mail.ident, input_mail2.ident])
mails = self.get_mails_by_tag('inbox')
+
self.assertNotIn('read', mails[0].status)
+ self.assertNotIn('read', mails[1].status)
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index c2f84157..8f42e335 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -186,6 +186,9 @@ class SoledadTestBase:
def mark_as_unread(self, mail_ident):
self.app.post('/mail/' + mail_ident + '/unread', content_type="application/json")
+ def mark_many_as_unread(self, idents):
+ self.app.post('/mails/unread', data={'idents': json.dumps(idents)})
+
def add_mail_to_inbox(self, input_mail):
mail = self.pixelated_mailboxes.inbox().add(input_mail)
self.search_engine.index_mail(mail)