示例#1
0
    def test_create_ldp_dc_post(self, dc_rdf):
        """
        Create an LDP Direct Container via POST.
        """
        rsrc_api.create_or_replace('/member')
        dc_rsrc = rsrc_api.create(
                '/', 'test_dc_post', rdf_data=dc_rdf, rdf_fmt='turtle')

        member_rsrc = rsrc_api.get('/member')

        with env.app_globals.rdf_store.txn_ctx():
            assert nsc['ldp'].Container in dc_rsrc.ldp_types
            assert nsc['ldp'].DirectContainer in dc_rsrc.ldp_types
示例#2
0
def post_resource(parent_uid):
    """
    https://www.w3.org/TR/ldp/#ldpr-HTTP_POST

    Add a new resource in a new URI.
    """
    out_headers = std_headers
    try:
        slug = request.headers['Slug']
        logger.debug('Slug: {}'.format(slug))
    except KeyError:
        slug = None

    handling, disposition = set_post_put_params()
    stream, mimetype = _bistream_from_req()

    if LdpFactory.is_rdf_parsable(mimetype):
        # If the content is RDF, localize in-repo URIs.
        global_rdf = stream.read()
        local_rdf = g.tbox.localize_payload(global_rdf)
        stream = BytesIO(local_rdf)
        is_rdf = True
    else:
        is_rdf = False

    try:
        uid = rsrc_api.create(parent_uid,
                              slug,
                              stream=stream,
                              mimetype=mimetype,
                              handling=handling,
                              disposition=disposition)
    except ResourceNotExistsError as e:
        return str(e), 404
    except InvalidResourceError as e:
        return str(e), 409
    except TombstoneError as e:
        return _tombstone_response(e, uid)
    except ServerManagedTermError as e:
        return str(e), 412

    uri = g.tbox.uid_to_uri(uid)
    hdr = {'Location': uri}

    if mimetype and not is_rdf:
        hdr['Link'] = '<{0}/fcr:metadata>; rel="describedby"; anchor="<{0}>"'\
                .format(uri)

    out_headers.update(hdr)

    return uri, 201, out_headers
示例#3
0
    def test_add_dc_member(self, dc_rdf):
        """
        Add members to a direct container and verify special properties.
        """
        dc_uid = '/test_dc_put02'
        _, dc_rsrc = rsrc_api.create_or_replace(
                dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')

        child_uid = rsrc_api.create(dc_uid).uid
        member_rsrc = rsrc_api.get('/member')

        with env.app_globals.rdf_store.txn_ctx():
            assert member_rsrc.imr[
                member_rsrc.uri: nsc['dcterms'].relation: nsc['fcres'][child_uid]]
示例#4
0
def _ingest_py(method, dest, data, ref):
    from lakesuperior.api import resource as rsrc_api

    kwargs = {}
    if isinstance(data, rdflib.Graph):
        kwargs['graph'] = data
    else:
        kwargs['stream'] = data
        kwargs['mimetype'] = 'image/png'

    if method == 'put':
        _, rsrc = rsrc_api.create_or_replace(dest, **kwargs)
    else:
        rsrc = rsrc_api.create(dest, **kwargs)

    return rsrc.uid
示例#5
0
    def test_create_ldp_dc_defaults3(self):
        """
        Create an LDP Direct Container with default values.
        """
        dc_rdf = b'''
        PREFIX dcterms: <http://purl.org/dc/terms/>
        PREFIX ldp: <http://www.w3.org/ns/ldp#>

        <> a ldp:DirectContainer .
        '''
        dc_uid = '/test_dc_defaults3'
        _, dc_rsrc = rsrc_api.create_or_replace(
                dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')

        child_uid = rsrc_api.create(dc_uid, None).uid
        member_rsrc = rsrc_api.get(dc_uid)

        with env.app_globals.rdf_store.txn_ctx():
            assert member_rsrc.imr[
                member_rsrc.uri: nsc['ldp'].member: nsc['fcres'][child_uid]]
示例#6
0
def post_resource(parent_uid):
    """
    https://www.w3.org/TR/ldp/#ldpr-HTTP_POST

    Add a new resource in a new URI.
    """
    rsp_headers = std_headers.copy()
    slug = request.headers.get('Slug')

    try:
        kwargs = _create_args_from_req(slug)
        rsrc = rsrc_api.create(parent_uid, slug, **kwargs)
    except exc.RdfParsingError as e:
        return str(e), 400
    except exc.IndigestibleError:
        return (
            f'Unable to parse digest header: {request.headers["digest"]}'), 400
    except exc.ResourceNotExistsError as e:
        return str(e), 404
    except (exc.InvalidResourceError, exc.ChecksumValidationError) as e:
        return str(e), 409
    except exc.TombstoneError as e:
        return _tombstone_response(e, uid)
    except exc.ServerManagedTermError as e:
        rsp_headers['Link'] = (f'<{uri}>; rel="{nsc["ldp"].constrainedBy}"; '
                               f'{g.webroot}/info/ldp_constraints"')
        return str(e), 412

    uri = g.tbox.uid_to_uri(rsrc.uid)
    with store.txn_ctx():
        rsp_headers.update(_headers_from_metadata(rsrc))
    rsp_headers['Location'] = uri

    if kwargs.get('mimetype') and kwargs.get('rdf_fmt') is None:
        rsp_headers['Link'] = (
            f'<{uri}/fcr:metadata>; rel="describedby"; anchor="{uri}"')

    return uri, 201, rsp_headers
示例#7
0
    def test_create_ldp_dc_defaults2(self):
        """
        Create an LDP Direct Container with default values.
        """
        dc_rdf = b'''
        PREFIX dcterms: <http://purl.org/dc/terms/>
        PREFIX ldp: <http://www.w3.org/ns/ldp#>

        <> a ldp:DirectContainer ;
            ldp:hasMemberRelation dcterms:relation .
        '''
        dc_uid = '/test_dc_defaults2'
        _, dc_rsrc = rsrc_api.create_or_replace(
                dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')

        child_uid = rsrc_api.create(dc_uid).uid
        member_rsrc = rsrc_api.get(dc_uid)

        with env.app_globals.rdf_store.txn_ctx():
            #import pdb; pdb.set_trace()
            assert member_rsrc.imr[
                member_rsrc.uri: nsc['dcterms'].relation:
                nsc['fcres'][child_uid]]