Add basic test for check_content
This commit is contained in:
parent
9bea186008
commit
e09bf7a4d4
35
test.py
35
test.py
|
@ -1,4 +1,6 @@
|
|||
import unittest
|
||||
import requests
|
||||
import responses
|
||||
import spider
|
||||
|
||||
class TestSpider(unittest.TestCase):
|
||||
|
@ -24,6 +26,39 @@ class TestSpider(unittest.TestCase):
|
|||
result = spider.reduce_urls(testdata)
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
@responses.activate
|
||||
def test_check_content1(self):
|
||||
"""
|
||||
Very basic test of our content analysis function
|
||||
"""
|
||||
url = 'http://my.url'
|
||||
responses.add(responses.GET, url, status=200,
|
||||
content_type='text/html',
|
||||
body='''
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>The title</title>
|
||||
</head>
|
||||
</html>
|
||||
''')
|
||||
r = requests.get(url)
|
||||
result = spider.check_content(r)
|
||||
|
||||
del result['html'] # don't want to have the messy HTML part in comparison
|
||||
|
||||
expected_result = {
|
||||
'icon': None,
|
||||
'title': 'The title',
|
||||
'generator': None,
|
||||
'feeds': [],
|
||||
'encoding': 'ISO-8859-1',
|
||||
'canonical_link': None,
|
||||
'opengraph': None
|
||||
}
|
||||
self.assertDictEqual(result, expected_result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue