def testRaiseConfigurationErrorOnUnsupportedProtocol(self): # connection should never be used in this case. mock_conn = self.mox.CreateMockAnything() mock_conn.setopt(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes() self.mox.StubOutWithMock(pycurl, 'Curl') pycurl.Curl().AndReturn(mock_conn) self.mox.ReplayAll() source = httpsource.HttpFilesSource({}) self.assertRaises(error.ConfigurationError, httpsource.UpdateGetter().GetUpdates, source, 'ftp://test_url', None)
def testNoUpdatesForTemporaryFailure(self): mock_conn = self.mox.CreateMockAnything() mock_conn.setopt(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes() mock_conn.perform() mock_conn.getinfo(pycurl.RESPONSE_CODE).AndReturn(304) self.mox.StubOutWithMock(pycurl, 'Curl') pycurl.Curl().AndReturn(mock_conn) self.mox.ReplayAll() config = {} source = httpsource.HttpFilesSource(config) result = httpsource.UpdateGetter().GetUpdates(source, 'https://TEST_URL', 37) self.assertEquals(result, [])
def testAcceptHttpProtocol(self): mock_conn = self.mox.CreateMockAnything() mock_conn.setopt(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes() mock_conn.perform() # We use code 304 since it basically shortcuts to the end of the method. mock_conn.getinfo(pycurl.RESPONSE_CODE).AndReturn(304) self.mox.StubOutWithMock(pycurl, 'Curl') pycurl.Curl().AndReturn(mock_conn) self.mox.ReplayAll() config = {} source = httpsource.HttpFilesSource(config) result = httpsource.UpdateGetter().GetUpdates(source, 'http://TEST_URL', None) self.assertEqual([], result)
def testRetryOnErrorCodeResponse(self): config = {'retry_delay': 5, 'retry_max': 3} mock_conn = self.mox.CreateMockAnything() mock_conn.setopt(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes() mock_conn.perform().MultipleTimes() mock_conn.getinfo(pycurl.RESPONSE_CODE).MultipleTimes().AndReturn(400) self.mox.StubOutWithMock(time, 'sleep') time.sleep(5) time.sleep(5) self.mox.StubOutWithMock(pycurl, 'Curl') pycurl.Curl().AndReturn(mock_conn) self.mox.ReplayAll() source = httpsource.HttpFilesSource(config) self.assertRaises(error.SourceUnavailable, httpsource.UpdateGetter().GetUpdates, source, url='https://TEST_URL', since=None)
def testGetUpdatesWithoutTimestamp(self): mock_conn = self.mox.CreateMockAnything() mock_conn.setopt(mox.IgnoreArg(), mox.IgnoreArg()).MultipleTimes() mock_conn.perform() mock_conn.getinfo(pycurl.RESPONSE_CODE).AndReturn(200) mock_conn.getinfo(pycurl.INFO_FILETIME).AndReturn(-1) self.mox.StubOutWithMock(pycurl, 'Curl') pycurl.Curl().AndReturn(mock_conn) mock_map = self.mox.CreateMockAnything() getter = httpsource.UpdateGetter() self.mox.StubOutWithMock(getter, 'GetMap') getter.GetMap(cache_info=mox.IgnoreArg()).AndReturn(mock_map) self.mox.ReplayAll() config = {} source = httpsource.HttpFilesSource(config) result = getter.GetUpdates(source, 'https://TEST_URL', 1) self.assertEqual(mock_map, result)
def testFromHttpToTimestamp(self): expected_ts = 1259641025 http_ts = 'Tue, 01 Dec 2009 04:17:05 GMT' self.assertEquals( expected_ts, httpsource.UpdateGetter().FromHttpToTimestamp(http_ts))
def testFromTimestampToHttp(self): ts = 1259641025 expected_http_ts = 'Tue, 01 Dec 2009 04:17:05 GMT' self.assertEqual(expected_http_ts, httpsource.UpdateGetter().FromTimestampToHttp(ts))