예제 #1
0
파일: storage_test.py 프로젝트: kaydoh/h
    def test_it_validates_the_group_scope(self, pyramid_request, annotation,
                                          _validate_group_scope):
        storage.update_annotation(pyramid_request, annotation.id,
                                  {"target_uri": "sentinel.target_uri"})

        _validate_group_scope.assert_called_once_with(annotation.group,
                                                      "sentinel.target_uri")
예제 #2
0
파일: storage_test.py 프로젝트: welhefna/h
    def test_it_raises_if_missing_group(self, annotation_data, pyramid_request, group_service):
        group_service.find.return_value = None

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert str(exc.value).startswith('group: ')
예제 #3
0
    def test_it_updates_the_document_metadata_from_the_annotation(
            self,
            annotation_data,
            pyramid_request,
            datetime,
            update_document_metadata,
            group_service):
        annotation = pyramid_request.db.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(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        update_document_metadata.assert_called_once_with(
            pyramid_request.db,
            annotation.target_uri,
            mock.sentinel.document_meta_dicts,
            mock.sentinel.document_uri_dicts,
            updated=datetime.utcnow()
        )
예제 #4
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_does_not_call_update_document_meta_if_no_document_in_data(
            self, pyramid_request, update_document_metadata, group_service):

        storage.update_annotation(pyramid_request, "test_annotation_id", {},
                                  group_service)

        assert not update_document_metadata.called
예제 #5
0
    def test_it_updates_the_document_metadata_from_the_annotation(
        self,
        annotation_data,
        pyramid_request,
        datetime,
        update_document_metadata,
        groupfinder_service,
    ):
        annotation = pyramid_request.db.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(
            pyramid_request, "test_annotation_id", annotation_data, groupfinder_service
        )

        update_document_metadata.assert_called_once_with(
            pyramid_request.db,
            annotation.target_uri,
            mock.sentinel.document_meta_dicts,
            mock.sentinel.document_uri_dicts,
            updated=datetime.utcnow(),
        )
예제 #6
0
파일: storage_test.py 프로젝트: welhefna/h
    def test_it_updates_the_document_metadata_from_the_annotation(
            self,
            annotation_data,
            pyramid_request,
            datetime,
            update_document_metadata,
            group_service):
        annotation = pyramid_request.db.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(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        update_document_metadata.assert_called_once_with(
            pyramid_request.db,
            annotation.target_uri,
            mock.sentinel.document_meta_dicts,
            mock.sentinel.document_uri_dicts,
            updated=datetime.utcnow()
        )
예제 #7
0
    def test_it_raises_if_missing_group(self, annotation_data, pyramid_request, group_service):
        group_service.find.return_value = None

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert str(exc.value).startswith('group: ')
예제 #8
0
파일: storage_test.py 프로젝트: welhefna/h
    def test_it_raises_when_group_scope_mismatch(self, annotation_data, pyramid_request, group_service, scoped_open_group):
        annotation_data['target_uri'] = u'http://www.bar.com/baz/ding.html'
        group_service.find.return_value = scoped_open_group

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert str(exc.value).startswith('group scope: ')
예제 #9
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
예제 #10
0
    def test_it_raises_when_group_scope_mismatch(self, annotation_data, pyramid_request, group_service, scoped_open_group):
        annotation_data['target_uri'] = 'http://www.bar.com/baz/ding.html'
        group_service.find.return_value = scoped_open_group

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert str(exc.value).startswith('group scope: ')
예제 #11
0
파일: storage_test.py 프로젝트: kaydoh/h
    def test_it_queues_the_annotation_for_syncing_to_Elasticsearch(
            self, annotation, pyramid_request, search_index):
        storage.update_annotation(pyramid_request, annotation.id, {})

        search_index._queue.add_by_id.assert_called_once_with(  # pylint:disable=protected-access
            annotation.id,
            tag="storage.update_annotation",
            schedule_in=60)
예제 #12
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')
예제 #13
0
파일: storage_test.py 프로젝트: gnott/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
예제 #14
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_gets_the_annotation_model(self, pyramid_request,
                                          annotation_data, group_service,
                                          models):
        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)

        pyramid_request.db.query.assert_called_once_with(models.Annotation)
        pyramid_request.db.query.return_value.get.assert_called_once_with(
            "test_annotation_id")
예제 #15
0
    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
예제 #16
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'}
예제 #17
0
파일: storage_test.py 프로젝트: gnott/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
예제 #18
0
    def test_it_does_not_call_update_document_meta_if_no_document_in_data(
            self,
            pyramid_request,
            update_document_metadata,
            group_service):

        storage.update_annotation(pyramid_request, 'test_annotation_id', {}, group_service)

        assert not update_document_metadata.called
예제 #19
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'}
예제 #20
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_updates_the_annotation(self, annotation_data, pyramid_request,
                                       group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value

        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)

        for key, value in annotation_data.items():
            assert getattr(annotation, key) == value
예제 #21
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_adds_new_extras(self, pyramid_request, annotation_data,
                                group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {}
        annotation_data["extra"] = {"foo": "bar"}

        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)

        assert annotation.extra == {"foo": "bar"}
예제 #22
0
    def test_it_does_not_change_extras_if_none_are_sent(
            self, pyramid_request, annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {'one': 1, 'two': 2}
        assert not annotation_data.get('extra')

        storage.update_annotation(pyramid_request, 'test_annotation_id',
                                  annotation_data, group_service)

        assert annotation.extra == {'one': 1, 'two': 2}
예제 #23
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_does_not_change_extras_if_none_are_sent(
            self, pyramid_request, annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {"one": 1, "two": 2}
        assert not annotation_data.get("extra")

        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)

        assert annotation.extra == {"one": 1, "two": 2}
예제 #24
0
    def test_it_overwrites_existing_extras(self, pyramid_request,
                                           annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {'foo': 'original_value'}
        annotation_data['extra'] = {'foo': 'new_value'}

        storage.update_annotation(pyramid_request, 'test_annotation_id',
                                  annotation_data, group_service)

        assert annotation.extra == {'foo': 'new_value'}
예제 #25
0
파일: storage_test.py 프로젝트: gnott/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'}
예제 #26
0
    def test_it_updates_the_annotation(self, annotation_data, pyramid_request, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value

        storage.update_annotation(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        for key, value in annotation_data.items():
            assert getattr(annotation, key) == value
예제 #27
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}
예제 #28
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_overwrites_existing_extras(self, pyramid_request,
                                           annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {"foo": "original_value"}
        annotation_data["extra"] = {"foo": "new_value"}

        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)

        assert annotation.extra == {"foo": "new_value"}
예제 #29
0
    def test_it_queues_the_annotation_for_syncing_to_Elasticsearch(
        self, annotation_data, groupfinder_service, pyramid_request, search_index
    ):
        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, groupfinder_service
        )

        search_index._queue.add_by_id.assert_called_once_with(
            "test_annotation_id", tag="storage.update_annotation", schedule_in=60
        )
예제 #30
0
    def test_it_adds_new_extras(self, pyramid_request, annotation_data,
                                group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {}
        annotation_data['extra'] = {'foo': 'bar'}

        storage.update_annotation(pyramid_request, 'test_annotation_id',
                                  annotation_data, group_service)

        assert annotation.extra == {'foo': 'bar'}
예제 #31
0
    def test_it_adds_new_extras(self, pyramid_request, annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {}
        annotation_data["extra"] = {"foo": "bar"}

        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        assert annotation.extra == {"foo": "bar"}
예제 #32
0
파일: storage_test.py 프로젝트: gnott/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')
예제 #33
0
    def test_it_updates_the_annotations_document_id(
        self, annotation_data, pyramid_request, update_document_metadata, group_service
    ):
        annotation = pyramid_request.db.query.return_value.get.return_value
        document = mock.Mock()
        update_document_metadata.return_value = document

        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )
        assert annotation.document == document
예제 #34
0
    def test_it_adds_new_extras(self, pyramid_request, annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {}
        annotation_data['extra'] = {'foo': 'bar'}

        storage.update_annotation(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        assert annotation.extra == {'foo': 'bar'}
예제 #35
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_updates_the_annotations_document_id(self, annotation_data,
                                                    pyramid_request,
                                                    update_document_metadata,
                                                    group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        document = mock.Mock()
        update_document_metadata.return_value = document

        storage.update_annotation(pyramid_request, "test_annotation_id",
                                  annotation_data, group_service)
        assert annotation.document == document
예제 #36
0
    def test_it_gets_the_annotation_model(
        self, pyramid_request, annotation_data, group_service, models
    ):
        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        pyramid_request.db.query.assert_called_once_with(models.Annotation)
        pyramid_request.db.query.return_value.get.assert_called_once_with(
            "test_annotation_id"
        )
예제 #37
0
파일: storage_test.py 프로젝트: gnott/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}
예제 #38
0
파일: storage_test.py 프로젝트: gnott/h
    def test_it_updates_the_annotations_document_id(self,
                                                    annotation_data,
                                                    session,
                                                    update_document_metadata):
        annotation = session.query.return_value.get.return_value
        document = mock.Mock()
        update_document_metadata.return_value = document

        storage.update_annotation(session,
                                  'test_annotation_id',
                                  annotation_data)
        assert annotation.document == document
예제 #39
0
    def test_it_does_not_change_extras_if_none_are_sent(
        self, pyramid_request, annotation_data, group_service
    ):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {"one": 1, "two": 2}
        assert not annotation_data.get("extra")

        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        assert annotation.extra == {"one": 1, "two": 2}
예제 #40
0
    def test_it_does_not_change_extras_that_are_not_sent(
        self, pyramid_request, annotation_data, groupfinder_service
    ):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {"one": 1, "two": 2}
        annotation_data["extra"] = {"two": 22}

        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, groupfinder_service
        )

        assert annotation.extra["one"] == 1
예제 #41
0
    def test_it_overwrites_existing_extras(
        self, pyramid_request, annotation_data, group_service
    ):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {"foo": "original_value"}
        annotation_data["extra"] = {"foo": "new_value"}

        storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        assert annotation.extra == {"foo": "new_value"}
예제 #42
0
파일: storage_test.py 프로젝트: gnott/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'}
예제 #43
0
    def test_it_does_not_change_extras_that_are_not_sent(
            self, pyramid_request, annotation_data, group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {
            'one': 1,
            'two': 2,
        }
        annotation_data['extra'] = {'two': 22}

        storage.update_annotation(pyramid_request, 'test_annotation_id',
                                  annotation_data, group_service)

        assert annotation.extra['one'] == 1
예제 #44
0
    def test_it_raises_when_group_scope_mismatch(
        self, annotation_data, pyramid_request, group_service, scoped_open_group
    ):
        # This target URI does not match any of the group's defined scopes
        annotation_data["target_uri"] = "http://www.bar.com/baz/ding.html"
        group_service.find.return_value = scoped_open_group

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(
                pyramid_request, "test_annotation_id", annotation_data, group_service
            )

        assert str(exc.value).startswith("group scope: ")
예제 #45
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_raises_when_group_scope_mismatch(self, annotation_data,
                                                 pyramid_request,
                                                 group_service,
                                                 scoped_open_group):
        # This target URI does not match any of the group's defined scopes
        annotation_data["target_uri"] = "http://www.bar.com/baz/ding.html"
        group_service.find.return_value = scoped_open_group

        with pytest.raises(ValidationError) as exc:
            storage.update_annotation(pyramid_request, "test_annotation_id",
                                      annotation_data, group_service)

        assert str(exc.value).startswith("group scope: ")
예제 #46
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
예제 #47
0
    def test_it_does_not_change_extras_if_none_are_sent(self,
                                                        pyramid_request,
                                                        annotation_data,
                                                        group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {'one': 1, 'two': 2}
        assert not annotation_data.get('extra')

        storage.update_annotation(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        assert annotation.extra == {'one': 1, 'two': 2}
예제 #48
0
    def test_it_overwrites_existing_extras(self,
                                           pyramid_request,
                                           annotation_data,
                                           group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {'foo': 'original_value'}
        annotation_data['extra'] = {'foo': 'new_value'}

        storage.update_annotation(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        assert annotation.extra == {'foo': 'new_value'}
예제 #49
0
파일: storage_test.py 프로젝트: gnott/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
예제 #50
0
    def test_it_returns_the_annotation(self, annotation_data, pyramid_request, group_service):
        annotation = storage.update_annotation(pyramid_request,
                                               'test_annotation_id',
                                               annotation_data,
                                               group_service)

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #51
0
    def test_it_changes_the_updated_timestamp(self, annotation_data, pyramid_request, datetime, group_service):
        annotation = storage.update_annotation(pyramid_request,
                                               'test_annotation_id',
                                               annotation_data,
                                               group_service)

        assert annotation.updated == datetime.utcnow()
예제 #52
0
    def test_it_allows_when_group_scope_matches(self, annotation_data, pyramid_request, group_service, scoped_open_group, models):
        annotation_data['target_uri'] = 'http://www.foo.com/baz/ding.html'

        # this should not raise
        annotation = storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #53
0
파일: storage_test.py 프로젝트: tarsbase/h
    def test_it_returns_the_annotation(self, annotation_data, pyramid_request,
                                       group_service):
        annotation = storage.update_annotation(pyramid_request,
                                               "test_annotation_id",
                                               annotation_data, group_service)

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #54
0
파일: storage_test.py 프로젝트: welhefna/h
    def test_it_changes_the_updated_timestamp(self, annotation_data, pyramid_request, datetime, group_service):
        annotation = storage.update_annotation(pyramid_request,
                                               'test_annotation_id',
                                               annotation_data,
                                               group_service)

        assert annotation.updated == datetime.utcnow()
예제 #55
0
파일: storage_test.py 프로젝트: welhefna/h
    def test_it_allows_when_group_scope_matches(self, annotation_data, pyramid_request, group_service, scoped_open_group, models):
        annotation_data['target_uri'] = u'http://www.foo.com/baz/ding.html'

        # this should not raise
        annotation = storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #56
0
    def test_it_does_not_change_extras_that_are_not_sent(self,
                                                         pyramid_request,
                                                         annotation_data,
                                                         group_service):
        annotation = pyramid_request.db.query.return_value.get.return_value
        annotation.extra = {
            'one': 1,
            'two': 2,
        }
        annotation_data['extra'] = {'two': 22}

        storage.update_annotation(pyramid_request,
                                  'test_annotation_id',
                                  annotation_data,
                                  group_service)

        assert annotation.extra['one'] == 1
예제 #57
0
    def test_it_allows_group_scope_when_no_target_uri(self, annotation_data, pyramid_request, group_service, scoped_open_group):
        annotation_data.pop('target_uri')
        group_service.find.return_value = scoped_open_group

        # this should not raise
        annotation = storage.update_annotation(pyramid_request, 'test_annotation_id', annotation_data, group_service)

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #58
0
    def test_it_allows_when_group_scope_matches(
        self, annotation_data, pyramid_request, group_service, scoped_open_group, models
    ):
        # This target URI matches at least one of the scopes for the group
        # it will go into...
        annotation_data["target_uri"] = "http://www.foo.com/baz/ding.html"

        # this should not raise
        annotation = storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        assert annotation == pyramid_request.db.query.return_value.get.return_value
예제 #59
0
파일: storage_test.py 프로젝트: gnott/h
    def test_it_updates_the_document_metadata_from_the_annotation(
            self,
            annotation_data,
            session,
            datetime,
            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.target_uri,
            mock.sentinel.document_meta_dicts,
            mock.sentinel.document_uri_dicts,
            updated=datetime.utcnow()
        )
예제 #60
0
    def test_it_allows_scope_mismatch_when_enforce_scope_is_False(
        self, annotation_data, pyramid_request, group_service, scoped_open_group
    ):
        scoped_open_group.enforce_scope = False
        group_service.find.return_value = scoped_open_group
        # This target URI is not within any of the group's defined scopes
        annotation_data["target_uri"] = "http://www.bar.com/baz/ding.html"

        # This will not raise because ``enforce_scope`` is set to False for the
        # annotation's group
        annotation = storage.update_annotation(
            pyramid_request, "test_annotation_id", annotation_data, group_service
        )

        assert annotation == pyramid_request.db.query.return_value.get.return_value