summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorsage <laymonage@gmail.com>2021-07-24 07:09:03 +0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-09-01 12:08:02 +0200
commit84c7c4a477eae5de394d036d7ba1e58a37e18b69 (patch)
tree226181586fa7134a6674517105c0699e0314615f /tests/admin_scripts
parent3686077d463685d383e14b4695eaaa2658919a42 (diff)
downloaddjango-84c7c4a477eae5de394d036d7ba1e58a37e18b69.tar.gz
Fixed #32309 -- Added --exclude option to startapp/startproject management commands.
Diffstat (limited to 'tests/admin_scripts')
-rw-r--r--tests/admin_scripts/tests.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index bed9c61b31..9467bf32c3 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -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):