예제 #1
0
파일: storage_test.py 프로젝트: ackermann/h
    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)
예제 #2
0
파일: storage_test.py 프로젝트: ackermann/h
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
파일: storage_test.py 프로젝트: ackermann/h
    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)
예제 #6
0
    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)
예제 #7
0
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()
예제 #8
0
파일: views.py 프로젝트: Cinemacloud/h
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
예제 #9
0
파일: storage_test.py 프로젝트: ackermann/h
    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
예제 #10
0
파일: storage_test.py 프로젝트: ackermann/h
    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()
예제 #11
0
파일: storage_test.py 프로젝트: ackermann/h
 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)
예제 #12
0
파일: storage_test.py 프로젝트: ackermann/h
    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)
예제 #13
0
    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
예제 #14
0
    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()
예제 #15
0
 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)
예제 #16
0
    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)