summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_scripts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regressiontests/admin_scripts')
-rw-r--r--tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt2
-rw-r--r--tests/regressiontests/admin_scripts/models.py4
-rw-r--r--tests/regressiontests/admin_scripts/tests.py30
3 files changed, 29 insertions, 7 deletions
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 0000000000..873eaded88
--- /dev/null
+++ b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt
@@ -0,0 +1,2 @@
+Some non-ASCII text for testing ticket #18091:
+üäö €
diff --git a/tests/regressiontests/admin_scripts/models.py b/tests/regressiontests/admin_scripts/models.py
index da803d0174..cd96052098 100644
--- a/tests/regressiontests/admin_scripts/models.py
+++ b/tests/regressiontests/admin_scripts/models.py
@@ -1,11 +1,13 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index 546fa7d79c..2710f80929 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -1,8 +1,10 @@
+# -*- coding: utf-8 -*-
"""
A series of tests to establish that the command-line managment tools work as
advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
and default settings.py files.
"""
+from __future__ import unicode_literals
import os
import re
@@ -10,6 +12,7 @@ import shutil
import socket
import subprocess
import sys
+import codecs
from django import conf, bin, get_version
from django.conf import settings
@@ -71,6 +74,10 @@ class AdminScriptTestCase(unittest.TestCase):
os.remove(full_name + 'c')
except OSError:
pass
+ # Also remove a __pycache__ directory, if it exists
+ cache_name = os.path.join(test_dir, '__pycache__')
+ if os.path.isdir(cache_name):
+ shutil.rmtree(cache_name)
def _ext_backend_paths(self):
"""
@@ -110,14 +117,11 @@ class AdminScriptTestCase(unittest.TestCase):
python_path.extend(ext_backend_base_dirs)
os.environ[python_path_var_name] = os.pathsep.join(python_path)
- # Silence the DeprecationWarning caused by having a locale directory
- # in the project directory.
- cmd = [sys.executable, '-Wignore:::django.utils.translation', script]
-
# Move to the test directory and run
os.chdir(test_dir)
- out, err = subprocess.Popen(cmd + args,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
+ out, err = subprocess.Popen([sys.executable, script] + args,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+ universal_newlines=True).communicate()
# Restore the old environment
if old_django_settings_module:
@@ -1572,3 +1576,17 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
self.assertFalse(os.path.exists(testproject_dir))
+
+ def test_custom_project_template_with_non_ascii_templates(self):
+ "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content"
+ template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template')
+ args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject']
+ testproject_dir = os.path.join(test_dir, 'customtestproject')
+
+ out, err = self.run_django_admin(args)
+ self.addCleanup(shutil.rmtree, testproject_dir)
+ self.assertNoOutput(err)
+ self.assertTrue(os.path.isdir(testproject_dir))
+ path = os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')
+ self.assertEqual(codecs.open(path, 'r', 'utf-8').read(),
+ 'Some non-ASCII text for testing ticket #18091:\nüäö €\n')