def take_action(self, parsed_args): LOG.info('Starting url access check for {0}'.format(parsed_args.urls)) try: api.check_urls(parsed_args.urls) except errors.UrlNotAvailable as e: sys.stdout.write(str(e)) raise e
def take_action(self, parsed_args): LOG.info('Starting url access check for {0}'.format(parsed_args.urls)) proxies = {} if parsed_args.http_proxy: proxies['http'] = parsed_args.http_proxy if parsed_args.https_proxy: proxies['https'] = parsed_args.https_proxy try: api.check_urls(parsed_args.urls, proxies=proxies or None, timeout=parsed_args.timeout) except errors.UrlNotAvailable as e: sys.stdout.write(str(e)) raise e
def test_check_urls(self, req_mocker): for url in self.urls: req_mocker.get(url, status_code=200) check_result = api.check_urls(self.urls) self.assertTrue(check_result)
def test_check_ftp_fail(self): with self.assertRaises(errors.UrlNotAvailable): api.check_urls(self.paths)
def test_check_ftp(self, _): check_result = api.check_urls(self.ftps, timeout=5) self.assertTrue(check_result)
def test_check_paths_fail(self, mock_exists): mock_exists.return_value = False with self.assertRaises(errors.UrlNotAvailable): api.check_urls(self.paths)
def test_check_paths(self, mock_exists): mock_exists.return_value = True check_result = api.check_urls(self.paths) self.assertTrue(check_result)
def test_check_urls_fail(self, req_mocker): for url in self.urls: req_mocker.get(url, status_code=404) with self.assertRaises(errors.UrlNotAvailable): api.check_urls(self.urls)
def check_url(self, url, http_proxy): try: return urlck.check_urls([url], proxies={'http': http_proxy}) except url_errors.UrlNotAvailable: return False