Beispiel #1
0
def _publish_annotation_event(request, annotation, action):
    """Publish an event to the annotations queue for this annotation action."""
    annotation_dict = None
    if action == 'delete':
        annotation_dict = AnnotationJSONPresenter(request, annotation).asdict()

    event = AnnotationEvent(request, annotation.id, action, annotation_dict)
    request.notify_after_commit(event)
Beispiel #2
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)
Beispiel #3
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()
Beispiel #4
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)
Beispiel #5
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>'),
        ]
Beispiel #6
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')
Beispiel #7
0
    def test_calls_get_notification_with_request_annotation_and_action(
            self, fetch_annotation):
        send = FakeMailer()
        get_notification = mock.Mock(spec_set=[], return_value=None)
        generate_mail = mock.Mock(spec_set=[], return_value=[])
        event = AnnotationEvent(mock.sentinel.request,
                                mock.sentinel.annotation_id,
                                mock.sentinel.action)
        mock.sentinel.request.db = mock.Mock()

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

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

        get_notification.assert_called_once_with(mock.sentinel.request,
                                                 fetch_annotation.return_value,
                                                 mock.sentinel.action)
Beispiel #8
0
def _publish_annotation_event(request, annotation, action):
    """Publish an event to the annotations queue for this annotation action"""
    event = AnnotationEvent(request, annotation, action)
    request.registry.notify(event)
Beispiel #9
0
 def event(self):
     return mock.Mock(
         spec=AnnotationEvent(testing.DummyRequest(),
                              mock.Mock(spec=models.Annotation()),
                              'create'),
     )
Beispiel #10
0
 def event(self):
     event = mock.Mock(spec=AnnotationEvent(testing.DummyRequest(),
                                            'test_annotation_id',
                                            'create'), )
     type(event).annotation_dict = mock.PropertyMock(return_value=None)
     return event