Code

Ticket #18091: 18091-startproject-non-ascii-templates.2.diff

File 18091-startproject-non-ascii-templates.2.diff, 2.5 KB (added by akaihola, 2 years ago)

Added a non-ASCII template to the startproject tests

Line 
1diff --git a/django/core/management/templates.py b/django/core/management/templates.py
2index b2a1226..cf3d190 100644
3--- a/django/core/management/templates.py
4+++ b/django/core/management/templates.py
5@@ -156,7 +156,7 @@ class TemplateCommand(BaseCommand):
6                     content = template_file.read()
7                 if filename.endswith(extensions) or filename in extra_files:
8                     template = Template(content)
9-                    content = template.render(context)
10+                    content = template.render(context).encode('UTF-8')
11                 with open(new_path, 'w') as new_file:
12                     new_file.write(content)
13 
14diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt
15new file mode 100644
16index 0000000..873eade
17--- /dev/null
18+++ b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt
19@@ -0,0 +1,2 @@
20+Some non-ASCII text for testing ticket #18091:
21+üäö €
22diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
23index 4c4edbb..4b3ecf4 100644
24--- a/tests/regressiontests/admin_scripts/tests.py
25+++ b/tests/regressiontests/admin_scripts/tests.py
26@@ -1552,3 +1552,15 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
27         self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
28         self.assertFalse(os.path.exists(testproject_dir))
29 
30+    def test_custom_project_template_with_non_ascii_templates(self):
31+        "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
32+        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
33+        args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject']
34+        testproject_dir = os.path.join(test_dir, 'customtestproject')
35+
36+        out, err = self.run_django_admin(args)
37+        self.addCleanup(shutil.rmtree, testproject_dir)
38+        self.assertNoOutput(err)
39+        self.assertTrue(os.path.isdir(testproject_dir))
40+        self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(),
41+                         'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n')