コード例 #1
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    def test_it_does_not_call_update_document_meta_if_no_document_in_data(
            self,
            session,
            models):

        storage.update_annotation(session, 'test_annotation_id', {})

        assert not models.update_document_metadata.called
コード例 #2
0
ファイル: storage_test.py プロジェクト: ssin122/test-h
    def test_it_does_not_call_update_document_meta_if_no_document_in_data(
            self,
            session,
            models):

        storage.update_annotation(session, 'test_annotation_id', {})

        assert not models.update_document_metadata.called
コード例 #3
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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')
コード例 #4
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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
コード例 #5
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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
コード例 #6
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    def test_it_updates_the_annotations_document_id(self, annotation_data,
                                                    session, models):
        annotation = session.query.return_value.get.return_value
        document = mock.Mock()
        models.update_document_metadata.return_value = document

        storage.update_annotation(session, 'test_annotation_id',
                                  annotation_data)
        assert annotation.document == document
コード例 #7
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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'}
コード例 #8
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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'}
コード例 #9
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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'}
コード例 #10
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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}
コード例 #11
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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')
コード例 #12
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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'}
コード例 #13
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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}
コード例 #14
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    def test_it_updates_the_annotations_document_id(self,
                                                    annotation_data,
                                                    session,
                                                    models):
        annotation = session.query.return_value.get.return_value
        document = mock.Mock()
        models.update_document_metadata.return_value = document

        storage.update_annotation(session,
                                  'test_annotation_id',
                                  annotation_data)
        assert annotation.document == document
コード例 #15
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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
コード例 #16
0
    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)
コード例 #17
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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
コード例 #18
0
ファイル: storage_test.py プロジェクト: pombredanne/h
    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
        )
コード例 #19
0
def update(annotation, request):
    """Update the specified annotation with data from the PUT payload."""
    schema = schemas.UpdateAnnotationSchema(request, annotation.target_uri,
                                            annotation.groupid)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.update_annotation(request.db, annotation.id,
                                           appstruct)

    _publish_annotation_event(request, annotation, 'update')

    links_service = request.find_service(name='links')
    presenter = AnnotationJSONPresenter(annotation, links_service)
    return presenter.asdict()
コード例 #20
0
def update(context, request):
    """Update the specified annotation with data from the PUT payload."""
    schema = schemas.UpdateAnnotationSchema(request,
                                            context.annotation.target_uri,
                                            context.annotation.groupid)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.update_annotation(request.db,
                                           context.annotation.id,
                                           appstruct)

    _publish_annotation_event(request, annotation, 'update')

    links_service = request.find_service(name='links')
    presenter = AnnotationJSONPresenter(annotation, links_service)
    return presenter.asdict()
コード例 #21
0
def update(context, request):
    """Update the specified annotation with data from the PATCH payload."""
    if request.method == 'PUT' and hasattr(request, 'stats'):
        request.stats.incr('memex.api.deprecated.put_update_annotation')

    schema = schemas.UpdateAnnotationSchema(request,
                                            context.annotation.target_uri,
                                            context.annotation.groupid)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.update_annotation(request.db, context.annotation.id,
                                           appstruct)

    _publish_annotation_event(request, annotation, 'update')

    links_service = request.find_service(name='links')
    group_service = request.find_service(IGroupService)
    resource = AnnotationResource(annotation, group_service, links_service)
    presenter = AnnotationJSONPresenter(resource)
    return presenter.asdict()
コード例 #22
0
ファイル: storage_test.py プロジェクト: tetratorus/h
 def test_it_does_not_crash_if_no_document_in_data(self, session):
     storage.update_annotation(session, 'test_annotation_id', {})
コード例 #23
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    def test_it_changes_the_updated_timestamp(self, annotation_data, session,
                                              datetime):
        annotation = storage.update_annotation(session, 'test_annotation_id',
                                               annotation_data)

        assert annotation.updated == datetime.utcnow()
コード例 #24
0
ファイル: storage_test.py プロジェクト: nlisgo/h
 def test_it_does_not_crash_if_no_document_in_data(self,
                                                   session):
     storage.update_annotation(session, 'test_annotation_id', {})
コード例 #25
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    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
コード例 #26
0
ファイル: storage_test.py プロジェクト: tetratorus/h
    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
コード例 #27
0
ファイル: storage_test.py プロジェクト: nlisgo/h
    def test_it_changes_the_updated_timestamp(self, annotation_data, session, datetime):
        annotation = storage.update_annotation(session,
                                               'test_annotation_id',
                                               annotation_data)

        assert annotation.updated == datetime.utcnow()