diff options
-rw-r--r-- | service/pixelated/config/app_factory.py | 1 | ||||
-rw-r--r-- | service/pixelated/controllers/mails_controller.py | 7 | ||||
-rw-r--r-- | service/test/integration/mark_as_read_unread_test.py | 19 | ||||
-rw-r--r-- | service/test/support/integration_helper.py | 3 |
4 files changed, 30 insertions, 0 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py index 6c9c07fe..ed752118 100644 --- a/service/pixelated/config/app_factory.py +++ b/service/pixelated/config/app_factory.py @@ -36,6 +36,7 @@ def _setup_routes(app, home_controller, mails_controller, tags_controller, featu app.add_url_rule('/mail/<mail_id>/read', methods=['POST'], view_func=mails_controller.mark_mail_as_read) app.add_url_rule('/mail/<mail_id>/unread', methods=['POST'], view_func=mails_controller.mark_mail_as_unread) app.add_url_rule('/mails/unread', methods=['POST'], view_func=mails_controller.mark_many_mail_unread) + app.add_url_rule('/mails/read', methods=['POST'], view_func=mails_controller.mark_many_mail_read) app.add_url_rule('/mail/<mail_id>', methods=['GET'], view_func=mails_controller.mail) app.add_url_rule('/mail/<mail_id>', methods=['DELETE'], view_func=mails_controller.delete_mail) app.add_url_rule('/mails', methods=['DELETE'], view_func=mails_controller.delete_mails) diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py index b850d24d..ba8cbba1 100644 --- a/service/pixelated/controllers/mails_controller.py +++ b/service/pixelated/controllers/mails_controller.py @@ -65,6 +65,13 @@ class MailsController: self._search_engine.index_mail(mail) return "" + def mark_many_mail_read(self): + idents = json.loads(request.form['idents']) + for ident in idents: + mail = self._mail_service.mark_as_read(ident) + self._search_engine.index_mail(mail) + return "" + def delete_mail(self, mail_id): trashed_mail = self._mail_service.delete_mail(mail_id) self._search_engine.index_mail(trashed_mail) diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py index 94c23565..3f83153d 100644 --- a/service/test/integration/mark_as_read_unread_test.py +++ b/service/test/integration/mark_as_read_unread_test.py @@ -61,3 +61,22 @@ class MarkAsReadUnreadTest(unittest.TestCase, SoledadTestBase): self.assertNotIn('read', mails[0].status) self.assertNotIn('read', mails[1].status) + + def test_mark_many_mails_as_read(self): + input_mail = MailBuilder().build_input_mail() + input_mail2 = MailBuilder().build_input_mail() + + self.add_mail_to_inbox(input_mail) + self.add_mail_to_inbox(input_mail2) + + mails = self.get_mails_by_tag('inbox') + + self.assertNotIn('read', mails[0].status) + self.assertNotIn('read', mails[1].status) + + self.mark_many_as_read([input_mail.ident, input_mail2.ident]) + + mails = self.get_mails_by_tag('inbox') + + self.assertIn('read', mails[0].status) + self.assertIn('read', mails[1].status) diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py index 47bc8f11..f6b4249e 100644 --- a/service/test/support/integration_helper.py +++ b/service/test/support/integration_helper.py @@ -211,6 +211,9 @@ class SoledadTestBase: def mark_many_as_unread(self, idents): 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)}) + def add_mail_to_inbox(self, input_mail): mail = self.mailboxes.inbox().add(input_mail) mail.update_tags(input_mail.tags) |