Commits

Joe Gregorio  committed da8b014

Add default support for optimistic concurrency on PATCH requests

  • Participants
  • Parent commits 65527fb

Comments (0)

Files changed (4)

File python2/httplib2/__init__.py

 
         # Which HTTP methods do we apply optimistic concurrency to, i.e.
         # which methods get an "if-match:" etag header added to them.
-        self.optimistic_concurrency_methods = ["PUT"]
+        self.optimistic_concurrency_methods = ["PUT", "PATCH"]
 
         # If 'follow_redirects' is True, and this is set to True then
         # all redirecs are followed, including unsafe ones.

File python2/httplib2test.py

         self.assertEqual(response.fromcache, False)
 
     def testUpdateUsesCachedETag(self):
-        # Test that we natively support http://www.w3.org/1999/04/Editing/ 
+        # Test that we natively support http://www.w3.org/1999/04/Editing/
         uri = urlparse.urljoin(base, "conditional-updates/test.cgi")
 
         (response, content) = self.http.request(uri, "GET")
         (response, content) = self.http.request(uri, "PUT", body="foo")
         self.assertEqual(response.status, 412)
 
+    def testUpdatePatchUsesCachedETag(self):
+        # Test that we natively support http://www.w3.org/1999/04/Editing/
+        uri = urlparse.urljoin(base, "conditional-updates/test.cgi")
+
+        (response, content) = self.http.request(uri, "GET")
+        self.assertEqual(response.status, 200)
+        self.assertEqual(response.fromcache, False)
+        (response, content) = self.http.request(uri, "GET")
+        self.assertEqual(response.status, 200)
+        self.assertEqual(response.fromcache, True)
+        (response, content) = self.http.request(uri, "PATCH", body="foo")
+        self.assertEqual(response.status, 200)
+        (response, content) = self.http.request(uri, "PATCH", body="foo")
+        self.assertEqual(response.status, 412)
+
+
     def testUpdateUsesCachedETagAndOCMethod(self):
         # Test that we natively support http://www.w3.org/1999/04/Editing/ 
         uri = urlparse.urljoin(base, "conditional-updates/test.cgi")

File python3/httplib2/__init__.py

 
         # Which HTTP methods do we apply optimistic concurrency to, i.e.
         # which methods get an "if-match:" etag header added to them.
-        self.optimistic_concurrency_methods = ["PUT"]
-        
+        self.optimistic_concurrency_methods = ["PUT", "PATCH"]
+
         # If 'follow_redirects' is True, and this is set to True then
         # all redirecs are followed, including unsafe ones.
         self.follow_all_redirects = False

File python3/httplib2test.py

         (response, content) = self.http.request(uri, "PUT", body="foo")
         self.assertEqual(response.status, 412)
 
+
+    def testUpdatePatchUsesCachedETag(self):
+        # Test that we natively support http://www.w3.org/1999/04/Editing/ 
+        uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")
+
+        (response, content) = self.http.request(uri, "GET")
+        self.assertEqual(response.status, 200)
+        self.assertEqual(response.fromcache, False)
+        (response, content) = self.http.request(uri, "GET")
+        self.assertEqual(response.status, 200)
+        self.assertEqual(response.fromcache, True)
+        (response, content) = self.http.request(uri, "PATCH", body="foo")
+        self.assertEqual(response.status, 200)
+        (response, content) = self.http.request(uri, "PATCH", body="foo")
+        self.assertEqual(response.status, 412)
+
     def testUpdateUsesCachedETagAndOCMethod(self):
         # Test that we natively support http://www.w3.org/1999/04/Editing/ 
         uri = urllib.parse.urljoin(base, "conditional-updates/test.cgi")