Browse Source

Wrap to 80 characters

Jared Whiklo 4 years ago
parent
commit
8e70cb9fa0
2 changed files with 66 additions and 26 deletions
  1. 5 3
      lakesuperior/endpoints/ldp.py
  2. 61 23
      tests/3_endpoints/test_3_0_ldp.py

+ 5 - 3
lakesuperior/endpoints/ldp.py

@@ -686,9 +686,10 @@ def parse_repr_options(retr_opts, out_headers):
                 include = list()
                 omit = list()
                 for k, v in pref_imr_options.items():
-                    # pref_imr_options only contains requested preferences, override the defaults for those.
+                    # pref_imr_options only contains requested preferences,
+                    # override the defaults for those.
                     imr_options[k] = v
-                    # This creates Preference-Applied headers for those things we support.
+                    # This creates Preference-Applied headers.
                     if v:
                         list_holder = include
                     else:
@@ -700,7 +701,8 @@ def parse_repr_options(retr_opts, out_headers):
                 if len(omit) > 0:
                     header_output += ' omit="' + ' '.join(omit) + '";'
                 if len(header_output) > 0:
-                    out_headers['Preference-Applied'] = 'return=representation;' + header_output
+                    out_headers['Preference-Applied'] = 'return=representation;'\
+                                                        + header_output
             except KeyError:
                 # Invalid Prefer header so we disregard the entire thing.
                 pass

+ 61 - 23
tests/3_endpoints/test_3_0_ldp.py

@@ -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