summaryrefslogtreecommitdiff
path: root/tests/admin_scripts
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-02-08 12:38:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-11 12:23:26 +0100
commitd113b5a837f726d1c638d76c4e88445e6cd59fd5 (patch)
tree37191ed160b698bfbf81559b56735d3e83fd7f92 /tests/admin_scripts
parentf9ec777a826816e20e68021c0e73b5a76be650af (diff)
downloaddjango-d113b5a837f726d1c638d76c4e88445e6cd59fd5.tar.gz
Refs #33476 -- Made management commands use black.
Run black on generated files, if it is available on PATH.
Diffstat (limited to 'tests/admin_scripts')
-rwxr-xr-xtests/admin_scripts/custom_templates/project_template/manage.py-tpl6
-rw-r--r--tests/admin_scripts/tests.py21
2 files changed, 18 insertions, 9 deletions
diff --git a/tests/admin_scripts/custom_templates/project_template/manage.py-tpl b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
index d9843c433f..42a1fa6684 100755
--- a/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
+++ b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl
@@ -1,6 +1,6 @@
# The manage.py of the {{ project_name }} test project
# template context:
-project_name = '{{ project_name }}'
-project_directory = '{{ project_directory }}'
-secret_key = '{{ secret_key }}'
+project_name = "{{ project_name }}"
+project_directory = "{{ project_directory }}"
+secret_key = "{{ secret_key }}"
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 3d5902f768..9d2ca839d5 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -41,6 +41,8 @@ custom_templates_dir = os.path.join(os.path.dirname(__file__), "custom_templates
SYSTEM_CHECK_MSG = "System check identified no issues"
+HAS_BLACK = shutil.which("black")
+
class AdminScriptTestCase(SimpleTestCase):
def setUp(self):
@@ -732,7 +734,10 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class SettingsTestConfig(AppConfig)", content)
- self.assertIn("name = 'settings_test'", content)
+ self.assertIn(
+ 'name = "settings_test"' if HAS_BLACK else "name = 'settings_test'",
+ content,
+ )
def test_setup_environ_custom_template(self):
"directory: startapp creates the correct directory with a custom template"
@@ -754,7 +759,7 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py"), encoding="utf8") as f:
content = f.read()
self.assertIn("class こんにちはConfig(AppConfig)", content)
- self.assertIn("name = 'こんにちは'", content)
+ self.assertIn('name = "こんにちは"' if HAS_BLACK else "name = 'こんにちは'", content)
def test_builtin_command(self):
"""
@@ -2614,8 +2619,8 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
test_manage_py = os.path.join(testproject_dir, "manage.py")
with open(test_manage_py) as fp:
content = fp.read()
- self.assertIn("project_name = 'another_project'", content)
- self.assertIn("project_directory = '%s'" % testproject_dir, content)
+ self.assertIn('project_name = "another_project"', content)
+ self.assertIn('project_directory = "%s"' % testproject_dir, content)
def test_no_escaping_of_project_variables(self):
"Make sure template context variables are not html escaped"
@@ -2880,11 +2885,15 @@ class StartApp(AdminScriptTestCase):
with open(os.path.join(app_path, "apps.py")) as f:
content = f.read()
self.assertIn("class NewAppConfig(AppConfig)", content)
+ if HAS_BLACK:
+ test_str = 'default_auto_field = "django.db.models.BigAutoField"'
+ else:
+ test_str = "default_auto_field = 'django.db.models.BigAutoField'"
+ self.assertIn(test_str, content)
self.assertIn(
- "default_auto_field = 'django.db.models.BigAutoField'",
+ 'name = "new_app"' if HAS_BLACK else "name = 'new_app'",
content,
)
- self.assertIn("name = 'new_app'", content)
class DiffSettings(AdminScriptTestCase):