Пример #1
0
def create_annotation_schema_validate(request, data):
    # 'uri' is required when creating new annotations.
    if "uri" not in data:
        data["uri"] = "http://example.com/example"

    schema = CreateAnnotationSchema(request)
    return schema.validate(data)
Пример #2
0
    def test_it_defaults_to_private_if_no_permissions_object_sent(
            self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct["shared"] is False
Пример #3
0
    def test_it_sets_userid(self, pyramid_config, pyramid_request):
        pyramid_config.testing_securitypolicy("acct:[email protected]")
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct["userid"] == "acct:[email protected]"
Пример #4
0
    def test_it_renames_group_to_groupid(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(group="foo"))

        assert appstruct["groupid"] == "foo"
        assert "group" not in appstruct
Пример #5
0
    def test_it_renames_group_to_groupid(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(group='foo'))

        assert appstruct['groupid'] == 'foo'
        assert 'group' not in appstruct
Пример #6
0
    def test_it_renames_group_to_groupid(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(group='foo'))

        assert appstruct['groupid'] == 'foo'
        assert 'group' not in appstruct
Пример #7
0
    def test_it_keeps_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(references=["parent id", "parent id 2"]))

        assert appstruct["references"] == ["parent id", "parent id 2"]
Пример #8
0
    def test_it_sets_userid(self, pyramid_config, pyramid_request):
        pyramid_config.testing_securitypolicy('acct:[email protected]')
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct['userid'] == 'acct:[email protected]'
Пример #9
0
    def test_it_deletes_groupid_for_replies(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(group="foo", references=["parent annotation id"]))

        assert "groupid" not in appstruct
Пример #10
0
def create_annotation_schema_validate(request, data):
    # 'uri' is required when creating new annotations.
    if 'uri' not in data:
        data['uri'] = 'http://example.com/example'

    schema = CreateAnnotationSchema(request)
    return schema.validate(data)
Пример #11
0
    def test_it_keeps_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(references=['parent id', 'parent id 2']))

        assert appstruct['references'] == ['parent id', 'parent id 2']
Пример #12
0
    def test_it_renames_group_to_groupid(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(group="foo"))

        assert appstruct["groupid"] == "foo"
        assert "group" not in appstruct
Пример #13
0
    def test_it_keeps_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(
            references=['parent id', 'parent id 2']
        ))

        assert appstruct['references'] == ['parent id', 'parent id 2']
Пример #14
0
    def test_it_deletes_groupid_for_replies(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(group="foo", references=["parent annotation id"])
        )

        assert "groupid" not in appstruct
Пример #15
0
    def test_it_keeps_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(references=["parent id", "parent id 2"])
        )

        assert appstruct["references"] == ["parent id", "parent id 2"]
Пример #16
0
    def test_it_defaults_to_private_if_no_permissions_object_sent(
        self, pyramid_request
    ):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct["shared"] is False
Пример #17
0
    def test_it_raises_if_data_has_no_uri(self, pyramid_request):
        data = self.valid_data()
        del data['uri']
        schema = CreateAnnotationSchema(pyramid_request)

        with pytest.raises(ValidationError) as exc:
            schema.validate(data)

        assert str(exc.value) == "uri: 'uri' is a required property"
Пример #18
0
    def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(
            permissions={'read': ['acct:[email protected]']}
        ))

        assert appstruct['shared'] is False
        assert 'permissions' not in appstruct
Пример #19
0
    def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(permissions={"read": ["acct:[email protected]"]})
        )

        assert appstruct["shared"] is False
        assert "permissions" not in appstruct
Пример #20
0
    def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(permissions={"read": ["acct:[email protected]"]})
        )

        assert not appstruct["shared"]
        assert "permissions" not in appstruct
Пример #21
0
    def test_it_raises_if_data_has_no_uri(self, pyramid_request):
        data = self.valid_data()
        del data["uri"]
        schema = CreateAnnotationSchema(pyramid_request)

        with pytest.raises(ValidationError) as exc:
            schema.validate(data)

        assert str(exc.value) == "uri: 'uri' is a required property"
Пример #22
0
    def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data(
            permissions={'read': ['group:__world__']},
            group='__world__'
        ))

        assert appstruct['shared'] is True
        assert 'permissions' not in appstruct
Пример #23
0
    def test_it_replaces_shared_permissions_with_shared_True(
            self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(permissions={"read": ["group:__world__"]},
                            group="__world__"))

        assert appstruct["shared"] is True
        assert "permissions" not in appstruct
Пример #24
0
    def test_it_replaces_shared_permissions_with_shared_True(
            self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(permissions={'read': ['group:__world__']},
                            group='__world__'))

        assert appstruct['shared'] is True
        assert 'permissions' not in appstruct
Пример #25
0
    def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(
            self.valid_data(
                permissions={"read": ["group:__world__"]}, group="__world__"
            )
        )

        assert appstruct["shared"] is True
        assert "permissions" not in appstruct
Пример #26
0
def create(request):
    """Create an annotation from the POST payload."""
    schema = CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))
    group_service = request.find_service(IGroupService)
    annotation = storage.create_annotation(request, appstruct, group_service)

    _publish_annotation_event(request, annotation, "create")

    svc = request.find_service(name="annotation_json_presentation")
    annotation_resource = _annotation_resource(request, annotation)
    return svc.present(annotation_resource)
Пример #27
0
def create(request):
    """Create an annotation from the POST payload."""
    schema = CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))

    annotation = storage.create_annotation(request, appstruct)

    _publish_annotation_event(request, annotation, "create")

    return request.find_service(name="annotation_json").present_for_user(
        annotation=annotation, user=request.user
    )
Пример #28
0
def create(request):
    """Create an annotation from the POST payload."""
    schema = CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))
    group_service = request.find_service(IGroupService)
    annotation = storage.create_annotation(request, appstruct, group_service)

    _publish_annotation_event(request, annotation, "create")

    svc = request.find_service(name="annotation_json_presentation")
    annotation_resource = _annotation_resource(request, annotation)
    return svc.present(annotation_resource)
Пример #29
0
Файл: api.py Проект: rowhit/h
def create(request):
    """Create an annotation from the POST payload."""
    schema = CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))
    group_service = request.find_service(IGroupService)
    annotation = storage.create_annotation(request, appstruct, group_service)

    _publish_annotation_event(request, annotation, 'create')

    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()
Пример #30
0
Файл: api.py Проект: gnott/h
def create(request):
    """Create an annotation from the POST payload."""
    schema = CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))
    group_service = request.find_service(IGroupService)
    annotation = storage.create_annotation(request, appstruct, group_service)

    _publish_annotation_event(request, annotation, 'create')

    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()
Пример #31
0
    def test_it_inserts_empty_string_if_data_contains_no_text(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())['text'] == ''
Пример #32
0
    def test_it_inserts_empty_list_if_data_contains_no_tags(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())['tags'] == []
Пример #33
0
    def test_it_inserts_empty_list_if_no_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct["references"] == []
Пример #34
0
    def test_it_inserts_default_groupid_if_no_group(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct["groupid"] == "__world__"
Пример #35
0
    def test_it_inserts_default_groupid_if_no_group(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct['groupid'] == '__world__'
Пример #36
0
    def test_it_inserts_empty_list_if_no_references(self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        appstruct = schema.validate(self.valid_data())

        assert appstruct['references'] == []
Пример #37
0
    def test_it_inserts_empty_string_if_data_contains_no_text(
            self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())["text"] == ""
Пример #38
0
    def test_it_inserts_empty_list_if_data_contains_no_tags(
            self, pyramid_request):
        schema = CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())["tags"] == []