コード例 #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
ファイル: storage_test.py プロジェクト: Cinemacloud/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)
コード例 #4
0
ファイル: storage_test.py プロジェクト: Cinemacloud/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)
コード例 #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
ファイル: storage_test.py プロジェクト: Cinemacloud/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)
コード例 #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
ファイル: storage_test.py プロジェクト: Cinemacloud/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
コード例 #14
0
ファイル: storage_test.py プロジェクト: Cinemacloud/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()
コード例 #15
0
ファイル: storage_test.py プロジェクト: Cinemacloud/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)
コード例 #16
0
ファイル: storage_test.py プロジェクト: Cinemacloud/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)