Skip to content

Commit

Permalink
More thorough testing for LDP-NR metadata and content retrieval.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Cossu committed Oct 8, 2018
1 parent 9a6807f commit a1ea22f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/2_endpoints/test_ldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,46 @@ def test_put_ldp_nr_multipart(self, rnd_img):
assert sha1(resp.data).hexdigest() == rnd_img['hash']


def test_get_ldp_nr(self, rnd_img):
"""
PUT a resource with binary payload and test various retieval methods.
"""
uid = '/ldpnr03'
path = '/ldp' + uid
content = b'This is some exciting content.'
resp = self.client.put(path, data=content,
headers={
'Content-Type': 'text/plain',
'Content-Disposition' : 'attachment; filename=exciting.txt'})
assert resp.status_code == 201
uri = g.webroot + uid

# Content retrieval methods.
resp_bin1 = self.client.get(path)
assert resp_bin1.status_code == 200
assert resp_bin1.data == content

resp_bin2 = self.client.get(path, headers={'accept' : 'text/plain'})
assert resp_bin2.status_code == 200
assert resp_bin2.data == content

resp_bin3 = self.client.get(path + '/fcr:content')
assert resp_bin3.status_code == 200
assert resp_bin3.data == content

# Metadata retrieval methods.
resp_md1 = self.client.get(path, headers={'accept' : 'text/turtle'})
assert resp_md1.status_code == 200
gr1 = Graph().parse(data=resp_md1.data, format='text/turtle')
assert gr1[ URIRef(uri) : nsc['rdf'].type : nsc['ldp'].Resource]

resp_md2 = self.client.get(path + '/fcr:metadata')
assert resp_md2.status_code == 200
gr2 = Graph().parse(data=resp_md2.data, format='text/turtle')
assert isomorphic(gr1, gr2)



def test_put_mismatched_ldp_rs(self, rnd_img):
"""
Verify MIME type / LDP mismatch.
Expand Down Expand Up @@ -268,17 +308,18 @@ def test_post_ldp_nr(self, rnd_img):
"""
POST a resource with binary payload and verify checksums.
"""
import pdb; pdb.set_trace()
rnd_img['content'].seek(0)
resp = self.client.post('/ldp/', data=rnd_img['content'],
headers={
'slug': 'ldpnr03',
'slug': 'ldpnr04',
'Content-Type': 'image/png',
'Content-Disposition' : 'attachment; filename={}'.format(
rnd_img['filename'])})
assert resp.status_code == 201

resp = self.client.get(
'/ldp/ldpnr03', headers={'accept' : 'image/png'})
'/ldp/ldpnr04', headers={'accept' : 'image/png'})
assert resp.status_code == 200
assert sha1(resp.data).hexdigest() == rnd_img['hash']

Expand Down

0 comments on commit a1ea22f

Please sign in to comment.