def test_it_does_not_call_update_document_meta_if_no_document_in_data( self, session, update_document_metadata): storage.update_annotation(session, 'test_annotation_id', {}) assert not update_document_metadata.called
def test_it_gets_the_annotation_model(self, annotation_data, models, session): storage.update_annotation(session, 'test_annotation_id', annotation_data) session.query.assert_called_once_with(models.Annotation) session.query.return_value.get.assert_called_once_with( 'test_annotation_id')
def test_it_updates_the_annotation(self, annotation_data, session): annotation = session.query.return_value.get.return_value storage.update_annotation(session, 'test_annotation_id', annotation_data) for key, value in annotation_data.items(): assert getattr(annotation, key) == value
def test_it_adds_new_extras(self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = {} annotation_data['extra'] = {'foo': 'bar'} storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra == {'foo': 'bar'}
def test_it_overwrites_existing_extras(self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = {'foo': 'original_value'} annotation_data['extra'] = {'foo': 'new_value'} storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra == {'foo': 'new_value'}
def test_it_does_not_change_extras_if_none_are_sent( self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = {'one': 1, 'two': 2} assert not annotation_data.get('extra') storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra == {'one': 1, 'two': 2}
def test_it_does_not_change_extras_if_none_are_sent(self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = {'one': 1, 'two': 2} assert not annotation_data.get('extra') storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra == {'one': 1, 'two': 2}
def test_it_does_not_change_extras_that_are_not_sent( self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = { 'one': 1, 'two': 2, } annotation_data['extra'] = {'two': 22} storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra['one'] == 1
def test_it_updates_the_document_metadata_from_the_annotation( self, annotation_data, session, update_document_metadata): annotation = session.query.return_value.get.return_value annotation_data['document']['document_meta_dicts'] = ( mock.sentinel.document_meta_dicts) annotation_data['document']['document_uri_dicts'] = ( mock.sentinel.document_uri_dicts) storage.update_annotation(session, 'test_annotation_id', annotation_data) update_document_metadata.assert_called_once_with( session, annotation, mock.sentinel.document_meta_dicts, mock.sentinel.document_uri_dicts)
def test_it_does_not_change_extras_that_are_not_sent(self, annotation_data, session): annotation = session.query.return_value.get.return_value annotation.extra = { 'one': 1, 'two': 2, } annotation_data['extra'] = {'two': 22} storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation.extra['one'] == 1
def update(context, request): """Update the specified annotation with data from the PUT payload.""" schema = schemas.UpdateAnnotationSchema(request, annotation=context.model) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(context.id, appstruct) _publish_annotation_event(request, annotation, 'update') return annotation
def update(annotation, request): """Update the specified annotation with data from the PUT payload.""" schema = schemas.UpdateAnnotationSchema(request, annotation=annotation) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request, annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') presenter = AnnotationJSONPresenter(annotation) return presenter.asdict()
def test_it_updates_the_document_metadata_from_the_annotation( self, annotation_data, session, update_document_metadata): annotation = session.query.return_value.get.return_value annotation_data['document']['document_meta_dicts'] = ( mock.sentinel.document_meta_dicts) annotation_data['document']['document_uri_dicts'] = ( mock.sentinel.document_uri_dicts) storage.update_annotation(session, 'test_annotation_id', annotation_data) update_document_metadata.assert_called_once_with( session, annotation, mock.sentinel.document_meta_dicts, mock.sentinel.document_uri_dicts )
def test_it_does_not_crash_if_no_document_in_data(self, session): storage.update_annotation(session, 'test_annotation_id', {})
def test_it_returns_the_annotation(self, annotation_data, session): annotation = storage.update_annotation(session, 'test_annotation_id', annotation_data) assert annotation == session.query.return_value.get.return_value