def test_is_modified_tests_against_urlinfo_lastmod(self): resource_info = self._create_resource_info() fetcher = self._create_fetcher(resource_info) resource_info.last_indexed = to_utc(datetime(2014, 1, 1, 15, 30)) server_modified = to_utc(datetime(2014, 1, 1, 15, 30)) resource_info.url_info['lastmod'] = to_iso_datetime(server_modified) self.assertFalse( fetcher.is_modified(), "Equal modification dates should lead to resource being " "considered UNMODIFIED") server_modified = to_utc(datetime(2014, 1, 1, 15, 31)) resource_info.url_info['lastmod'] = to_iso_datetime(server_modified) self.assertTrue( fetcher.is_modified(), "Newer server modification date should lead to resource being " "considered MODIFIED") server_modified = to_utc(datetime(2014, 1, 1, 15, 29)) resource_info.url_info['lastmod'] = to_iso_datetime(server_modified) self.assertFalse( fetcher.is_modified(), "Older server modification date should lead to resource being " "considered UNMODIFIED")
def test_is_modified_tests_against_http_last_modified(self, request): resource_info = self._create_resource_info() fetcher = self._create_fetcher(resource_info) resource_info.last_indexed = to_utc(datetime(2014, 1, 1, 15, 30)) server_modified = to_utc(datetime(2014, 1, 1, 15, 30)) request.return_value = MockResponse( headers={'last-modified': to_http_datetime(server_modified)}) self.assertFalse( fetcher.is_modified(), "Equal modification dates should lead to resource being " "considered UNMODIFIED") server_modified = to_utc(datetime(2014, 1, 1, 15, 31)) request.return_value = MockResponse( headers={'last-modified': to_http_datetime(server_modified)}) self.assertTrue( fetcher.is_modified(), "Newer server modification date should lead to resource being " "considered MODIFIED") server_modified = to_utc(datetime(2014, 1, 1, 15, 29)) request.return_value = MockResponse( headers={'last-modified': to_http_datetime(server_modified)}) self.assertFalse( fetcher.is_modified(), "Older server modification date should lead to resource being " "considered UNMODIFIED")
def test_parses_rfc2616_http_date_to_utc_datetime(self): from_http = from_http_datetime dt = to_utc(datetime(2014, 6, 30, 15, 45, 30)) # Test parsing of the three formats described by RFC 2616 # RFC 1123 self.assertEquals(dt, from_http('Mon, 30 Jun 2014 15:45:30 GMT')) # RFC 850 self.assertEquals(dt, from_http('Monday, 30-Jun-14 15:45:30 GMT')) # ANSI C's asctime() Sun Nov 6 08:49:37 1994 self.assertEquals(dt, from_http('Mon Jun 30 15:45:30 2014')) # Test a date in winter as well to trigger any DST issues dt_s = to_utc(datetime(2014, 12, 31, 15, 45, 30)) self.assertEquals(dt_s, from_http('Wed, 31 Dec 2014 15:45:30 GMT'))
def test_falls_back_to_http_last_modified(self): extractor = LastModifiedExtractor() resource_info = ResourceInfo( url_info={}, headers={'last-modified': 'Wed, 31 Dec 2014 15:45:30 GMT'}) self.assertEquals(to_utc(datetime(2014, 12, 31, 15, 45, 30)), extractor.extract_value(resource_info))
def test_lastmod_from_urlinfo(self): extractor = LastModifiedExtractor() resource_info = ResourceInfo( url_info={'lastmod': '2014-12-31T16:45:30+01:00'}) self.assertEquals(to_utc(datetime(2014, 12, 31, 15, 45, 30)), extractor.extract_value(resource_info))
def test_is_modified_defaults_to_true(self, request): resource_info = self._create_resource_info() fetcher = self._create_fetcher(resource_info) resource_info.last_indexed = to_utc(datetime(2014, 1, 1, 15, 30)) self.assertTrue( fetcher.is_modified(), "is_modified() should default to True if last_indexed date " "is present, but no server modification date could be determined")
def test_converts_tz_aware_dt_to_utc(self): cet = timezone('CET') dt = datetime(2014, 12, 31, 16, 45, 30, tzinfo=cet) self.assertEquals(datetime(2014, 12, 31, 15, 45, 30, tzinfo=pytz.utc), to_utc(dt))
def test_parses_utc_iso_8601_to_utc_datetime(self): dt = to_utc(datetime(2014, 12, 31, 15, 45, 30)) self.assertEquals(dt, from_iso_datetime('2014-12-31T15:45:30Z')) self.assertEquals(dt, from_iso_datetime('2014-12-31T15:45:30')) self.assertEquals(dt, from_iso_datetime('2014-12-31T15:45:30+00:00')) self.assertEquals(dt, from_iso_datetime('2014-12-31T16:45:30+01:00'))
def test_assigns_utc_to_naive_dt(self): naive_dt = datetime(2014, 12, 31, 15, 45, 30) self.assertEquals(datetime(2014, 12, 31, 15, 45, 30, tzinfo=pytz.utc), to_utc(naive_dt))
def test_doesnt_change_dt_already_in_utc(self): dt = datetime(2014, 12, 31, 15, 45, 30, tzinfo=pytz.utc) self.assertEquals(dt, to_utc(dt))