mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-05-01 16:44:51 +02:00
Add unit test for charset checker
This commit is contained in:
parent
7b2c3c15ff
commit
c8b55e93ec
49
checks/charset_test.py
Normal file
49
checks/charset_test.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import httpretty
|
||||
from httpretty import httprettified
|
||||
import unittest
|
||||
|
||||
from checks import charset
|
||||
from checks import page_content
|
||||
from checks.config import Config
|
||||
|
||||
@httprettified
|
||||
class TestCharsetChecker(unittest.TestCase):
|
||||
|
||||
def test_http_response(self):
|
||||
url = 'http://www.example.com/'
|
||||
httpretty.register_uri(httpretty.GET, url,
|
||||
body="""<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" value="text/html; charset=foo">
|
||||
<meta charset="utf-8">
|
||||
<title>Hello</title>
|
||||
</head>
|
||||
</html>""",
|
||||
adding_headers={
|
||||
"Content-Type": "text/html; charset=ISO-8859-1",
|
||||
})
|
||||
|
||||
results = {}
|
||||
|
||||
config = Config(urls=[url])
|
||||
page_content_checker = page_content.Checker(config=config, previous_results={})
|
||||
results['page_content'] = page_content_checker.run()
|
||||
|
||||
self.assertIn(url, results['page_content'])
|
||||
self.assertIn('response_headers', results['page_content'][url])
|
||||
self.assertIn('content-type', results['page_content'][url]['response_headers'])
|
||||
|
||||
charset_checker = charset.Checker(config=page_content_checker.config, previous_results=results)
|
||||
result = charset_checker.run()
|
||||
|
||||
self.assertIn(url, result)
|
||||
self.assertEqual(result[url], {
|
||||
'meta_charset_tag': 'utf-8',
|
||||
'content_type_header_charset': 'iso-8859-1',
|
||||
'charset': 'utf-8',
|
||||
'valid': True,
|
||||
'exception': None,
|
||||
})
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in a new issue