From 5d95f5e2efaf88f1ecba6b04f87d3867fd50e02c Mon Sep 17 00:00:00 2001 From: Chris Mitchell Date: Tue, 23 Jun 2015 12:50:08 -0400 Subject: [PATCH] test case updates for new command_line package --- Makefile | 4 ++-- djangui/backend/command_line.py | 1 - djangui/conf/project_template/middleware.py | 2 +- tests/test_project.py | 21 ++++++++++++++------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 0ab1ead..0e4f9b9 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,6 @@ testenv: pip install -e . test: - nosetests tests - coverage run --branch --source=djangui --omit=djangui/conf*,djangui/migrations*,djangui/tests*,djangui/backend/ast* `which django-admin.py` test --settings=djangui.test_settings djangui.tests + nosetests --with-coverage --cover-erase --cover-package=djangui tests + coverage run --append --branch --source=djangui --omit=djangui/conf*,djangui/migrations*,djangui/tests*,djangui/backend/ast* `which django-admin.py` test --settings=djangui.test_settings djangui.tests coverage report diff --git a/djangui/backend/command_line.py b/djangui/backend/command_line.py index 04eeca0..5f0f9b5 100644 --- a/djangui/backend/command_line.py +++ b/djangui/backend/command_line.py @@ -86,4 +86,3 @@ def bootstrap(): sys.stdout.write("Please enter the project directory {0}, and run python manage.py createsuperuser and" " python manage.py runserver to start. The admin can be found at localhost:8000/admin. You may also want to set your " "DJANGO_SETTINGS_MODULE environment variable to {0}.settings \n".format(project_name)) - sys.exit(0) diff --git a/djangui/conf/project_template/middleware.py b/djangui/conf/project_template/middleware.py index 8ead019..853cb1a 100644 --- a/djangui/conf/project_template/middleware.py +++ b/djangui/conf/project_template/middleware.py @@ -9,4 +9,4 @@ def process_response(self, request, response): sys.stderr.write('{}'.format('\n'.join(traceback.format_exc()))) except AttributeError: pass - return response \ No newline at end of file + return response diff --git a/tests/test_project.py b/tests/test_project.py index 1c8f107..b5683e7 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -1,15 +1,17 @@ __author__ = 'chris' from unittest import TestCase -import subprocess import os +import subprocess import shutil +import sys +from djangui.backend import command_line BASE_DIR = os.path.split(__file__)[0] -DJANGUI_SCRIPT_PATH = os.path.join(BASE_DIR, '..', 'scripts', 'djanguify.py') +DJANGUI_SCRIPT_PATH = os.path.join(BASE_DIR, '..', 'scripts', 'djanguify') DJANGUI_TEST_PROJECT_NAME = 'djangui_project' DJANGUI_TEST_PROJECT_PATH = os.path.join(BASE_DIR, DJANGUI_TEST_PROJECT_NAME) DJANGUI_TEST_PROJECT_MANAGE = os.path.join(DJANGUI_TEST_PROJECT_PATH, 'manage.py') -PYTHON_INTERPRETTER = 'python' +PYTHON_INTERPRETTER = sys.executable env = os.environ env['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(DJANGUI_TEST_PROJECT_NAME) @@ -17,6 +19,7 @@ class TestProject(TestCase): def setUp(self): + os.chdir(BASE_DIR) # if old stuff exists, remove it if os.path.exists(DJANGUI_TEST_PROJECT_PATH): shutil.rmtree(DJANGUI_TEST_PROJECT_PATH) @@ -26,7 +29,11 @@ def tearDown(self): shutil.rmtree(DJANGUI_TEST_PROJECT_PATH) def test_bootstrap(self): - proc = subprocess.Popen([PYTHON_INTERPRETTER, DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME], - cwd=BASE_DIR, env=env, stderr=subprocess.PIPE) - stdout, stderr = proc.communicate() - self.assertEqual(proc.returncode, 0, msg=stderr) \ No newline at end of file + sys.argv = [DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME] + ret = command_line.bootstrap() + self.assertIsNone(ret) + # test our script is executable from the command line, it will fail with return code of 1 since + # the project already exists + proc = subprocess.Popen([PYTHON_INTERPRETTER, DJANGUI_SCRIPT_PATH, '-p', DJANGUI_TEST_PROJECT_NAME]) + stdout, stderr = proc.communicate() + self.assertEqual(proc.returncode, 1, stderr) \ No newline at end of file