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

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

Added a non-ASCII template to the startproject tests

  • django/core/management/templates.py

    diff --git a/django/core/management/templates.py b/django/core/management/templates.py
    index b2a1226..cf3d190 100644
    a b class TemplateCommand(BaseCommand):  
    156156                    content = template_file.read()
    157157                if filename.endswith(extensions) or filename in extra_files:
    158158                    template = Template(content)
    159                     content = template.render(context)
     159                    content = template.render(context).encode('UTF-8')
    160160                with open(new_path, 'w') as new_file:
    161161                    new_file.write(content)
    162162
  • new file tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt

    diff --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
    new file mode 100644
    index 0000000..873eade
    - +  
     1Some non-ASCII text for testing ticket #18091:
     2üäö €
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index 4c4edbb..4b3ecf4 100644
    a b class StartProject(LiveServerTestCase, AdminScriptTestCase):  
    15521552        self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
    15531553        self.assertFalse(os.path.exists(testproject_dir))
    15541554
     1555    def test_custom_project_template_with_non_ascii_templates(self):
     1556        "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
     1557        template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
     1558        args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject']
     1559        testproject_dir = os.path.join(test_dir, 'customtestproject')
     1560
     1561        out, err = self.run_django_admin(args)
     1562        self.addCleanup(shutil.rmtree, testproject_dir)
     1563        self.assertNoOutput(err)
     1564        self.assertTrue(os.path.isdir(testproject_dir))
     1565        self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(),
     1566                         'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n')
Back to Top