Skip to content

Commit

Permalink
test case updates for new command_line package
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7 committed Jun 23, 2015
1 parent 5605de1 commit 5d95f5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion djangui/backend/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion djangui/conf/project_template/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def process_response(self, request, response):
sys.stderr.write('{}'.format('\n'.join(traceback.format_exc())))
except AttributeError:
pass
return response
return response
21 changes: 14 additions & 7 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
__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)
env['TESTING'] = 'True'

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)
Expand All @@ -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)
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)

0 comments on commit 5d95f5e

Please sign in to comment.