def testMd5FileDownloadFails(self): """Test behavior when MD5 file fetch fails.""" self.mox.StubOutWithMock(cb_url_lib, 'Download') cb_url_lib.CheckResourceExistsWithMd5(self.name, self.md5name).AndReturn(False) cb_url_lib.Download(self.url).AndReturn(True) cb_url_lib.Download(self.md5url).AndReturn(False) self.mox.ReplayAll() self.assertRaises(BundlingError, cb_url_lib.DownloadCheckMd5, self.url, self.path, self.desc)
def testDownloadsCheckMd5Succeed(self): """Test behavior when fetch is entirely successful.""" self.mox.StubOutWithMock(cb_url_lib, 'Download') self.mox.StubOutWithMock(cb_url_lib, 'CheckMd5') cb_url_lib.CheckResourceExistsWithMd5(self.name, self.md5name).AndReturn(False) cb_url_lib.Download(self.url).AndReturn(True) cb_url_lib.Download(self.md5url).AndReturn(True) cb_url_lib.CheckMd5(self.name, self.md5name).AndReturn(True) self.mox.ReplayAll() expected = self.name actual = cb_url_lib.DownloadCheckMd5(self.url, self.path, self.desc) self.assertEqual(expected, actual)
def testUrlBad(self): """Verify clean return value when page does not open properly.""" os.path.join(IsA(str), IsA(str)).AndReturn('') urllib.urlopen('test_url').AndRaise(IOError) self.mox.ReplayAll() expected = False actual = cb_url_lib.Download(self.url) self.assertEqual(expected, actual)
def testGsdUrlFileCopyFails(self): """Verify return value when gsutil copy fails.""" test_result = CommandResult() test_result.returncode = -1 os.path.join(IsA(str), IsA(str)).AndReturn(self.named_file.name) cb_url_lib.RunCommand( ['gsutil', 'cp', self.gsd_url, self.named_file.name], redirect_stdout=True, redirect_stderr=True).AndReturn(test_result) self.mox.ReplayAll() self.assertFalse(cb_url_lib.Download(self.gsd_url))
def testGsdUrlGoodLocalFileOpenSucceeds(self): """Verify return value when GSD URL opens properly.""" test_result = CommandResult() test_result.returncode = 0 os.path.join(IsA(str), IsA(str)).AndReturn(self.named_file.name) cb_url_lib.RunCommand( ['gsutil', 'cp', self.gsd_url, self.named_file.name], redirect_stdout=True, redirect_stderr=True).AndReturn(test_result) self.mox.ReplayAll() self.assertTrue(cb_url_lib.Download(self.gsd_url))
def testLocalFileOpenFails(self): """Verify clean return value when local file fails to open.""" os.path.join(IsA(str), IsA(str)).AndReturn('') urllib.urlopen('test_url').AndReturn(self.test_file) self.mox.ReplayAll() self.assertFalse(cb_url_lib.Download(self.url))
def testUrlGoodLocalFileOpenSucceeds(self): """Verify return value when page opens properly.""" os.path.join(IsA(str), IsA(str)).AndReturn(self.named_file.name) urllib.urlopen('test_url').AndReturn(self.test_file) self.mox.ReplayAll() self.assertTrue(cb_url_lib.Download(self.url))