def test_defaulting(self): self.assertFalse('expires' in extract_feed_info({})) self.assertFalse('expires' in extract_feed_info({'cache-control': ''})) self.assertFalse( 'expires' in extract_feed_info({'cache-control': 'garbage'})) self.assertFalse('expires' in extract_feed_info({'expires': ''})) self.assertFalse( 'expires' in extract_feed_info({'expires': 'garbage'}))
def test_extract_max_age(): max_age = conf.feed.max_expires / 2 headers = {'cache-control': 'garbage max-age=%d garbage' % max_age} assert_in_range( extract_feed_info(headers)['expires'], utc_now() + timedelta(seconds=max_age)) headers['expires'] = rfc_1123_utc(delta=timedelta(hours=12)) assert_in_range( extract_feed_info(headers)['expires'], utc_now() + timedelta(seconds=max_age))
def clean_feed(self, response, **info): """Will reset the errors counters on a feed that have known errors""" now = utc_now() info.update({'error_count': 0, 'last_error': None, 'last_retrieved': now, 'expires': None}) info.update(extract_feed_info(response.headers, response.text)) feed_permanently_redirected = response.history \ and self.feed.link != response.url \ and any(r.status_code in {301, 308} for r in response.history) if feed_permanently_redirected: logger.warning('%r: feed moved from %r to %r', self.feed, self.feed.link, response.url) info['link'] = response.url if info: FeedController(self.feed.user_id).update({'id': self.feed.id}, info)
def test_extract_naive_expires(): ok_delta = timedelta(seconds=conf.feed.max_expires / 2) headers = {'expires': (datetime.utcnow() + ok_delta).isoformat()} assert_in_range( extract_feed_info(headers)['expires'], utc_now() + ok_delta)
def test_extract_expires(): hours_off = int(conf.feed.max_expires / 60 / 60) headers = {'expires': rfc_1123_utc(delta=timedelta(hours=hours_off))} assert_in_range( extract_feed_info(headers)['expires'], utc_now() + timedelta(hours=hours_off))