Added runtest script
This commit is contained in:
parent
8a582e7a0f
commit
b07890c3b0
5 changed files with 78 additions and 38 deletions
|
@ -14,7 +14,7 @@
|
||||||
"watch-less": "watch 'npm run build-less' static/src/less/",
|
"watch-less": "watch 'npm run build-less' static/src/less/",
|
||||||
"watch": "npm run watch-less & npm run watch-images",
|
"watch": "npm run watch-less & npm run watch-images",
|
||||||
"clean": "rm -rf static/build collected-static/ node_modules/ env/",
|
"clean": "rm -rf static/build collected-static/ node_modules/ env/",
|
||||||
"test": "npm run lint && echo 'All NPM Tests Passed!'"
|
"test": "npm run lint"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
32
project/pages/tests.py
Normal file
32
project/pages/tests.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
|
|
||||||
|
class IndexTestCase(TestCase):
|
||||||
|
def test_accessable(self):
|
||||||
|
response = self.client.get(reverse('pages:index'))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class AboutWebsiteTestCase(TestCase):
|
||||||
|
def test_accessable(self):
|
||||||
|
response = self.client.get(reverse('pages:about-website'))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class AboutIndexTestCase(TestCase):
|
||||||
|
def test_accessable(self):
|
||||||
|
response = self.client.get(reverse('pages:about'))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
class Custom404TestCase(TestCase):
|
||||||
|
def test_accessable(self):
|
||||||
|
response = self.client.get(reverse('404'))
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
|
||||||
|
class NoJavascriptTestCase(TestCase):
|
||||||
|
def test_accessable(self):
|
||||||
|
response = self.client.get(reverse('no-js'))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
|
@ -1,4 +1,5 @@
|
||||||
coverage==4.0.3
|
coverage==4.0.3
|
||||||
|
colorama==0.3.6
|
||||||
Django==1.8.7
|
Django==1.8.7
|
||||||
dj-database-url==0.3.0
|
dj-database-url==0.3.0
|
||||||
django-bootstrap-form==3.2
|
django-bootstrap-form==3.2
|
||||||
|
|
53
runtests
53
runtests
|
@ -1,16 +1,51 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env python3
|
||||||
|
import coverage
|
||||||
|
import os, sys
|
||||||
|
import subprocess
|
||||||
|
from colorama import Fore, init
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
export PATH=env/bin:${PATH}
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
init(autoreset=True)
|
||||||
|
|
||||||
./scripts/check-coverage.py
|
bin_dir = os.path.abspath(os.path.join(sys.executable, os.path.pardir))
|
||||||
|
|
||||||
flake8 project scripts --ignore=E128,E501,E401 --exclude="migrations,settings,*/wsgi.py"
|
PERCENTAGE = 95
|
||||||
|
|
||||||
coverage html
|
cov = coverage.Coverage(
|
||||||
coverage report
|
source=["project"],
|
||||||
|
omit=["*/wsgi.py", "*/settings.py", "*/migrations/*.py", "*/__init__*"]
|
||||||
|
)
|
||||||
|
|
||||||
echo "All Python tests passed!"
|
cov.start()
|
||||||
|
print(Fore.YELLOW + "Running Tests...")
|
||||||
|
|
||||||
npm test
|
execute_from_command_line([sys.argv[0], 'test'])
|
||||||
|
|
||||||
|
cov.stop()
|
||||||
|
print(Fore.YELLOW + "Collecting Coverage...")
|
||||||
|
cov.save()
|
||||||
|
cov.html_report()
|
||||||
|
covered = cov.report()
|
||||||
|
if covered <= PERCENTAGE:
|
||||||
|
print(Fore.RED + "ERROR: Your coverage needs to be higher. Current coverage: {}%. Required: {}%.".format(covered, PERCENTAGE))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
print(Fore.GREEN + "Coverage Complete.")
|
||||||
|
|
||||||
|
FLAKE8_IGNORE = '--ignore=E128,E501,E401'
|
||||||
|
try:
|
||||||
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'project', FLAKE8_IGNORE, '--exclude=migrations,settings,wsgi.py'])
|
||||||
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), 'scripts', FLAKE8_IGNORE])
|
||||||
|
subprocess.check_output([os.path.join(bin_dir, 'flake8'), sys.argv[0], FLAKE8_IGNORE])
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(Fore.RED + e.output.decode())
|
||||||
|
exit(e.returncode)
|
||||||
|
|
||||||
|
|
||||||
|
print(Fore.GREEN + "All Python tests passed!")
|
||||||
|
|
||||||
|
os.system('npm test')
|
||||||
|
|
||||||
|
print(Fore.GREEN + "All Tests Passed!")
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
import coverage
|
|
||||||
import os
|
|
||||||
|
|
||||||
RED = "\033[31m"
|
|
||||||
GREEN = "\033[32m"
|
|
||||||
YELLOW = "\033[33m"
|
|
||||||
NORMAL = "\033[0m"
|
|
||||||
|
|
||||||
PERCENTAGE = 95
|
|
||||||
|
|
||||||
cov = coverage.Coverage(
|
|
||||||
source=["project"],
|
|
||||||
omit=["*/wsgi.py", "*/settings.py", "*/migrations/*.py", "*/__init__*"]
|
|
||||||
)
|
|
||||||
|
|
||||||
cov.start()
|
|
||||||
print(YELLOW + "Running Tests..." + NORMAL)
|
|
||||||
os.system('manage.py test')
|
|
||||||
cov.stop()
|
|
||||||
|
|
||||||
print(YELLOW + "Collecting Coverage..." + NORMAL)
|
|
||||||
covered = cov.report()
|
|
||||||
if covered <= PERCENTAGE:
|
|
||||||
print(RED + "ERROR: Your coverage needs to be higher. Current coverage: {}%. Required: {}%.".format(covered, PERCENTAGE) + NORMAL)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
print(GREEN + "Coverage Complete." + NORMAL)
|
|
Reference in a new issue