def testHttpUrlNoMatch(self): """Verify None returned when MatchUrl() returns None.""" with open('testdata/test_page_no_links.html', 'r') as test_page: urllib.urlopen('test_url').AndReturn(test_page) self.mox.ReplayAll() actual = cb_url_lib.DetermineUrl(self.url, self.pattern) self.assertEqual(None, actual)
def testUrlBad(self): """Verify clean return value when determining URL fails.""" cb_url_lib.DetermineUrl(self.url, self.pattern).AndReturn(None) self.mox.ReplayAll() self.assertRaises(cb_url_lib.NameResolutionError, cb_url_lib.DetermineThenDownloadCheckMd5, self.url, self.pattern, self.path, self.desc)
def testHttpUrlGood(self): """Verify URL returned when page opens properly.""" with open('testdata/test_page_many_links.html', 'r') as test_page: urllib.urlopen('test_url').AndReturn(test_page) self.mox.ReplayAll() expected = 'test_url/ChromeOS-0.12.433.269-r72d7eaa2-b198-x86-alex.zip' actual = cb_url_lib.DetermineUrl(self.url, self.pattern) self.assertEqual(expected, actual)
def testUrlGood(self): """Verify return value when determining URL succeeds.""" self.mox.StubOutWithMock(cb_url_lib, 'DownloadCheckMd5') cb_url_lib.DetermineUrl(self.url, self.pattern).AndReturn(self.url) cb_url_lib.DownloadCheckMd5(self.url, self.path, self.desc).AndReturn('name') self.mox.ReplayAll() expected = 'name' actual = cb_url_lib.DetermineThenDownloadCheckMd5( self.url, self.pattern, self.path, self.desc) self.assertEqual(expected, actual)
def testGsdUrlRunCommandError(self): """Verify None returned when RunCommand returns non-zero code.""" test_result = CommandResult() test_result.returncode = -1 cb_url_lib.RunCommand(['gsutil', 'ls', self.gsd_url], redirect_stdout=True, redirect_stderr=True).AndReturn(test_result) self.mox.ReplayAll() actual = cb_url_lib.DetermineUrl(self.http_url, self.gsd_pattern) self.assertEqual(None, actual)
def testGsdUrlNoMatch(self): """Verify None returned when MatchUrl() returns None.""" with open('testdata/test_page_many_links.html', 'r') as test_page: test_result = CommandResult() test_result.output = test_page.read() test_result.returncode = 0 cb_url_lib.RunCommand(['gsutil', 'ls', self.gsd_url], redirect_stdout=True, redirect_stderr=True).AndReturn(test_result) self.mox.ReplayAll() actual = cb_url_lib.DetermineUrl(self.http_url, self.gsd_pattern) self.assertEqual(None, actual)
def testGsdUrlGood(self): """Verify GSD URL returned when page opens properly.""" with open('testdata/test_page_gsd_links.html', 'r') as test_page: test_result = CommandResult() test_result.output = test_page.read() test_result.returncode = 0 cb_url_lib.RunCommand(['gsutil', 'ls', self.gsd_url], redirect_stdout=True, redirect_stderr=True).AndReturn(test_result) self.mox.ReplayAll() expected = ( 'gs://chromeos-releases/stable-channel/x86-alex/0.12.433.269/' 'chromeos_0.12.433.269_x86-alex_recovery_stable-channel_mp-v3.bin') actual = cb_url_lib.DetermineUrl(self.http_url, self.gsd_pattern) self.assertEqual(expected, actual)
def testHttpUrlBad(self): """Verify None returned when page fails to open properly.""" urllib.urlopen('test_url').AndRaise(IOError) self.mox.ReplayAll() actual = cb_url_lib.DetermineUrl(self.url, self.pattern) self.assertEqual(None, actual)