Exemplo n.º 1
0
    def test_generates_and_sends_mail_for_any_notification(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(
            spec_set=[], return_value=mock.sentinel.notification
        )
        generate_mail = mock.Mock(spec_set=[])
        generate_mail.return_value = (
            ["*****@*****.**"],
            "Your email",
            "Text body",
            "HTML body",
        )
        event = AnnotationEvent(pyramid_request, None, None)

        subscribers.send_reply_notifications(
            event,
            get_notification=get_notification,
            generate_mail=generate_mail,
            send=send,
        )

        generate_mail.assert_called_once_with(
            pyramid_request, mock.sentinel.notification
        )
        assert send.lastcall == (
            ["*****@*****.**"],
            "Your email",
            "Text body",
            "HTML body",
        )
Exemplo n.º 2
0
    def test_it_sends_emails(
        self,
        event,
        pyramid_request,
        storage,
        reply,
        emails,
        mailer,
    ):

        subscribers.send_reply_notifications(event)

        # This is a pure plumbing test, checking everything is connected to
        # everything else as we expect
        storage.fetch_annotation.assert_called_once_with(
            pyramid_request.db, event.annotation_id)
        annotation = storage.fetch_annotation.return_value
        reply.get_notification.assert_called_once_with(pyramid_request,
                                                       annotation,
                                                       event.action)
        notification = reply.get_notification.return_value
        emails.reply_notification.generate.assert_called_once_with(
            pyramid_request, notification)
        send_params = emails.reply_notification.generate.return_value
        mailer.send.delay.assert_called_once_with(*send_params)
Exemplo n.º 3
0
    def test_it_does_nothing_if_no_notification_is_required(
            self, event, reply, mailer):
        reply.get_notification.return_value = None

        subscribers.send_reply_notifications(event)

        mailer.send.delay.assert_not_called()
Exemplo n.º 4
0
    def test_generates_and_sends_mail_for_any_notification(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(
            spec_set=[], return_value=mock.sentinel.notification
        )
        generate_mail = mock.Mock(spec_set=[])
        generate_mail.return_value = (
            ["*****@*****.**"],
            "Your email",
            "Text body",
            "HTML body",
        )
        event = AnnotationEvent(pyramid_request, None, None)

        subscribers.send_reply_notifications(
            event,
            get_notification=get_notification,
            generate_mail=generate_mail,
            send=send,
        )

        generate_mail.assert_called_once_with(
            pyramid_request, mock.sentinel.notification
        )
        assert send.lastcall == (
            ["*****@*****.**"],
            "Your email",
            "Text body",
            "HTML body",
        )
Exemplo n.º 5
0
    def test_reraises_exceptions_in_debug_mode(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        request = testing.DummyRequest(sentry=mock.Mock(), debug=True)
        event = AnnotationEvent(request, None, None)

        with pytest.raises(RuntimeError):
            subscribers.send_reply_notifications(event,
                                                 generate=generate,
                                                 send=send)
Exemplo n.º 6
0
    def test_reraises_exceptions_in_debug_mode(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        request = testing.DummyRequest(sentry=mock.Mock(), debug=True)
        event = AnnotationEvent(request, None, None)

        with pytest.raises(RuntimeError):
            subscribers.send_reply_notifications(event,
                                                 generate=generate,
                                                 send=send)
Exemplo n.º 7
0
    def test_catches_exceptions_and_reports_to_sentry(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        request = testing.DummyRequest(sentry=mock.Mock(), debug=False)
        event = AnnotationEvent(request, None, None)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        event.request.sentry.captureException.assert_called_once_with()
Exemplo n.º 8
0
    def test_catches_exceptions_and_reports_to_sentry(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        request = testing.DummyRequest(sentry=mock.Mock(), debug=False)
        event = AnnotationEvent(request, None, None)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        event.request.sentry.captureException.assert_called_once_with()
Exemplo n.º 9
0
    def test_reraises_exceptions_in_debug_mode(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        pyramid_request.debug = True
        pyramid_request.sentry = mock.Mock()
        event = AnnotationEvent(pyramid_request, None, None)

        with pytest.raises(RuntimeError):
            subscribers.send_reply_notifications(event,
                                                 get_notification=get_notification,
                                                 generate_mail=generate_mail,
                                                 send=send)
Exemplo n.º 10
0
    def test_catches_exceptions_and_reports_to_sentry(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], side_effect=RuntimeError('asplode!'))
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        pyramid_request.debug = False
        pyramid_request.sentry = mock.Mock()
        event = AnnotationEvent(pyramid_request, None, None)

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        event.request.sentry.captureException.assert_called_once_with()
Exemplo n.º 11
0
    def test_calls_generate_with_request_annotation_and_action(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], return_value=[])
        event = AnnotationEvent(mock.sentinel.request,
                                mock.sentinel.annotation,
                                mock.sentinel.action)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        generate.assert_called_once_with(mock.sentinel.request,
                                         mock.sentinel.annotation,
                                         mock.sentinel.action)
Exemplo n.º 12
0
    def test_calls_generate_with_request_annotation_and_action(self):
        send = FakeMailer()
        generate = mock.Mock(spec_set=[], return_value=[])
        event = AnnotationEvent(mock.sentinel.request,
                                mock.sentinel.annotation,
                                mock.sentinel.action)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        generate.assert_called_once_with(mock.sentinel.request,
                                         mock.sentinel.annotation,
                                         mock.sentinel.action)
Exemplo n.º 13
0
    def test_generates_and_sends_mail_for_any_notification(self):
        s = mock.sentinel
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], return_value=s.notification)
        generate_mail = mock.Mock(spec_set=[])
        generate_mail.return_value = (['*****@*****.**'], 'Your email', 'Text body', 'HTML body')
        event = AnnotationEvent(s.request, None, None)

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        generate_mail.assert_called_once_with(s.request, s.notification)
        assert send.lastcall == (['*****@*****.**'], 'Your email', 'Text body', 'HTML body')
Exemplo n.º 14
0
    def test_reraises_exceptions_in_debug_mode(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[],
                                     side_effect=RuntimeError('asplode!'))
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        pyramid_request.debug = True
        pyramid_request.sentry = mock.Mock()
        event = AnnotationEvent(pyramid_request, None, None)

        with pytest.raises(RuntimeError):
            subscribers.send_reply_notifications(
                event,
                get_notification=get_notification,
                generate_mail=generate_mail,
                send=send)
Exemplo n.º 15
0
    def test_catches_exceptions_and_reports_to_sentry(self, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[],
                                     side_effect=RuntimeError('asplode!'))
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        pyramid_request.debug = False
        pyramid_request.sentry = mock.Mock()
        event = AnnotationEvent(pyramid_request, None, None)

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        event.request.sentry.captureException.assert_called_once_with()
Exemplo n.º 16
0
    def test_sends_mail_generated_by_generate(self):
        send = FakeMailer()
        generate = fake_generate([
            ('Your email', 'Text body', 'HTML body', ['*****@*****.**']),
            ('Safari', 'Giraffes', '<p>Elephants!</p>', ['*****@*****.**']),
        ])
        event = AnnotationEvent(None, None, None)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        assert send.calls == [
            (['*****@*****.**'], 'Your email', 'Text body', 'HTML body'),
            (['*****@*****.**'], 'Safari', 'Giraffes', '<p>Elephants!</p>'),
        ]
Exemplo n.º 17
0
    def test_sends_mail_generated_by_generate(self):
        send = FakeMailer()
        generate = fake_generate([
            ('Your email', 'Text body', 'HTML body', ['*****@*****.**']),
            ('Safari', 'Giraffes', '<p>Elephants!</p>', ['*****@*****.**']),
        ])
        event = AnnotationEvent(None, None, None)

        subscribers.send_reply_notifications(event,
                                             generate=generate,
                                             send=send)

        assert send.calls == [
            (['*****@*****.**'], 'Your email', 'Text body', 'HTML body'),
            (['*****@*****.**'], 'Safari', 'Giraffes', '<p>Elephants!</p>'),
        ]
Exemplo n.º 18
0
    def test_generates_and_sends_mail_for_any_notification(self):
        s = mock.sentinel
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], return_value=s.notification)
        generate_mail = mock.Mock(spec_set=[])
        generate_mail.return_value = (['*****@*****.**'], 'Your email',
                                      'Text body', 'HTML body')
        event = AnnotationEvent(s.request, None, None)
        s.request.db = mock.Mock()

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        generate_mail.assert_called_once_with(s.request, s.notification)
        assert send.lastcall == (['*****@*****.**'], 'Your email',
                                 'Text body', 'HTML body')
Exemplo n.º 19
0
    def test_calls_get_notification_with_request_annotation_and_action(
            self, fetch_annotation, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], return_value=None)
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        event = AnnotationEvent(pyramid_request, mock.sentinel.annotation_id,
                                mock.sentinel.action)

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        fetch_annotation.assert_called_once_with(pyramid_request.db,
                                                 mock.sentinel.annotation_id)

        get_notification.assert_called_once_with(pyramid_request,
                                                 fetch_annotation.return_value,
                                                 mock.sentinel.action)
Exemplo n.º 20
0
    def test_calls_get_notification_with_request_annotation_and_action(self, fetch_annotation, pyramid_request):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], return_value=None)
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        event = AnnotationEvent(pyramid_request,
                                mock.sentinel.annotation_id,
                                mock.sentinel.action)

        subscribers.send_reply_notifications(event,
                                             get_notification=get_notification,
                                             generate_mail=generate_mail,
                                             send=send)

        fetch_annotation.assert_called_once_with(pyramid_request.db,
                                                 mock.sentinel.annotation_id)

        get_notification.assert_called_once_with(pyramid_request,
                                                 fetch_annotation.return_value,
                                                 mock.sentinel.action)
Exemplo n.º 21
0
    def test_it_fails_gracefully_if_the_task_does_not_queue(
            self, event, mailer):
        mailer.send.side_effect = OperationalError

        # No explosions please
        subscribers.send_reply_notifications(event)