Ejemplo n.º 1
0
    def test_flag_setting(self):
        user = factories.UserFactory()
        inbox = factories.InboxFactory(user=user)

        with mock.patch(
                "inboxen.router.app.server.make_email") as mock_make_email:
            process_message(None, inbox.inbox, inbox.domain.domain)
        self.assertTrue(mock_make_email.called)

        user = get_user_model().objects.get(id=user.id)
        profile = user.inboxenprofile
        inbox = models.Inbox.objects.get(id=inbox.id)

        self.assertTrue(inbox.new)
        self.assertTrue(profile.unified_has_new_messages)

        # reset some bools
        inbox.new = False
        inbox.exclude_from_unified = True
        inbox.save(update_fields=["new", "exclude_from_unified"])
        profile.unified_has_new_messages = False
        profile.save(update_fields=["unified_has_new_messages"])

        with mock.patch(
                "inboxen.router.app.server.make_email") as mock_make_email:
            process_message(None, inbox.inbox, inbox.domain.domain)
        self.assertTrue(mock_make_email.called)

        user = get_user_model().objects.get(id=user.id)
        profile = user.inboxenprofile
        inbox = models.Inbox.objects.get(id=inbox.id)

        self.assertTrue(inbox.new)
        self.assertFalse(profile.unified_has_new_messages)
Ejemplo n.º 2
0
    def test_flag_setting(self):
        user = factories.UserFactory()
        inbox = factories.InboxFactory(user=user)

        with mock.patch("inboxen.router.app.server.make_email") as mock_make_email:
            process_message(None, inbox.inbox, inbox.domain.domain)
        self.assertTrue(mock_make_email.called)

        user = get_user_model().objects.get(id=user.id)
        profile = user.inboxenprofile
        inbox = models.Inbox.objects.get(id=inbox.id)

        self.assertTrue(inbox.new)
        self.assertTrue(profile.unified_has_new_messages)

        # reset some bools
        inbox.new = False
        inbox.exclude_from_unified = True
        inbox.save(update_fields=["new", "exclude_from_unified"])
        profile.unified_has_new_messages = False
        profile.save(update_fields=["unified_has_new_messages"])

        with mock.patch("inboxen.router.app.server.make_email") as mock_make_email:
            process_message(None, inbox.inbox, inbox.domain.domain)
        self.assertTrue(mock_make_email.called)

        user = get_user_model().objects.get(id=user.id)
        profile = user.inboxenprofile
        inbox = models.Inbox.objects.get(id=inbox.id)

        self.assertTrue(inbox.new)
        self.assertFalse(profile.unified_has_new_messages)
Ejemplo n.º 3
0
    def test_exceptions(self):
        with self.assertRaises(SMTPError) as error:
            process_message(None, None, None)
        self.assertEqual(error.exception.code, 550)

        with self.assertRaises(SMTPError) as error, \
                mock.patch.object(models.Inbox.objects, "filter", side_effect=DatabaseError):
            process_message(None, None, None)
        self.assertEqual(error.exception.code, 451)
Ejemplo n.º 4
0
    def test_exceptions(self):
        with self.assertRaises(SMTPError) as error:
            process_message(None, None, None)
        self.assertEqual(error.exception.code, 550)

        with self.assertRaises(SMTPError) as error, \
                mock.patch.object(models.Inbox.objects, "filter", side_effect=DatabaseError):
            process_message(None, None, None)
        self.assertEqual(error.exception.code, 451)