def test_it_calls_partial(self, partial): request = self.mock_request() storage.legacy_create_annotation(request, self.annotation_data()) partial.assert_called_once_with( storage.fetch_annotation, request, _postgres=False)
def test_it_calls_notify(self, AnnotationBeforeSaveEvent): request = self.mock_request() storage.legacy_create_annotation(request, self.annotation_data()) request.registry.notify.assert_called_once_with( AnnotationBeforeSaveEvent.return_value)
def test_it_inits_AnnotationBeforeSaveEvent(self, AnnotationBeforeSaveEvent, models): request = self.mock_request() storage.legacy_create_annotation(request, self.annotation_data()) AnnotationBeforeSaveEvent.assert_called_once_with( request, models.elastic.Annotation.return_value)
def create(request): """Create an annotation from the POST payload.""" json_payload = _json_payload(request) # Validate the annotation for, and create the annotation in, PostgreSQL. if request.feature('postgres'): schema = schemas.CreateAnnotationSchema(request) appstruct = schema.validate(copy.deepcopy(json_payload)) annotation = storage.create_annotation(request, appstruct) # Validate the annotation for, and create the annotation in, Elasticsearch. legacy_schema = schemas.LegacyCreateAnnotationSchema(request) legacy_appstruct = legacy_schema.validate(copy.deepcopy(json_payload)) # When 'postgres' is on make sure that annotations in the legacy # Elasticsearch database use the same IDs as the PostgreSQL ones. if request.feature('postgres'): assert annotation.id legacy_appstruct['id'] = annotation.id legacy_annotation = storage.legacy_create_annotation( request, legacy_appstruct) if request.feature('postgres'): _publish_annotation_event(request, annotation, 'create') return AnnotationJSONPresenter(request, annotation).asdict() _publish_annotation_event(request, legacy_annotation, 'create') return AnnotationJSONPresenter(request, legacy_annotation).asdict()
def create(request): """Create an annotation from the POST payload.""" json_payload = _json_payload(request) # Validate the annotation for, and create the annotation in, PostgreSQL. if request.feature('postgres'): schema = schemas.CreateAnnotationSchema(request) appstruct = schema.validate(copy.deepcopy(json_payload)) annotation = storage.create_annotation(request, appstruct) # Validate the annotation for, and create the annotation in, Elasticsearch. legacy_schema = schemas.LegacyCreateAnnotationSchema(request) legacy_appstruct = legacy_schema.validate(copy.deepcopy(json_payload)) # When 'postgres' is on make sure that annotations in the legacy # Elasticsearch database use the same IDs as the PostgreSQL ones. if request.feature('postgres'): assert annotation.id legacy_appstruct['id'] = annotation.id legacy_annotation = storage.legacy_create_annotation(request, legacy_appstruct) if request.feature('postgres'): annotation_dict = ( AnnotationJSONPresenter(request, annotation).asdict()) else: annotation_dict = ( AnnotationJSONPresenter(request, legacy_annotation).asdict()) _publish_annotation_event(request, annotation_dict, 'create') return annotation_dict
def test_it_returns_the_annotation(self, models): result = storage.legacy_create_annotation(self.mock_request(), self.annotation_data()) assert result == models.elastic.Annotation.return_value
def test_it_calls_annotation_save(self, models): storage.legacy_create_annotation(self.mock_request(), self.annotation_data()) models.elastic.Annotation.return_value.save.assert_called_once_with()
def test_it_calls_prepare(self, models, partial, transform): storage.legacy_create_annotation(self.mock_request(), self.annotation_data()) transform.prepare.assert_called_once_with( models.elastic.Annotation.return_value, partial.return_value)
def test_it_inits_an_elastic_annotation_model(self, models): data = self.annotation_data() storage.legacy_create_annotation(self.mock_request(), data) models.elastic.Annotation.assert_called_once_with(data)