def test_it_inits_the_schema(self, pyramid_request, schemas): annotation = mock.Mock() views.update(annotation, pyramid_request) schemas.UpdateAnnotationSchema.assert_called_once_with( pyramid_request, annotation.target_uri, annotation.groupid)
def test_it_validates_the_posted_data(self, pyramid_request, schemas): annotation = mock.Mock() schema = schemas.UpdateAnnotationSchema.return_value views.update(annotation, pyramid_request) schema.validate.assert_called_once_with(pyramid_request.json_body)
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( 'memex.api.deprecated.put_update_annotation')
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_inits_a_presenter(self, AnnotationJSONPresenter, links_service, pyramid_request, storage): views.update(mock.Mock(), pyramid_request) AnnotationJSONPresenter.assert_any_call( storage.update_annotation.return_value, links_service)
def test_it_updates_the_annotation_in_storage(self, pyramid_request, storage, schemas): annotation = mock.Mock() schema = schemas.UpdateAnnotationSchema.return_value schema.validate.return_value = mock.sentinel.validated_data views.update(annotation, pyramid_request) storage.update_annotation.assert_called_once_with( pyramid_request.db, 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_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_an_AnnotationEvent(self, AnnotationEvent, storage, pyramid_request): annotation = mock.Mock() views.update(annotation, pyramid_request) AnnotationEvent.assert_called_once_with( pyramid_request, storage.update_annotation.return_value.id, 'update', annotation_dict=None)
def test_it_updates_the_annotation_in_storage(self, pyramid_request, storage, schemas): annotation = mock.Mock() schema = schemas.UpdateAnnotationSchema.return_value schema.validate.return_value = mock.sentinel.validated_data views.update(annotation, pyramid_request) storage.update_annotation.assert_called_once_with( pyramid_request.db, 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_dictizes_the_presenter(self, AnnotationJSONPresenter, pyramid_request): views.update(mock.Mock(), pyramid_request) AnnotationJSONPresenter.return_value.asdict.assert_called_with()
def test_it_raises_if_validate_raises(self, pyramid_request, schemas): schemas.UpdateAnnotationSchema.return_value.validate\ .side_effect = ValidationError('asplode') with pytest.raises(ValidationError): views.update(mock.Mock(), pyramid_request)
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_storage_raises(self, pyramid_request, storage): storage.update_annotation.side_effect = ValidationError('asplode') with pytest.raises(ValidationError): views.update(mock.Mock(), pyramid_request)