More unittests for checks (#73)
* Add test for dns_resolution * Add test for domain_variations * Add test for duplicate_content
This commit is contained in:
parent
57f8dea4e0
commit
c065da4957
|
@ -12,7 +12,7 @@ class Config(object):
|
|||
|
||||
@property
|
||||
def urls(self):
|
||||
return list(self._urls)
|
||||
return sorted(list(self._urls))
|
||||
|
||||
def add_url(self, url):
|
||||
self._urls.add(url)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import unittest
|
||||
from pprint import pprint
|
||||
|
||||
from checks import dns_resolution
|
||||
from checks.config import Config
|
||||
|
||||
class TestDNSResolution(unittest.TestCase):
|
||||
|
||||
def test_google(self):
|
||||
"""Resolves www.google.com"""
|
||||
url = 'https://www.google.com/'
|
||||
config = Config(urls=[url])
|
||||
checker = dns_resolution.Checker(config=config, previous_results={})
|
||||
result = checker.run()
|
||||
|
||||
self.assertIn(url, result)
|
||||
self.assertEqual(result[url]['hostname'], 'www.google.com')
|
||||
self.assertTrue(result[url], 'resolvable')
|
||||
self.assertIsInstance(result[url]['ipv4_addresses'], list)
|
||||
self.assertNotEqual(result[url]['ipv4_addresses'], [])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -0,0 +1,20 @@
|
|||
import unittest
|
||||
from pprint import pprint
|
||||
|
||||
from checks import domain_variations
|
||||
from checks.config import Config
|
||||
|
||||
|
||||
class TestDomainVariations(unittest.TestCase):
|
||||
|
||||
def test_simple(self):
|
||||
url = 'http://example.org/'
|
||||
config = Config(urls=[url])
|
||||
checker = domain_variations.Checker(config=config, previous_results={})
|
||||
checker.run()
|
||||
config_after = checker.config
|
||||
|
||||
self.assertEqual(config_after.urls, ['http://example.org/', 'http://www.example.org/'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -0,0 +1,56 @@
|
|||
import httpretty
|
||||
from httpretty import httprettified
|
||||
import unittest
|
||||
|
||||
from checks import duplicate_content
|
||||
from checks import page_content
|
||||
from checks.config import Config
|
||||
|
||||
@httprettified
|
||||
class TestDuplicateContent(unittest.TestCase):
|
||||
|
||||
def test_identical(self):
|
||||
page_body = """
|
||||
<html>
|
||||
<head>
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 class="title">Headline</h1>
|
||||
<p class="intro">Second paragraph with <strong>strong words</strong></p>
|
||||
<p class="text">Third paragraph</p>
|
||||
<ul class="somelist">
|
||||
<li>A list item</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
url1 = 'http://example.com/'
|
||||
httpretty.register_uri(httpretty.GET, url1, body=page_body)
|
||||
|
||||
url2 = 'http://www.example.com/'
|
||||
httpretty.register_uri(httpretty.GET, url2, body=page_body)
|
||||
|
||||
results = {}
|
||||
|
||||
config = Config(urls=[url1, url2])
|
||||
page_content_checker = page_content.Checker(config=config, previous_results={})
|
||||
results['page_content'] = page_content_checker.run()
|
||||
|
||||
checker = duplicate_content.Checker(config=page_content_checker.config,
|
||||
previous_results=results)
|
||||
result = checker.run()
|
||||
urls_after = checker.config.urls
|
||||
|
||||
self.assertEqual(result, {
|
||||
'http://example.com/ http://www.example.com/': {
|
||||
'exception': None,
|
||||
'similarity': 1.0
|
||||
}
|
||||
})
|
||||
self.assertEqual(urls_after, ['http://example.com/'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -18,6 +18,7 @@ class Checker(AbstractChecker):
|
|||
def run(self):
|
||||
assert 'page_content' in self.previous_results
|
||||
assert 'html_head' in self.previous_results
|
||||
assert 'dns_resolution' in self.previous_results
|
||||
|
||||
results = {}
|
||||
|
||||
|
@ -31,7 +32,6 @@ class Checker(AbstractChecker):
|
|||
page_content = self.previous_results['page_content'][url]
|
||||
assert 'content' in page_content
|
||||
|
||||
assert 'dns_resolution' in self.previous_results
|
||||
dns_resolution = self.previous_results['dns_resolution']
|
||||
|
||||
head = self.previous_results['html_head'][url]
|
||||
|
|
Loading…
Reference in New Issue