Fixed #32309 -- Added --exclude option to startapp/startproject management commands.

This commit is contained in:
sage 2021-07-24 07:09:03 +07:00 committed by Mariusz Felisiak
parent 3686077d46
commit 84c7c4a477
4 changed files with 100 additions and 1 deletions

View file

@ -2232,6 +2232,70 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
hidden_dir = os.path.join(testproject_dir, '.hidden')
self.assertIs(os.path.exists(hidden_dir), False)
def test_custom_project_template_hidden_directory_included(self):
"""
Template context variables in hidden directories are rendered, if not
excluded.
"""
template_path = os.path.join(custom_templates_dir, 'project_template')
project_name = 'custom_project_template_hidden_directories_included'
args = [
'startproject',
'--template',
template_path,
project_name,
'project_dir',
'--exclude',
]
testproject_dir = os.path.join(self.test_dir, 'project_dir')
os.mkdir(testproject_dir)
_, err = self.run_django_admin(args)
self.assertNoOutput(err)
render_py_path = os.path.join(testproject_dir, '.hidden', 'render.py')
with open(render_py_path) as fp:
self.assertIn(
f'# The {project_name} should be rendered.',
fp.read(),
)
def test_custom_project_template_exclude_directory(self):
"""
Excluded directories (in addition to .git and __pycache__) are not
included in the project.
"""
template_path = os.path.join(custom_templates_dir, 'project_template')
project_name = 'custom_project_with_excluded_directories'
args = [
'startproject',
'--template',
template_path,
project_name,
'project_dir',
'--exclude',
'additional_dir',
'-x',
'.hidden',
]
testproject_dir = os.path.join(self.test_dir, 'project_dir')
os.mkdir(testproject_dir)
_, err = self.run_django_admin(args)
self.assertNoOutput(err)
excluded_directories = [
'.hidden',
'additional_dir',
'.git',
'__pycache__',
]
for directory in excluded_directories:
self.assertIs(
os.path.exists(os.path.join(testproject_dir, directory)),
False,
)
not_excluded = os.path.join(testproject_dir, project_name)
self.assertIs(os.path.exists(not_excluded), True)
class StartApp(AdminScriptTestCase):