def has_no_external_connectivity(): """ Check condition for building the docs with Sphinx Sphinx will attempt to fetch the Python objects inventory during the build process. If for some reason, this test is being run on a machine that can not access that address simply because of network restrictions (or the developer may simply be on a plane) then it's better to SKIP the test than to give a false positive. """ try: download.url_open('http://docs.python.org/objects.inv') return False except Exception: return True
def get_content_by_encoding(url): """ Returns the content of the given URL, attempting to use server provided encoding. :rtype: str """ http_response = download.url_open(url) content_type = None encoding = None if hasattr(http_response, 'headers'): content_type = http_response.headers['Content-Type'] elif hasattr(http_response, 'getheader'): content_type = http_response.getheader('Content-Type') if content_type is not None: match = re.match(r'^[az\\].*\; charset\=(.*)$', content_type) if match is not None: encoding = match.group(1) content = http_response.read() if hasattr(content, 'decode'): if encoding is not None: content = content.decode(encoding) else: content = content.decode() # Python default encoding return content
def test(self): url = "https://api.cirrus-ci.com/github/avocado-framework/avocado.json" http_response = download.url_open(url) self.assertEqual(http_response.code, 200) content = http_response.read() data = json.loads(content) self.assertIn("status", data) self.assertEqual(data["status"], "passing")
def test_paramiko_ecsda_bug(self): # https://github.com/paramiko/paramiko/issues/243 # Problems with using ECDSA known_hosts keys when negotiation also # accepts RSA or DSS keys try: issue_url = 'https://api.github.com/repos/paramiko/paramiko/issues/243' issue = json.load(download.url_open(issue_url)) self.assertEqual(issue['state'], 'open', 'The issue %s is not open ' 'anymore. Please double check and, if already fixed, ' 'change the avocado.conf option ' '"reject_unknown_hosts" defaults to True.' % 'https://github.com/paramiko/paramiko/issues/243') except URLError as details: raise unittest.SkipTest(details)
def test_paramiko_ecsda_bug(self): # https://github.com/paramiko/paramiko/issues/243 # Problems with using ECDSA known_hosts keys when negotiation also # accepts RSA or DSS keys try: issue_url = 'https://api.github.com/repos/paramiko/paramiko/issues/243' issue = json.load(download.url_open(issue_url)) self.assertEqual(issue['state'], 'open', 'The issue %s is not open ' 'anymore. Please double check and, if already fixed, ' 'change the avocado.conf option ' '"reject_unknown_hosts" defaults to True.' % 'https://github.com/paramiko/paramiko/issues/243') except urllib2.URLError as details: raise unittest.SkipTest(details)
def test_inspektor_indent_bug(self): # https://github.com/avocado-framework/inspektor/issues/31 # Inspektor indent will poke inside a Python string and change its # content. This happened while writing selftests/unit/test_utils_cpu.py # with content from /proc/cpuinfo. Right now the indent check is disabled # on that file try: issue_url = 'https://api.github.com/repos/avocado-framework/inspektor/issues/31' issue = json.load(download.url_open(issue_url)) self.assertEqual(issue['state'], 'open', 'The issue %s is not open ' 'anymore. Please double check and, if already fixed, ' 'remove the selftests/unit/test_utils_cpu.py from ' 'the exclusion list of indent in selftests/checkall' % 'https://github.com/avocado-framework/inspektor/issues/31') except URLError as details: raise unittest.SkipTest(details)
def test_inspektor_indent_bug(self): # https://github.com/avocado-framework/inspektor/issues/31 # Inspektor indent will poke inside a Python string and change its # content. This happened while writing selftests/unit/test_utils_cpu.py # with content from /proc/cpuinfo. Right now the indent check is disabled # on that file try: issue_url = 'https://api.github.com/repos/avocado-framework/inspektor/issues/31' issue = json.load(download.url_open(issue_url)) self.assertEqual( issue['state'], 'open', 'The issue %s is not open ' 'anymore. Please double check and, if already fixed, ' 'remove the selftests/unit/test_utils_cpu.py from ' 'the exclusion list of indent in selftests/checkall' % 'https://github.com/avocado-framework/inspektor/issues/31') except URLError as details: raise unittest.SkipTest(details)
def get_content_by_encoding(url): """ Returns the content of the given URL, attempting to use server provided encoding. :param url: the url to be fetched :rtype: str :raises: URLError when the given url can not be retrieved """ http_response = download.url_open(url) content_type = None encoding = None if hasattr(http_response, 'headers'): content_type = http_response.headers['Content-Type'] elif hasattr(http_response, 'getheader'): content_type = http_response.getheader('Content-Type') if content_type is not None: match = re.match(r'^[az\\].*\; charset\=(.*)$', content_type) if match is not None: encoding = match.group(1) content = http_response.read() return astring.to_text(content, encoding)