summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-02-14 23:45:32 +0000
committerJannis Leidel <jannis@leidel.info>2011-02-14 23:45:32 +0000
commit64a0a33c33079fa8ea79f1935d2a56281427e0f0 (patch)
treeedc42e70a22522c09bedd55105f58d0aae482969 /tests
parent6eacbfd4111127c0cfc5e9272ef4553a163ed7df (diff)
Fixed the staticfiles management commands collectstatic and findstatic to not raise encoding related exceptions when handlings filenames with non-ASCII characters.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15538 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/staticfiles_tests/apps/test/static/test/speçial.txt1
-rw-r--r--tests/regressiontests/staticfiles_tests/tests.py19
2 files changed, 15 insertions, 5 deletions
diff --git a/tests/regressiontests/staticfiles_tests/apps/test/static/test/speçial.txt b/tests/regressiontests/staticfiles_tests/apps/test/static/test/speçial.txt
new file mode 100644
index 0000000000..5da2e16831
--- /dev/null
+++ b/tests/regressiontests/staticfiles_tests/apps/test/static/test/speçial.txt
@@ -0,0 +1 @@
+speçial in the app dir \ No newline at end of file
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 0ceb11bafd..0e73e48480 100644
--- a/tests/regressiontests/staticfiles_tests/tests.py
+++ b/tests/regressiontests/staticfiles_tests/tests.py
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+import codecs
import os
import posixpath
import shutil
@@ -11,6 +13,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
from django.core.management import call_command
from django.test import TestCase
+from django.utils.encoding import smart_unicode
from django.utils._os import rmtree_errorhandler
@@ -72,8 +75,8 @@ class StaticFilesTestCase(TestCase):
settings.INSTALLED_APPS = self.old_installed_apps
def assertFileContains(self, filepath, text):
- self.assertTrue(text in self._get_file(filepath),
- "'%s' not in '%s'" % (text, filepath))
+ self.assertTrue(text in self._get_file(smart_unicode(filepath)),
+ u"'%s' not in '%s'" % (text, filepath))
def assertFileNotFound(self, filepath):
self.assertRaises(IOError, self._get_file, filepath)
@@ -108,7 +111,7 @@ class BuildStaticTestCase(StaticFilesTestCase):
def _get_file(self, filepath):
assert filepath, 'filepath is empty.'
filepath = os.path.join(settings.STATIC_ROOT, filepath)
- f = open(filepath)
+ f = codecs.open(filepath, "r", "utf-8")
try:
return f.read()
finally:
@@ -140,10 +143,16 @@ class TestDefaults(object):
def test_app_files(self):
"""
- Can find a file in an app media/ directory.
+ Can find a file in an app static/ directory.
"""
self.assertFileContains('test/file1.txt', 'file1 in the app dir')
+ def test_nonascii_filenames(self):
+ """
+ Can find a file with non-ASCII character in an app static/ directory.
+ """
+ self.assertFileContains(u'test/speçial.txt', u'speçial in the app dir')
+
class TestFindStatic(BuildStaticTestCase, TestDefaults):
"""
@@ -156,7 +165,7 @@ class TestFindStatic(BuildStaticTestCase, TestDefaults):
call_command('findstatic', filepath, all=False, verbosity='0')
sys.stdout.seek(0)
lines = [l.strip() for l in sys.stdout.readlines()]
- contents = open(lines[1].strip()).read()
+ contents = codecs.open(lines[1].strip(), "r", "utf-8").read()
finally:
sys.stdout = _stdout
return contents