def test_it_tracks_deprecated_put_requests(self, pyramid_request): pyramid_request.method = 'PUT' pyramid_request.stats = mock.Mock(spec_set=['incr']) views.update(mock.Mock(), pyramid_request) pyramid_request.stats.incr.assert_called_once_with('api.deprecated.put_update_annotation')
def test_it_raises_if_validate_raises(self, pyramid_request, update_schema): update_schema.return_value.validate.side_effect = ValidationError( 'asplode') with pytest.raises(ValidationError): views.update(mock.Mock(), pyramid_request)
def test_it_validates_the_posted_data(self, pyramid_request, update_schema): context = mock.Mock() schema = update_schema.return_value views.update(context, pyramid_request) schema.validate.assert_called_once_with(pyramid_request.json_body)
def test_it_presents_annotation(self, annotation_resource, presentation_service, pyramid_request): views.update(mock.Mock(), pyramid_request) presentation_service.present.assert_called_once_with( annotation_resource.return_value)
def test_it_inits_the_schema(self, pyramid_request, update_schema): context = mock.Mock() views.update(context, pyramid_request) update_schema.assert_called_once_with(pyramid_request, context.annotation.target_uri, context.annotation.groupid)
def test_it_inits_an_AnnotationEvent(self, AnnotationEvent, storage, pyramid_request): context = mock.Mock() views.update(context, pyramid_request) AnnotationEvent.assert_called_once_with( pyramid_request, storage.update_annotation.return_value.id, 'update')
def test_it_raises_if_json_parsing_fails(self, pyramid_request): """It raises PayloadError if parsing of the request body fails.""" # Make accessing the request.json_body property raise ValueError. type(pyramid_request).json_body = {} with mock.patch.object(type(pyramid_request), 'json_body', new_callable=mock.PropertyMock) as json_body: json_body.side_effect = ValueError() with pytest.raises(views.PayloadError): views.update(mock.Mock(), pyramid_request)
def test_it_initialises_annotation_resource(self, storage, annotation_resource, pyramid_request, group_service, links_service): annotation = storage.update_annotation.return_value views.update(mock.Mock(), pyramid_request) annotation_resource.assert_called_once_with(annotation, group_service, links_service)
def test_it_inits_an_AnnotationEvent(self, AnnotationEvent, storage, pyramid_request): context = mock.Mock() views.update(context, pyramid_request) AnnotationEvent.assert_called_once_with(pyramid_request, storage.update_annotation.return_value.id, 'update')
def test_it_inits_a_presenter(self, AnnotationJSONPresenter, annotation_resource, group_service, links_service, pyramid_request, storage): views.update(mock.Mock(), pyramid_request) annotation_resource.assert_called_once_with( storage.update_annotation.return_value, group_service, links_service) AnnotationJSONPresenter.assert_any_call( annotation_resource.return_value)
def test_it_updates_the_annotation_in_storage(self, pyramid_request, storage, update_schema): context = mock.Mock() schema = update_schema.return_value schema.validate.return_value = mock.sentinel.validated_data views.update(context, pyramid_request) storage.update_annotation.assert_called_once_with( pyramid_request.db, context.annotation.id, mock.sentinel.validated_data)
def test_it_inits_a_presenter(self, AnnotationJSONPresenter, annotation_resource, group_service, links_service, pyramid_request, storage): views.update(mock.Mock(), pyramid_request) annotation_resource.assert_called_once_with( storage.update_annotation.return_value, group_service, links_service) AnnotationJSONPresenter.assert_any_call(annotation_resource.return_value)
def test_it_updates_the_annotation_in_storage(self, pyramid_request, storage, update_schema): context = mock.Mock() schema = update_schema.return_value schema.validate.return_value = mock.sentinel.validated_data views.update(context, pyramid_request) storage.update_annotation.assert_called_once_with( pyramid_request.db, context.annotation.id, mock.sentinel.validated_data )
def test_it_returns_a_presented_dict(self, AnnotationJSONPresenter, pyramid_request): returned = views.update(mock.Mock(), pyramid_request) assert returned == ( AnnotationJSONPresenter.return_value.asdict.return_value)
def test_it_fires_the_AnnotationEvent(self, AnnotationEvent, pyramid_request): views.update(mock.Mock(), pyramid_request) pyramid_request.notify_after_commit.assert_called_once_with( AnnotationEvent.return_value)
def test_it_raises_if_validate_raises(self, pyramid_request, update_schema): update_schema.return_value.validate.side_effect = ValidationError('asplode') with pytest.raises(ValidationError): views.update(mock.Mock(), pyramid_request)
def test_it_raises_if_storage_raises(self, pyramid_request, storage): storage.update_annotation.side_effect = ValidationError('asplode') with pytest.raises(ValidationError): views.update(mock.Mock(), pyramid_request)
def test_it_dictizes_the_presenter(self, AnnotationJSONPresenter, pyramid_request): views.update(mock.Mock(), pyramid_request) AnnotationJSONPresenter.return_value.asdict.assert_called_with()
def test_it_returns_a_presented_dict(self, presentation_service, pyramid_request): returned = views.update(mock.Mock(), pyramid_request) assert returned == presentation_service.present.return_value