How to use get_content_by_encoding method in avocado

Best Python code snippet using avocado_python

test_thirdparty_bugs.py

Source:test_thirdparty_bugs.py Github

copy

Full Screen

...3import unittest4from six.moves.urllib.error import URLError5from avocado.utils import astring6from avocado.utils import download7def get_content_by_encoding(url):8 """9 Returns the content of the given URL, attempting to use server provided10 encoding.11 :param url: the url to be fetched12 :rtype: str13 :raises: URLError when the given url can not be retrieved14 """15 http_response = download.url_open(url)16 content_type = None17 encoding = None18 if hasattr(http_response, 'headers'):19 content_type = http_response.headers['Content-Type']20 elif hasattr(http_response, 'getheader'):21 content_type = http_response.getheader('Content-Type')22 if content_type is not None:23 match = re.match(r'^[az\\].*\; charset\=(.*)$', content_type)24 if match is not None:25 encoding = match.group(1)26 content = http_response.read()27 return astring.to_text(content, encoding)28class TestThirdPartyBugs(unittest.TestCase):29 """30 Class created to verify third-party known issues31 """32 def test_paramiko_ecsda_bug(self):33 # https://github.com/paramiko/paramiko/issues/24334 # Problems with using ECDSA known_hosts keys when negotiation also35 # accepts RSA or DSS keys36 try:37 issue_url = 'https://api.github.com/repos/paramiko/paramiko/issues/243'38 content = get_content_by_encoding(issue_url)39 except URLError as details:40 raise unittest.SkipTest(details)41 issue = json.loads(content)42 self.assertEqual(issue['state'], 'open', 'The issue %s is not open '43 'anymore. Please double check and, if already fixed, '44 'change the avocado.conf option '45 '"reject_unknown_hosts" defaults to True.' %46 'https://github.com/paramiko/paramiko/issues/243')47 def test_inspektor_indent_bug(self):48 # https://github.com/avocado-framework/inspektor/issues/3149 # Inspektor indent will poke inside a Python string and change its50 # content. This happened while writing selftests/unit/test_utils_cpu.py51 # with content from /proc/cpuinfo. Right now the indent check is disabled52 # on that file53 try:54 issue_url = 'https://api.github.com/repos/avocado-framework/inspektor/issues/31'55 content = get_content_by_encoding(issue_url)56 except URLError as details:57 raise unittest.SkipTest(details)58 issue = json.loads(content)59 self.assertEqual(issue['state'], 'open', 'The issue %s is not open '60 'anymore. Please double check and, if already fixed, '61 'remove the selftests/unit/test_utils_cpu.py from '62 'the exclusion list of indent in selftests/checkall' %63 'https://github.com/avocado-framework/inspektor/issues/31')64if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful