[Repoze-checkins] r1123 - in repoze.accelerator/trunk/repoze/accelerator: . tests

Chris McDonough chrism at agendaless.com
Sun Jun 22 20:46:41 EDT 2008


Author: Chris McDonough <chrism at agendaless.com>
Date: Sun Jun 22 20:46:41 2008
New Revision: 1123

Log:
Better fetch tests.


Modified:
   repoze.accelerator/trunk/repoze/accelerator/policy.py
   repoze.accelerator/trunk/repoze/accelerator/tests/test_policy.py

Modified: repoze.accelerator/trunk/repoze/accelerator/policy.py
==============================================================================
--- repoze.accelerator/trunk/repoze/accelerator/policy.py	(original)
+++ repoze.accelerator/trunk/repoze/accelerator/policy.py	Sun Jun 22 20:46:41 2008
@@ -127,7 +127,7 @@
         if environ.get('REQUEST_METHOD', 'GET') not in self.allowed_methods:
             return
 
-        request_headers = parse_headers(environ)
+        request_headers = list(parse_headers(environ))
 
         # if a Cache-Control/Pragma: no-cache header is in the request,
         # and if honor_shift_reload is true, we don't serve it from cache
@@ -237,12 +237,12 @@
             for (getter, discrim) in discrims:
                 stored_name, stored_value = discrim
                 strval = getter(stored_name)
-                if strval is None or strval.lower() != stored_value:
+                if strval is None or strval != stored_value:
                     matching_entries.remove(entry)
                     break
 
         if matching_entries:
-            match = matching_entries[0]
+            match = matching_entries[0] # this is essentially random
             status, headers, body = match[:3]
             return status, headers, body
 

Modified: repoze.accelerator/trunk/repoze/accelerator/tests/test_policy.py
==============================================================================
--- repoze.accelerator/trunk/repoze/accelerator/tests/test_policy.py	(original)
+++ repoze.accelerator/trunk/repoze/accelerator/tests/test_policy.py	Sun Jun 22 20:46:41 2008
@@ -82,6 +82,15 @@
         result = policy.store('200 OK', headers, environ)
         self.assertEqual(result, None)
 
+    def test_store_not_cacheable_bad_maxage(self):
+        storage = DummyStorage()
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        headers = self._makeHeaders()
+        headers.append(('Cache-Control', 'max-age=thisisbad'))
+        result = policy.store('200 OK', headers, environ)
+        self.assertEqual(result, None)
+
     def test_store_not_cacheable_nostore_https_responses(self):
         storage = DummyStorage()
         policy = self._makeOne(storage)
@@ -245,6 +254,38 @@
         result = policy.fetch(environ)
         self.failIfEqual(result, False)
 
+    def test_fetch_fails_range_request(self):
+        storage = DummyStorage(fetch_result=False)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_RANGE'] = '200-300'
+        result = policy.fetch(environ)
+        self.failIfEqual(result, False)
+
+    def test_fetch_fails_conditional_ims_request(self):
+        storage = DummyStorage(fetch_result=False)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_IF_MODIFIED_SINCE'] = 'whenever'
+        result = policy.fetch(environ)
+        self.failIfEqual(result, False)
+
+    def test_fetch_fails_conditional_if_none_match_request(self):
+        storage = DummyStorage(fetch_result=False)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_IF_NONE_MATCH'] = 'yeah'
+        result = policy.fetch(environ)
+        self.failIfEqual(result, False)
+
+    def test_fetch_fails_conditional_if_match_request(self):
+        storage = DummyStorage(fetch_result=False)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_IF_MATCH'] = 'yeah'
+        result = policy.fetch(environ)
+        self.failIfEqual(result, False)
+
     def test_fetch_succeeds_no_request_method(self):
         headers = self._makeHeaders()
         cc = 'max-age=4000'
@@ -268,6 +309,62 @@
         result = policy.fetch(environ)
         self.assertEqual(result, expected[:3])
 
+    def test_fetch_succeeds_more_than_one_response_from_storage(self):
+        headers = self._makeHeaders()
+        cc = 'max-age=4000'
+        headers.append(('Cache-Control', cc))
+        expected1 = (200, headers, [], [], [])
+        expected2 = (200, headers, [], [], [])
+        storage = DummyStorage(fetch_result=[expected1] + [expected2])
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        result = policy.fetch(environ)
+        self.assertEqual(result, expected1[:3])
+
+    def test_fetch_succeeds_via_discrimination(self):
+        headers = self._makeHeaders()
+        cc = 'max-age=4000'
+        headers.append(('Cache-Control', cc))
+        stored = [
+            (200, headers, [], [('Cookie', '12345')], []),
+            (200, headers, [], [('X-Foo', '12345'), ('Cookie', '12345')], []),
+            (200, headers, [], [('X-Bar', '123')], []),
+             ]
+        storage = DummyStorage(fetch_result=stored)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_COOKIE'] = '12345'
+        environ['HTTP_X_FOO'] = '12345'
+        result = policy.fetch(environ)
+        self.assertEqual(result, stored[1][:3])
+
+    def test_fetch_fails_via_discrimination(self):
+        headers = self._makeHeaders()
+        cc = 'max-age=4000'
+        headers.append(('Cache-Control', cc))
+        stored = [
+            (200, headers, [], [('Cookie', '12345')], []),
+            (200, headers, [], [('X-Foo', '12345'), ('Cookie', '12345')], []),
+            (200, headers, [], [('X-Bar', '123')], []),
+             ]
+        storage = DummyStorage(fetch_result=stored)
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        environ['HTTP_COOKIE'] = '5678'
+        environ['HTTP_X_FOO'] = '5678'
+        result = policy.fetch(environ)
+        self.assertEqual(result, None)
+
+    def test_fetch_fails_no_response_from_storage(self):
+        headers = self._makeHeaders()
+        cc = 'max-age=4000'
+        headers.append(('Cache-Control', cc))
+        storage = DummyStorage(fetch_result=[])
+        policy = self._makeOne(storage)
+        environ = self._makeEnviron()
+        result = policy.fetch(environ)
+        self.assertEqual(result, None)
+
 class DummyStorage:
     def __init__(self, fetch_result=None, store_result=None):
         self.fetch_result = fetch_result


More information about the Repoze-checkins mailing list