mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #25589 -- Allowed startapp/project to create apps with Unicode characters in the name.
This commit is contained in:
parent
ee66d8dd7d
commit
3f300efede
2 changed files with 42 additions and 11 deletions
|
@ -31,7 +31,7 @@ from django.test import (
|
|||
from django.test.runner import DiscoverRunner
|
||||
from django.utils._os import npath, upath
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import PY3, StringIO
|
||||
from django.utils.six import PY2, PY3, StringIO
|
||||
|
||||
custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates')
|
||||
|
||||
|
@ -633,6 +633,20 @@ class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
|||
self.assertTrue(os.path.exists(app_path))
|
||||
self.assertTrue(os.path.exists(os.path.join(app_path, 'api.py')))
|
||||
|
||||
@unittest.skipIf(PY2, "Python 2 doesn't support Unicode package names.")
|
||||
def test_startapp_unicode_name(self):
|
||||
"directory: startapp creates the correct directory with unicode characters"
|
||||
args = ['startapp', 'こんにちは']
|
||||
app_path = os.path.join(self.test_dir, 'こんにちは')
|
||||
out, err = self.run_django_admin(args, 'test_project.settings')
|
||||
self.addCleanup(shutil.rmtree, app_path)
|
||||
self.assertNoOutput(err)
|
||||
self.assertTrue(os.path.exists(app_path))
|
||||
with open(os.path.join(app_path, 'apps.py'), 'r') as f:
|
||||
content = f.read()
|
||||
self.assertIn("class こんにちはConfig(AppConfig)", content)
|
||||
self.assertIn("name = 'こんにちは'", content)
|
||||
|
||||
def test_builtin_command(self):
|
||||
"directory: django-admin builtin commands fail with an error when no settings provided"
|
||||
args = ['check', 'admin_scripts']
|
||||
|
@ -1887,8 +1901,18 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
|||
self.addCleanup(shutil.rmtree, testproject_dir, True)
|
||||
|
||||
out, err = self.run_django_admin(args)
|
||||
self.assertOutput(err, "Error: '%s' is not a valid project name. "
|
||||
"Please make sure the name begins with a letter or underscore." % bad_name)
|
||||
if PY2:
|
||||
self.assertOutput(
|
||||
err,
|
||||
"Error: '%s' is not a valid project name. Please make "
|
||||
"sure the name begins with a letter or underscore." % bad_name
|
||||
)
|
||||
else:
|
||||
self.assertOutput(
|
||||
err,
|
||||
"Error: '%s' is not a valid project name. Please make "
|
||||
"sure the name is a valid identifier." % bad_name
|
||||
)
|
||||
self.assertFalse(os.path.exists(testproject_dir))
|
||||
|
||||
def test_simple_project_different_directory(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue