def is_cache_hit(self, response): if response.status_code == 304: self._metric_fetch('304', logging.DEBUG) elif response.status_code == 226: self._metric_fetch('226') elif response_etag_match(self.feed, response): self._metric_fetch('manual-hash-match', logging.DEBUG) elif response_calculated_etag_match(self.feed, response): self._metric_fetch('home-made-hash-match', logging.DEBUG) else: self._metric_fetch('cache-miss') return False return True
def test_etag_no_matching_wo_etag(self): self.feed.etag = '' self.assertFalse(response_etag_match(self.feed, self.resp)) self.assertFalse(response_calculated_etag_match(self.feed, self.resp))
def test_etag_matching(self): self.resp.headers['etag'] = self.feed.etag = 'etag' self.assertTrue(response_etag_match(self.feed, self.resp)) self.assertFalse(response_calculated_etag_match(self.feed, self.resp))
def test_etag_matching_w_constructed_etag(self): self.feed.etag = 'jarr/"%s"' % to_hash('text') self.assertFalse(response_etag_match(self.feed, self.resp)) self.assertTrue(response_calculated_etag_match(self.feed, self.resp))