def test_it_inits_AnnotationJSONPresenter(self, AnnotationJSONPresenter, links_service, pyramid_request, storage): views.create(pyramid_request) AnnotationJSONPresenter.assert_called_once_with( storage.create_annotation.return_value, links_service)
def test_it_raises_if_create_annotation_raises(self, pyramid_request, storage): storage.create_annotation.side_effect = ValidationError('asplode') with pytest.raises(ValidationError) as exc: views.create(pyramid_request) assert exc.value.message == 'asplode'
def test_it_raises_if_validate_raises(self, pyramid_request, schemas): schemas.CreateAnnotationSchema.return_value.validate.side_effect = ( ValidationError('asplode')) with pytest.raises(ValidationError) as exc: views.create(pyramid_request) assert exc.value.message == 'asplode'
def test_it_creates_the_annotation_in_storage(self, pyramid_request, storage, schemas): schema = schemas.CreateAnnotationSchema.return_value views.create(pyramid_request) storage.create_annotation.assert_called_once_with( pyramid_request, schema.validate.return_value)
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.create(pyramid_request)
def test_it_publishes_annotation_event(self, AnnotationEvent, pyramid_request, storage): """It publishes an annotation "create" event for the annotation.""" views.create(pyramid_request) annotation = storage.create_annotation.return_value AnnotationEvent.assert_called_once_with(pyramid_request, annotation.id, 'create') pyramid_request.notify_after_commit.assert_called_once_with( AnnotationEvent.return_value)
def test_it_publishes_annotation_event(self, AnnotationEvent, pyramid_request, storage): """It publishes an annotation "create" event for the annotation.""" views.create(pyramid_request) annotation = storage.create_annotation.return_value AnnotationEvent.assert_called_once_with( pyramid_request, annotation.id, 'create', annotation_dict=None) pyramid_request.notify_after_commit.assert_called_once_with( AnnotationEvent.return_value)
def test_it_returns_presented_annotation(self, AnnotationJSONPresenter, pyramid_request): result = views.create(pyramid_request) AnnotationJSONPresenter.return_value.asdict.assert_called_once_with() assert result == ( AnnotationJSONPresenter.return_value.asdict.return_value)
def test_it_validates_the_posted_data(self, pyramid_request, schemas): """It should call validate() with a request.json_body.""" views.create(pyramid_request) schemas.CreateAnnotationSchema.return_value.validate\ .assert_called_once_with(pyramid_request.json_body)
def test_it_inits_CreateAnnotationSchema(self, pyramid_request, schemas): views.create(pyramid_request) schemas.CreateAnnotationSchema.assert_called_once_with(pyramid_request)