未验证 提交 1cdc7ae4 编写于 作者: A Amador Pahim

Merge branch 'clebergnu-python34_json_from_http'

Signed-off-by: NAmador Pahim <apahim@redhat.com>
import re
import json
import unittest
......@@ -9,6 +10,33 @@ except ImportError:
from avocado.utils import download
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
class TestThirdPartyBugs(unittest.TestCase):
"""
Class created to verify third-party known issues
......@@ -20,7 +48,8 @@ class TestThirdPartyBugs(unittest.TestCase):
# 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))
content = get_content_by_encoding(issue_url)
issue = json.loads(content)
self.assertEqual(issue['state'], 'open', 'The issue %s is not open '
'anymore. Please double check and, if already fixed, '
'change the avocado.conf option '
......@@ -37,7 +66,8 @@ class TestThirdPartyBugs(unittest.TestCase):
# on that file
try:
issue_url = 'https://api.github.com/repos/avocado-framework/inspektor/issues/31'
issue = json.load(download.url_open(issue_url))
content = get_content_by_encoding(issue_url)
issue = json.loads(content)
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 '
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册