Exemplo n.º 1
0
def _publish_annotation_event(request, annotation, action):
    """Publish an event to the annotations queue for this annotation action."""
    links_service = request.find_service(name='links')
    annotation_dict = None
    if action == 'delete':
        presenter = AnnotationJSONPresenter(annotation, links_service)
        annotation_dict = presenter.asdict()

    event = AnnotationEvent(request, annotation.id, action, annotation_dict)
    request.notify_after_commit(event)
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
0
def _publish_annotation_event(request, annotation, action):
    """Publish an event to the annotations queue for this annotation action."""
    event = AnnotationEvent(request, annotation.id, action)
    request.notify_after_commit(event)
Exemplo n.º 7
0
 def event(self, pyramid_request):
     pyramid_request.realtime = mock.Mock()
     event = AnnotationEvent(pyramid_request, 'test_annotation_id',
                             'create')
     return event
Exemplo n.º 8
0
 def event(self, pyramid_request):
     pyramid_request.realtime = mock.Mock()
     event = AnnotationEvent(pyramid_request, 'test_annotation_id',
                             'create')
     type(event).annotation_dict = mock.PropertyMock(return_value=None)
     return event