Trying to bulk up automated testing
This commit is contained in:
10
.travis.yml
10
.travis.yml
@@ -9,10 +9,20 @@ install:
|
|||||||
- docker build -t php .
|
- docker build -t php .
|
||||||
- docker run -d -p 127.0.0.1:80:80 --name nginx-php-fpm php
|
- docker run -d -p 127.0.0.1:80:80 --name nginx-php-fpm php
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- pip install -r requirements.txt
|
||||||
|
- pip install mock
|
||||||
|
- pip install requests
|
||||||
|
- pip install feedparser
|
||||||
|
- pip install coverage
|
||||||
|
- pip install coveralls
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- docker ps
|
- docker ps
|
||||||
- sleep 5
|
- sleep 5
|
||||||
- curl -I 127.0.0.1:80
|
- curl -I 127.0.0.1:80
|
||||||
|
- python tests.py
|
||||||
|
- coverage run tests.py
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
slack: ngineered:EIKJFrzibOe0TwUhLXNe8Q2Q
|
slack: ngineered:EIKJFrzibOe0TwUhLXNe8Q2Q
|
||||||
|
|||||||
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
jinja2
|
||||||
|
PyYaml
|
||||||
|
mistune
|
||||||
|
markdown
|
||||||
|
pygments
|
||||||
22
tests.py
Normal file
22
tests.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
''' test runner '''
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def run_functional_tests():
|
||||||
|
''' Execute Functional Tests '''
|
||||||
|
tests = unittest.TestLoader().discover('tests/functional')
|
||||||
|
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
||||||
|
return result.wasSuccessful()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
print "#" * 70
|
||||||
|
print "Test Runner: Functional tests"
|
||||||
|
print "#" * 70
|
||||||
|
functional_results = run_functional_tests()
|
||||||
|
|
||||||
|
if functional_results:
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
sys.exit(1)
|
||||||
62
tests/functional/test_content.py
Normal file
62
tests/functional/test_content.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
''' Crawl site and validate every page renders somewhat correctly '''
|
||||||
|
import unittest
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
|
||||||
|
class ContentTest(unittest.TestCase):
|
||||||
|
''' Run a functional test to validate content being served '''
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
''' Create some starter data to be used in tests '''
|
||||||
|
self.domain = "http://127.0.0.1"
|
||||||
|
self.search_string = "Version"
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
''' Destroy starter data '''
|
||||||
|
self.domain = None
|
||||||
|
self.search_string = "None"
|
||||||
|
|
||||||
|
def request_recurse(self, url, requested=None):
|
||||||
|
''' recursively request each page checking the return code and urls '''
|
||||||
|
counts = {
|
||||||
|
'pass' : 0,
|
||||||
|
'fail' : 0,
|
||||||
|
}
|
||||||
|
if requested is None:
|
||||||
|
requested = []
|
||||||
|
if url in requested:
|
||||||
|
return counts, requested
|
||||||
|
else:
|
||||||
|
requested.append(url)
|
||||||
|
url = self.domain + url
|
||||||
|
results = requests.get(url, allow_redirects=True, verify=False)
|
||||||
|
if self.search_string in results.text:
|
||||||
|
counts['pass'] = counts['pass'] + 1
|
||||||
|
else:
|
||||||
|
counts['fail'] = counts['fail'] + 1
|
||||||
|
urls = re.findall(
|
||||||
|
'href="/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
|
||||||
|
results.text
|
||||||
|
)
|
||||||
|
for url in urls:
|
||||||
|
url = url.lstrip('href="')
|
||||||
|
if "/static/" not in url:
|
||||||
|
if "//" not in url:
|
||||||
|
results, requested = self.request_recurse(url, requested=requested)
|
||||||
|
# Add counts for status codes
|
||||||
|
for key in results.keys():
|
||||||
|
if key in counts:
|
||||||
|
counts[key] = counts[key] + results[key]
|
||||||
|
else:
|
||||||
|
counts[key] = results[key]
|
||||||
|
return counts, requested
|
||||||
|
|
||||||
|
class CrawlSite(ContentTest):
|
||||||
|
''' Verify no broken links are present within blog '''
|
||||||
|
def runTest(self):
|
||||||
|
''' Execute recursive request '''
|
||||||
|
results, requested_pages = self.request_recurse("/")
|
||||||
|
self.assertFalse(
|
||||||
|
results['fail'] > 0,
|
||||||
|
"Found {0} pages that did not return keyword".format(results['fail'])
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user