コード例 #1
0
 def test_expires_with_date(self):
     '''Uses the Date header when present.'''
     response = mock.Mock(
         headers={
             'expires': 'Thu, 13 Oct 2016 15:50:54 GMT',
             'date': 'Thu, 13 Oct 2016 15:49:54 GMT'
         })
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 60)
コード例 #2
0
 def test_cache_control_precedence(self):
     '''Cache control is used before expires.'''
     response = mock.Mock(
         headers={
             'cache_control': 'max-age=30',
             'expires': 'Thu, 13 Oct 2016 15:50:54 GMT',
             'date': 'Thu, 13 Oct 2016 15:49:54 GMT'
         })
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 30)
コード例 #3
0
 def test_expires_with_no_date(self):
     '''Uses the host computer's date when the Date header is absent.'''
     expires = 'Thu, 13 Oct 2016 15:50:54 GMT'
     response = mock.Mock(headers={'expires': expires})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     timestamp = ttl.parse_date(expires)
     expected = 60
     with mock.patch.object(ttl.time,
                            'time',
                            return_value=timestamp - expected):
         self.assertEqual(policy.ttl(response), expected)
コード例 #4
0
 def test_multiple_cache_control(self):
     '''Can walk through multiple cache control configs.'''
     response = mock.Mock(headers={'cache_control': 'foo, max-age=15'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 15)
コード例 #5
0
 def test_default_for_malformed_maxage(self):
     '''Returns the default when maxage cannot be parsed.'''
     response = mock.Mock(headers={'cache_control': 'max-age=not-a-number'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 20)
コード例 #6
0
 def test_max_age(self):
     '''Returns the parsed max-age.'''
     response = mock.Mock(headers={'cache_control': 'max-age=15'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 15)
コード例 #7
0
 def test_no_cache(self):
     '''Returns the minimum when no-cache present.'''
     response = mock.Mock(headers={'cache_control': 'no-cache'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 10)
コード例 #8
0
 def test_must_revalidate(self):
     '''Returns the minimum when must-revalidate present.'''
     response = mock.Mock(headers={'cache_control': 'must-revalidate'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 10)
コード例 #9
0
 def test_malformed_expires(self):
     '''Returns the default when the Expires header is malformed.'''
     response = mock.Mock(headers={'expires': 'not parseable as a date'})
     policy = ttl.HeaderWithDefaultPolicy(20, 10)
     self.assertEqual(policy.ttl(response), 20)