|
@@ -1722,8 +1722,10 @@ class TestPrefHeader:
|
|
|
.format(Ldpr.EMBED_CHILD_RES_URI),
|
|
|
})
|
|
|
|
|
|
- self._assert_pref_applied(incl_embed_children_resp, include=[Ldpr.EMBED_CHILD_RES_URI])
|
|
|
- self._assert_pref_applied(omit_embed_children_resp, omit=[Ldpr.EMBED_CHILD_RES_URI])
|
|
|
+ self._assert_pref_applied(incl_embed_children_resp,
|
|
|
+ include=[Ldpr.EMBED_CHILD_RES_URI])
|
|
|
+ self._assert_pref_applied(omit_embed_children_resp,
|
|
|
+ omit=[Ldpr.EMBED_CHILD_RES_URI])
|
|
|
|
|
|
default_gr = Graph().parse(data=cont_resp.data, format='turtle')
|
|
|
incl_gr = Graph().parse(
|
|
@@ -1760,8 +1762,10 @@ class TestPrefHeader:
|
|
|
.format(Ldpr.RETURN_CHILD_RES_URI),
|
|
|
})
|
|
|
|
|
|
- self._assert_pref_applied(incl_children_resp, include=[Ldpr.RETURN_CHILD_RES_URI])
|
|
|
- self._assert_pref_applied(omit_children_resp, omit=[Ldpr.RETURN_CHILD_RES_URI])
|
|
|
+ self._assert_pref_applied(incl_children_resp,
|
|
|
+ include=[Ldpr.RETURN_CHILD_RES_URI])
|
|
|
+ self._assert_pref_applied(omit_children_resp,
|
|
|
+ omit=[Ldpr.RETURN_CHILD_RES_URI])
|
|
|
|
|
|
default_gr = Graph().parse(data=cont_resp.data, format='turtle')
|
|
|
incl_gr = Graph().parse(data=incl_children_resp.data, format='turtle')
|
|
@@ -1794,8 +1798,10 @@ class TestPrefHeader:
|
|
|
.format(Ldpr.RETURN_INBOUND_REF_URI),
|
|
|
})
|
|
|
|
|
|
- self._assert_pref_applied(incl_inbound_resp, include=[Ldpr.RETURN_INBOUND_REF_URI])
|
|
|
- self._assert_pref_applied(omit_inbound_resp, omit=[Ldpr.RETURN_INBOUND_REF_URI])
|
|
|
+ self._assert_pref_applied(incl_inbound_resp,
|
|
|
+ include=[Ldpr.RETURN_INBOUND_REF_URI])
|
|
|
+ self._assert_pref_applied(omit_inbound_resp,
|
|
|
+ omit=[Ldpr.RETURN_INBOUND_REF_URI])
|
|
|
|
|
|
default_gr = Graph().parse(data=cont_resp.data, format='turtle')
|
|
|
incl_gr = Graph().parse(data=incl_inbound_resp.data, format='turtle')
|
|
@@ -1828,8 +1834,10 @@ class TestPrefHeader:
|
|
|
.format(Ldpr.RETURN_SRV_MGD_RES_URI),
|
|
|
})
|
|
|
|
|
|
- self._assert_pref_applied(incl_srv_mgd_resp, include=[Ldpr.RETURN_SRV_MGD_RES_URI])
|
|
|
- self._assert_pref_applied(omit_srv_mgd_resp, omit=[Ldpr.RETURN_SRV_MGD_RES_URI])
|
|
|
+ self._assert_pref_applied(incl_srv_mgd_resp,
|
|
|
+ include=[Ldpr.RETURN_SRV_MGD_RES_URI])
|
|
|
+ self._assert_pref_applied(omit_srv_mgd_resp,
|
|
|
+ omit=[Ldpr.RETURN_SRV_MGD_RES_URI])
|
|
|
|
|
|
default_gr = Graph().parse(data=cont_resp.data, format='turtle')
|
|
|
incl_gr = Graph().parse(data=incl_srv_mgd_resp.data, format='turtle')
|
|
@@ -1875,12 +1883,18 @@ class TestPrefHeader:
|
|
|
|
|
|
def test_contradicting_prefs(self):
|
|
|
"""
|
|
|
- Test include and omit the same preference. Does not apply a preference or return a Preference-Applied header.
|
|
|
+ Test include and omit the same preference. Does not apply a preference
|
|
|
+ or return a Preference-Applied header.
|
|
|
"""
|
|
|
- self.client.put('/ldp/test_contradicting_prefs01', content_type='text/turtle')
|
|
|
+ self.client.put('/ldp/test_contradicting_prefs01',
|
|
|
+ content_type='text/turtle')
|
|
|
|
|
|
resp1 = self.client.get('/ldp/test_contradicting_prefs01', headers={
|
|
|
- 'prefer': 'return=representation; include={0}; omit={0}'.format(Ldpr.RETURN_CHILD_RES_URI)
|
|
|
+ 'prefer': (
|
|
|
+ 'return=representation; include={0}; omit={0}'.format(
|
|
|
+ Ldpr.RETURN_CHILD_RES_URI
|
|
|
+ )
|
|
|
+ )
|
|
|
})
|
|
|
assert resp1.status_code == 200
|
|
|
self._assert_pref_applied(resp1)
|
|
@@ -1912,7 +1926,8 @@ class TestPrefHeader:
|
|
|
"""
|
|
|
Test multiple include and/or omit preferences.
|
|
|
"""
|
|
|
- self.client.put('/ldp/test_multiple_preferences01', content_type='text/turtle')
|
|
|
+ self.client.put('/ldp/test_multiple_preferences01',
|
|
|
+ content_type='text/turtle')
|
|
|
|
|
|
resp1 = self.client.get('/ldp/test_multiple_preferences01', headers={
|
|
|
'prefer': (
|
|
@@ -1924,16 +1939,26 @@ class TestPrefHeader:
|
|
|
)
|
|
|
})
|
|
|
assert resp1.status_code == 200
|
|
|
- self._assert_pref_applied(resp1, include=[Ldpr.RETURN_CHILD_RES_URI, Ldpr.EMBED_CHILD_RES_URI],
|
|
|
- omit=[Ldpr.RETURN_SRV_MGD_RES_URI])
|
|
|
+ self._assert_pref_applied(
|
|
|
+ resp1,
|
|
|
+ include=[
|
|
|
+ Ldpr.RETURN_CHILD_RES_URI,
|
|
|
+ Ldpr.EMBED_CHILD_RES_URI
|
|
|
+ ],
|
|
|
+ omit=[
|
|
|
+ Ldpr.RETURN_SRV_MGD_RES_URI
|
|
|
+ ]
|
|
|
+ )
|
|
|
|
|
|
def test_invalid_preference(self):
|
|
|
"""
|
|
|
- Test to ensure Prefer headers with unknown include/omit URIs are completely disregarded.
|
|
|
+ Test to ensure Prefer headers with unknown include/omit URIs are
|
|
|
+ completely disregarded.
|
|
|
"""
|
|
|
fake_preference = 'http://doesntexist.org/fake#preference'
|
|
|
|
|
|
- self.client.put('/ldp/test_invalid_preference01', content_type='text/turtle')
|
|
|
+ self.client.put('/ldp/test_invalid_preference01',
|
|
|
+ content_type='text/turtle')
|
|
|
|
|
|
resp1 = self.client.get('/ldp/test_invalid_preference01', headers={
|
|
|
'prefer': (
|
|
@@ -1950,13 +1975,23 @@ class TestPrefHeader:
|
|
|
self._assert_pref_applied(resp2)
|
|
|
|
|
|
resp3 = self.client.get('/ldp/test_invalid_preference01', headers={
|
|
|
- 'prefer': 'return=representation; include="{0} {1}"'.format(fake_preference, Ldpr.EMBED_CHILD_RES_URI)
|
|
|
+ 'prefer': (
|
|
|
+ 'return=representation; include="{0} {1}"'.format(
|
|
|
+ fake_preference,
|
|
|
+ Ldpr.EMBED_CHILD_RES_URI
|
|
|
+ )
|
|
|
+ )
|
|
|
})
|
|
|
assert resp3.status_code == 200
|
|
|
self._assert_pref_applied(resp3)
|
|
|
|
|
|
resp4 = self.client.get('/ldp/test_invalid_preference01', headers={
|
|
|
- 'prefer': 'return=representation; omit="{0} {1}"'.format(fake_preference, Ldpr.EMBED_CHILD_RES_URI)
|
|
|
+ 'prefer': (
|
|
|
+ 'return=representation; omit="{0} {1}"'.format(
|
|
|
+ fake_preference,
|
|
|
+ Ldpr.EMBED_CHILD_RES_URI
|
|
|
+ )
|
|
|
+ )
|
|
|
})
|
|
|
assert resp4.status_code == 200
|
|
|
self._assert_pref_applied(resp4)
|
|
@@ -2005,10 +2040,11 @@ class TestPrefHeader:
|
|
|
|
|
|
def _assert_pref_applied(self, response, value='representation', include=None, omit=None):
|
|
|
"""
|
|
|
- Utility to test a response for a Preference-Applied header with the include or omit lists.
|
|
|
+ Utility to test a response for a Preference-Applied header with the
|
|
|
+ include or omit lists.
|
|
|
|
|
|
- If both include and omit are empty and value is representation, it is expected that there is NO
|
|
|
- Preference-Applied header.
|
|
|
+ If both include and omit are empty and value is representation, it is
|
|
|
+ expected that there is NO Preference-Applied header.
|
|
|
|
|
|
:param response:: The client response.
|
|
|
:param string value:: The return=<value>.
|
|
@@ -2031,14 +2067,16 @@ class TestPrefHeader:
|
|
|
|
|
|
def _assert_pref_header_exists(self, expected, returned, type='include'):
|
|
|
"""
|
|
|
- Utility function to compare a list of expected preferences to an include or omit string.
|
|
|
+ Utility function to compare a list of expected preferences to an include
|
|
|
+ or omit string.
|
|
|
|
|
|
:param list expected:: List of expected preference URIs.
|
|
|
:param string returned:: Returned Prefer parameters
|
|
|
"""
|
|
|
if len(expected) > 0:
|
|
|
expected = [str(k) for k in expected]
|
|
|
- assert type in returned['parameters'] and len(returned['parameters'][type]) > 0
|
|
|
+ assert type in returned['parameters']
|
|
|
+ assert len(returned['parameters'][type]) > 0
|
|
|
received_prefs = returned['parameters'][type].split(' ')
|
|
|
for pref in received_prefs:
|
|
|
assert pref in expected
|