Example #1
0
    def test_it_raises_for_missing_annotation_id(self, pyramid_request,
                                                 annotation):
        pyramid_request.json_body = {}
        context = FakeAnnotationResourceFactory(annotation)

        with pytest.raises(ValidationError):
            views.create(context, pyramid_request)
    def test_it_flags_annotation(self, pyramid_request, flag_service):
        context = mock.Mock()

        views.create(context, pyramid_request)

        flag_service.create.assert_called_once_with(pyramid_request.user,
                                                    context.annotation)
    def test_sends_notification_email(self, pyramid_request,
                                      flag_notification_email, mailer):
        context = mock.Mock()
        pyramid_request.json_body = {'annotation': context.annotation.id}

        views.create(context, pyramid_request)
        mailer.send.delay.assert_called_once_with(
            *flag_notification_email.return_value)
Example #4
0
    def test_it_raises_for_malformed_request_body(self, pyramid_request,
                                                  annotation):
        type(pyramid_request).json_body = mock.PropertyMock(
            side_effect=ValueError('not json!'))
        context = FakeAnnotationResourceFactory(annotation)

        with pytest.raises(ValidationError):
            views.create(context, pyramid_request)
Example #5
0
    def test_it_renders_error_when_annotation_does_not_exist(
            self, pyramid_request, annotation):
        pyramid_request.json_body = {'annotation': 'bogus'}
        context = FakeAnnotationResourceFactory(annotation)

        with pytest.raises(HTTPNotFound) as exc:
            views.create(context, pyramid_request)

        assert 'cannot find annotation' in exc.value.message
Example #6
0
    def test_it_flags_annotation(self, pyramid_request, annotation,
                                 flag_service):
        pyramid_request.json_body = {'annotation': annotation.id}
        context = FakeAnnotationResourceFactory(annotation)

        views.create(context, pyramid_request)

        flag_service.create.assert_called_once_with(
            pyramid_request.authenticated_user, annotation)
    def test_passes_annotation_target_uri_to_flag_notification_email(
            self, pyramid_request, group_service, flag_notification_email,
            incontext_link):
        context = mock.Mock()
        pyramid_request.json_body = {'annotation': context.annotation.id}
        incontext_link.return_value = None

        views.create(context, pyramid_request)

        flag_notification_email.assert_called_once_with(
            request=pyramid_request,
            email=group_service.find.return_value.creator.email,
            incontext_link=context.annotation.target_uri)
Example #8
0
    def test_it_renders_error_when_user_does_not_have_read_permission(
            self, pyramid_request, annotation):
        def fake_has_permission(action, _):
            if action == 'read':
                return False
            return True

        pyramid_request.has_permission = mock.Mock(
            side_effect=fake_has_permission)
        pyramid_request.json_body = {'annotation': annotation.id}
        context = FakeAnnotationResourceFactory(annotation)

        with pytest.raises(HTTPNotFound) as exc:
            views.create(context, pyramid_request)

        assert 'cannot find annotation' in exc.value.message
    def test_it_returns_no_content(self, pyramid_request):
        context = mock.Mock()

        response = views.create(context, pyramid_request)
        assert isinstance(response, HTTPNoContent)
Example #10
0
    def test_it_returns_no_content(self, pyramid_request, annotation):
        pyramid_request.json_body = {'annotation': annotation.id}
        context = FakeAnnotationResourceFactory(annotation)

        response = views.create(context, pyramid_request)
        assert isinstance(response, HTTPNoContent)