From b07890c3b0aa795fba2e88986b00ed47734206f0 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 10 Jan 2016 16:12:58 +0000 Subject: [PATCH] Added runtest script --- package.json | 2 +- project/pages/tests.py | 32 +++++++++++++++++++++++ requirements.txt | 1 + runtests | 53 ++++++++++++++++++++++++++++++++------- scripts/check-coverage.py | 28 --------------------- 5 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 project/pages/tests.py delete mode 100755 scripts/check-coverage.py diff --git a/package.json b/package.json index b045ecb..9a7fd10 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "watch-less": "watch 'npm run build-less' static/src/less/", "watch": "npm run watch-less & npm run watch-images", "clean": "rm -rf static/build collected-static/ node_modules/ env/", - "test": "npm run lint && echo 'All NPM Tests Passed!'" + "test": "npm run lint" }, "repository": { "type": "git", diff --git a/project/pages/tests.py b/project/pages/tests.py new file mode 100644 index 0000000..4aa97db --- /dev/null +++ b/project/pages/tests.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 7b1fbd3..a4bba44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ coverage==4.0.3 +colorama==0.3.6 Django==1.8.7 dj-database-url==0.3.0 django-bootstrap-form==3.2 diff --git a/runtests b/runtests index 77498b2..7bc9f9a 100755 --- a/runtests +++ b/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 -coverage report +cov = coverage.Coverage( + 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!") diff --git a/scripts/check-coverage.py b/scripts/check-coverage.py deleted file mode 100755 index 136417f..0000000 --- a/scripts/check-coverage.py +++ /dev/null @@ -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)