Commit ff600724 authored by Gaël Duval's avatar Gaël Duval 🏄🏼
Browse files

Merge branch 'nicofonk/fix-encoding' into 'master'

Revert wrong encoding changes

See merge request e/cloud/my-spot!23
parents c57f0c73 e9ba2366
...@@ -82,7 +82,7 @@ def request(query, params): ...@@ -82,7 +82,7 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
rss = etree.fromstring(resp.content.encode()) rss = etree.fromstring(resp.content)
ns = rss.nsmap ns = rss.nsmap
......
...@@ -65,7 +65,7 @@ def replace_pua_chars(text): ...@@ -65,7 +65,7 @@ def replace_pua_chars(text):
def response(resp): def response(resp):
results = [] results = []
search_results = etree.XML(resp.text.encode()) search_results = etree.XML(resp.text)
# return empty array if there are no results # return empty array if there are no results
if search_results.xpath(failure_xpath): if search_results.xpath(failure_xpath):
......
...@@ -33,13 +33,13 @@ class TestBingNewsEngine(TestCase): ...@@ -33,13 +33,13 @@ class TestBingNewsEngine(TestCase):
self.assertRaises(AttributeError, bing_news.response, '') self.assertRaises(AttributeError, bing_news.response, '')
self.assertRaises(AttributeError, bing_news.response, '[]') self.assertRaises(AttributeError, bing_news.response, '[]')
response = mock.Mock(content='<html></html>') response = mock.Mock(content=b'<html></html>')
self.assertEqual(bing_news.response(response), []) self.assertEqual(bing_news.response(response), [])
response = mock.Mock(content='<html></html>') response = mock.Mock(content=b'<html></html>')
self.assertEqual(bing_news.response(response), []) self.assertEqual(bing_news.response(response), [])
html = """<?xml version="1.0" encoding="utf-8" ?> html = b"""<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS"> <rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS">
<channel> <channel>
<title>python - Bing News</title> <title>python - Bing News</title>
...@@ -84,7 +84,7 @@ class TestBingNewsEngine(TestCase): ...@@ -84,7 +84,7 @@ class TestBingNewsEngine(TestCase):
self.assertEqual(results[1]['content'], 'Another Article Content') self.assertEqual(results[1]['content'], 'Another Article Content')
self.assertNotIn('img_src', results[1]) self.assertNotIn('img_src', results[1])
html = """<?xml version="1.0" encoding="utf-8" ?> html = b"""<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS"> <rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS">
<channel> <channel>
<title>python - Bing News</title> <title>python - Bing News</title>
...@@ -119,7 +119,7 @@ class TestBingNewsEngine(TestCase): ...@@ -119,7 +119,7 @@ class TestBingNewsEngine(TestCase):
self.assertEqual(results[0]['content'], 'Article Content') self.assertEqual(results[0]['content'], 'Article Content')
self.assertEqual(results[0]['img_src'], 'http://another.bing.com/image') self.assertEqual(results[0]['img_src'], 'http://another.bing.com/image')
html = """<?xml version="1.0" encoding="utf-8" ?> html = b"""<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS"> <rss version="2.0" xmlns:News="https://www.bing.com:443/news/search?q=python&amp;setmkt=en-US&amp;first=1&amp;format=RSS">
<channel> <channel>
<title>python - Bing News</title> <title>python - Bing News</title>
...@@ -138,6 +138,6 @@ class TestBingNewsEngine(TestCase): ...@@ -138,6 +138,6 @@ class TestBingNewsEngine(TestCase):
self.assertEqual(type(results), list) self.assertEqual(type(results), list)
self.assertEqual(len(results), 0) self.assertEqual(len(results), 0)
html = """<?xml version="1.0" encoding="utf-8" ?>gabarge""" html = b"""<?xml version="1.0" encoding="utf-8" ?>gabarge"""
response = mock.Mock(content=html) response = mock.Mock(content=html)
self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response) self.assertRaises(lxml.etree.XMLSyntaxError, bing_news.response, response)
...@@ -32,14 +32,14 @@ class TestWolframAlphaAPIEngine(TestCase): ...@@ -32,14 +32,14 @@ class TestWolframAlphaAPIEngine(TestCase):
request = Request(headers={'Referer': referer_url}) request = Request(headers={'Referer': referer_url})
# test failure # test failure
xml = '''<?xml version='1.0' encoding='UTF-8'?> xml = b'''<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='false' error='false' /> <queryresult success='false' error='false' />
''' '''
response = mock.Mock(text=xml) response = mock.Mock(text=xml)
self.assertEqual(wolframalpha_api.response(response), []) self.assertEqual(wolframalpha_api.response(response), [])
# test basic case # test basic case
xml = """<?xml version='1.0' encoding='UTF-8'?> xml = b"""<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true' <queryresult success='true'
error='false' error='false'
numpods='3' numpods='3'
...@@ -107,7 +107,7 @@ class TestWolframAlphaAPIEngine(TestCase): ...@@ -107,7 +107,7 @@ class TestWolframAlphaAPIEngine(TestCase):
self.assertIn('result_plaintext', results[1]['content']) self.assertIn('result_plaintext', results[1]['content'])
# test calc # test calc
xml = """<?xml version='1.0' encoding='UTF-8'?> xml = b"""<?xml version='1.0' encoding='UTF-8'?>
<queryresult success='true' <queryresult success='true'
error='false' error='false'
numpods='2' numpods='2'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment