Exemplo n.º 1
0
    def test_it_renames_group_to_groupid(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['groupid'] == 'foo'
        assert 'group' not in appstruct
Exemplo n.º 2
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 = schemas.CreateAnnotationSchema(request)
    return schema.validate(data)
Exemplo n.º 3
0
    def test_it_sets_userid(self, pyramid_config, pyramid_request):
        pyramid_config.testing_securitypolicy('acct:[email protected]')
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['userid'] == 'acct:[email protected]'
Exemplo n.º 4
0
    def test_it_deletes_groupid_for_replies(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert 'groupid' not in appstruct
Exemplo n.º 5
0
    def test_it_keeps_references(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['references'] == ['parent id', 'parent id 2']
Exemplo n.º 6
0
    def test_it_defaults_to_private_if_no_permissions_object_sent(
            self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['shared'] is False
Exemplo n.º 7
0
    def test_it_raises_if_uri_is_empty_string(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

        with pytest.raises(schemas.ValidationError) as exc:
            schema.validate(self.valid_data(uri=''))

        assert exc.value.message == "uri: 'uri' is a required property"
Exemplo n.º 8
0
    def test_it_replaces_private_permissions_with_shared_False(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['shared'] is False
        assert 'permissions' not in appstruct
Exemplo n.º 9
0
    def test_it_raises_if_data_has_no_uri(self, pyramid_request):
        data = self.valid_data()
        del data['uri']
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert exc.value.message == "uri: 'uri' is a required property"
Exemplo n.º 10
0
    def test_it_replaces_shared_permissions_with_shared_True(self, pyramid_request):
        schema = schemas.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
Exemplo n.º 11
0
def create(request):
    """Create an annotation from the POST payload."""
    schema = schemas.CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))
    annotation = storage.create_annotation(request, appstruct)

    _publish_annotation_event(request, annotation, 'create')

    links_service = request.find_service(name='links')
    presenter = AnnotationJSONPresenter(annotation, links_service)
    return presenter.asdict()
Exemplo n.º 12
0
    def test_it_inserts_empty_list_if_no_references(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['references'] == []
Exemplo n.º 13
0
    def test_it_inserts_default_groupid_if_no_group(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

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

        assert appstruct['groupid'] == '__world__'
Exemplo n.º 14
0
    def test_it_inserts_empty_list_if_data_contains_no_tags(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())['tags'] == []
Exemplo n.º 15
0
    def test_it_inserts_empty_string_if_data_contains_no_text(self, pyramid_request):
        schema = schemas.CreateAnnotationSchema(pyramid_request)

        assert schema.validate(self.valid_data())['text'] == ''