Skip to content

Commit

Permalink
Merge pull request #60 from scossu/fix_22
Browse files Browse the repository at this point in the history
Fix flaw in creating LDP-IC members; add tests for LDP-DC & LDP-IC.
  • Loading branch information
scossu authored Apr 16, 2018
2 parents c42349f + 804fd09 commit 1ad6251
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lakesuperior/model/ldpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,12 @@ def _add_ldp_dc_ic_rel(self, cont_rsrc):
s = cont_rsrc.metadata.value(cont_rsrc.uri, self.MBR_RSRC_URI)
p = cont_rsrc.metadata.value(cont_rsrc.uri, self.MBR_REL_URI)

if cont_rsrc.metadata[RDF.type: nsc['ldp'].DirectContainer]:
if nsc['ldp'].DirectContainer in cont_rsrc.ldp_types:
logger.info('Parent is a direct container.')

logger.debug('Creating DC triples.')
o = self.uri

elif (
cont_rsrc.metadata[
RDF.type: nsc['ldp'].IndirectContainer] and
self.INS_CNT_REL_URI in cont_p):
elif nsc['ldp'].IndirectContainer in cont_rsrc.ldp_types:
logger.info('Parent is an indirect container.')
cont_rel_uri = cont_rsrc.metadata.value(
cont_rsrc.uri, self.INS_CNT_REL_URI)
Expand Down
100 changes: 100 additions & 0 deletions tests/test_resource_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,31 @@
def random_uuid():
return str(uuid.uuid4())

@pytest.fixture
def dc_rdf():
return b'''
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
<> dcterms:title "Direct Container" ;
ldp:membershipResource <info:fcres/member> ;
ldp:hasMemberRelation dcterms:relation .
'''


@pytest.fixture
def ic_rdf():
return b'''
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX ldp: <http://www.w3.org/ns/ldp#>
PREFIX ore: <http://www.openarchives.org/ore/terms/>
<> dcterms:title "Indirect Container" ;
ldp:membershipResource <info:fcres/top_container> ;
ldp:hasMemberRelation dcterms:relation ;
ldp:insertedContentRelation ore:proxyFor .
'''


@pytest.mark.usefixtures('db')
class TestResourceApi:
Expand Down Expand Up @@ -225,3 +250,78 @@ def test_delta_update_wildcard(self):
rsrc.uri : nsc['foaf'].name : Literal('Joe 12oz Bob')]


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

dc_rsrc = rsrc_api.get(dc_uid)
member_rsrc = rsrc_api.get('/member')

assert nsc['ldp'].Container in dc_rsrc.ldp_types
assert nsc['ldp'].DirectContainer in dc_rsrc.ldp_types


def test_create_ldp_dc_put(self, dc_rdf):
"""
Create an LDP Direct Container via PUT.
"""
dc_uid = '/test_dc_put01'
rsrc_api.create_or_replace(
dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')

dc_rsrc = rsrc_api.get(dc_uid)
member_rsrc = rsrc_api.get('/member')

assert nsc['ldp'].Container in dc_rsrc.ldp_types
assert nsc['ldp'].DirectContainer in dc_rsrc.ldp_types


def test_add_dc_member(self, dc_rdf):
"""
Add members to a direct container and verify special properties.
"""
dc_uid = '/test_dc_put02'
rsrc_api.create_or_replace(
dc_uid, rdf_data=dc_rdf, rdf_fmt='turtle')

dc_rsrc = rsrc_api.get(dc_uid)
child_uid = rsrc_api.create(dc_uid, None)
member_rsrc = rsrc_api.get('/member')

assert member_rsrc.imr[
member_rsrc.uri: nsc['dcterms'].relation: nsc['fcres'][child_uid]]


def test_indirect_container(self, ic_rdf):
"""
Create an indirect container verify special properties.
"""
cont_uid = '/top_container'
ic_uid = '{}/test_ic'.format(cont_uid)
member_uid = '{}/ic_member'.format(ic_uid)
target_uid = '/ic_target'
ic_member_rdf = b'''
PREFIX ore: <http://www.openarchives.org/ore/terms/>
<> ore:proxyFor <info:fcres/ic_target> .'''

rsrc_api.create_or_replace(cont_uid)
rsrc_api.create_or_replace(target_uid)
rsrc_api.create_or_replace(ic_uid, rdf_data=ic_rdf, rdf_fmt='turtle')
rsrc_api.create_or_replace(
member_uid, rdf_data=ic_member_rdf, rdf_fmt='turtle')

ic_rsrc = rsrc_api.get(ic_uid)
assert nsc['ldp'].Container in ic_rsrc.ldp_types
assert nsc['ldp'].IndirectContainer in ic_rsrc.ldp_types
assert nsc['ldp'].DirectContainer not in ic_rsrc.ldp_types

member_rsrc = rsrc_api.get(member_uid)
top_cont_rsrc = rsrc_api.get(cont_uid)
assert top_cont_rsrc.imr[
top_cont_rsrc.uri: nsc['dcterms'].relation:
nsc['fcres'][target_uid]]

0 comments on commit 1ad6251

Please sign in to comment.