]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_web: improve ETag tests, add If-None-Match test
authorBrian Warner <warner@lothar.com>
Sun, 13 May 2012 07:19:20 +0000 (00:19 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 13 May 2012 07:45:11 +0000 (00:45 -0700)
src/allmydata/test/common_web.py
src/allmydata/test/test_web.py

index 477daa00c0b2bf5a07972effdb7ae6bb5d3fafbb..f6e0ac7a1840d530e6e9f7daf52ca5c793c7b58b 100644 (file)
@@ -61,7 +61,8 @@ class WebRenderingMixin:
 
 
 class MyGetter(client.HTTPPageGetter):
-    handleStatus_206 = lambda self: self.handleStatus_200()
+    handleStatus_206 = lambda self: self.handleStatus_200() # PARTIAL_CONTENT
+    handleStatus_304 = lambda self: self.handleStatus_200() # NOT_MODIFIED
 
 class HTTPClientHEADFactory(client.HTTPClientFactory):
     protocol = MyGetter
index 41c176e1d972c21c3b486c06ccb4dade3c382ba1..81dbb2015f420a0fd5f9d9c056224f4e56bcec19 100644 (file)
@@ -907,8 +907,11 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
             d2 = _get_etag(uri, 'json')
             d = defer.DeferredList([d1, d2], consumeErrors=True)
             def _check(results):
-                assert all([r[0] for r in results])  # All deferred must succeed
-                assert results[0][1] + 'json' == results[1][1]
+                # All deferred must succeed
+                self.failUnless(all([r[0] for r in results]))
+                # the etag for the t=json form should be just like the etag
+                # fo the default t='' form, but with a 'json' suffix
+                self.failUnlessEqual(results[0][1] + 'json', results[1][1])
             d.addCallback(_check)
             return d
 
@@ -918,7 +921,8 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
             def _just_the_etag(result):
                 data, response, headers = result
                 etag = headers['etag'][0]
-                if uri.startswith('URI:DIR'): assert etag.startswith('DIR:')
+                if uri.startswith('URI:DIR'):
+                    self.failUnless(etag.startswith('DIR:'), etag)
                 return etag
             return d.addCallback(_just_the_etag)
 
@@ -930,6 +934,23 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
 
         # Check that etags work with immutable files
         d.addCallback(lambda _: _check_etags(self._bar_txt_uri))
+
+        # use the ETag on GET
+        def _check_match(ign):
+            uri = "/uri/%s" % self._bar_txt_uri
+            d = self.GET(uri, return_response=True)
+            # extract the ETag
+            d.addCallback(lambda (data, code, headers):
+                          headers['etag'][0])
+            # do a GET that's supposed to match the ETag
+            d.addCallback(lambda etag:
+                          self.GET(uri, return_response=True,
+                                   headers={"If-None-Match": etag}))
+            # make sure it short-circuited (304 instead of 200)
+            d.addCallback(lambda (data, code, headers):
+                          self.failUnlessEqual(int(code), http.NOT_MODIFIED))
+            return d
+        d.addCallback(_check_match)
         return d
 
     # TODO: version of this with a Unicode filename