예제 #1
0
파일: storage_test.py 프로젝트: ficolo/h
    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
예제 #2
0
    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')
예제 #3
0
    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
예제 #4
0
    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'}
예제 #5
0
파일: storage_test.py 프로젝트: ficolo/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
    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'}
예제 #7
0
    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}
예제 #8
0
파일: storage_test.py 프로젝트: ficolo/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 프로젝트: ficolo/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')
예제 #10
0
파일: storage_test.py 프로젝트: ficolo/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'}
예제 #11
0
파일: storage_test.py 프로젝트: ficolo/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}
예제 #12
0
    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
예제 #13
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)
예제 #14
0
파일: storage_test.py 프로젝트: ficolo/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
예제 #15
0
파일: views.py 프로젝트: VanyTang/h
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
예제 #16
0
파일: views.py 프로젝트: hashin/h
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()
예제 #17
0
파일: views.py 프로젝트: hashin/h
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()
예제 #18
0
파일: storage_test.py 프로젝트: ficolo/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
파일: storage_test.py 프로젝트: ficolo/h
 def test_it_does_not_crash_if_no_document_in_data(self,
                                                   session):
     storage.update_annotation(session, 'test_annotation_id', {})
예제 #20
0
파일: storage_test.py 프로젝트: ficolo/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
예제 #21
0
    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
예제 #22
0
 def test_it_does_not_crash_if_no_document_in_data(self, session):
     storage.update_annotation(session, 'test_annotation_id', {})
예제 #23
0
    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