Ejemplo n.º 1
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
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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'}
Ejemplo n.º 5
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
Ejemplo n.º 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'}
Ejemplo n.º 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}
Ejemplo n.º 8
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'}
Ejemplo n.º 9
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')
Ejemplo n.º 10
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'}
Ejemplo n.º 11
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}
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
Archivo: views.py Proyecto: 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
Ejemplo n.º 16
0
Archivo: views.py Proyecto: 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()
Ejemplo n.º 17
0
Archivo: views.py Proyecto: 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()
Ejemplo n.º 18
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
        )
Ejemplo n.º 19
0
 def test_it_does_not_crash_if_no_document_in_data(self,
                                                   session):
     storage.update_annotation(session, 'test_annotation_id', {})
Ejemplo n.º 20
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
Ejemplo n.º 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
Ejemplo n.º 22
0
 def test_it_does_not_crash_if_no_document_in_data(self, session):
     storage.update_annotation(session, 'test_annotation_id', {})
Ejemplo n.º 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