summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/contrib/staticfiles/finders.py4
-rw-r--r--django/contrib/staticfiles/views.py1
-rw-r--r--tests/regressiontests/staticfiles_tests/tests.py42
3 files changed, 22 insertions, 25 deletions
diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
index ca0a248a39..a43412c499 100644
--- a/django/contrib/staticfiles/finders.py
+++ b/django/contrib/staticfiles/finders.py
@@ -79,7 +79,7 @@ class FileSystemFinder(BaseFinder):
absolute path (or ``None`` if no match).
"""
if prefix:
- prefix = '%s/' % prefix
+ prefix = '%s%s' % (prefix, os.sep)
if not path.startswith(prefix):
return None
path = path[len(prefix):]
@@ -144,7 +144,7 @@ class AppDirectoriesFinder(BaseFinder):
storage = self.storages[app]
prefix = storage.get_prefix()
if prefix:
- prefix = '%s/' % prefix
+ prefix = '%s%s' % (prefix, os.sep)
if not path.startswith(prefix):
return None
path = path[len(prefix):]
diff --git a/django/contrib/staticfiles/views.py b/django/contrib/staticfiles/views.py
index 694591c996..f5a6ec3dae 100644
--- a/django/contrib/staticfiles/views.py
+++ b/django/contrib/staticfiles/views.py
@@ -47,6 +47,7 @@ def serve(request, path, document_root=None, show_indexes=False, insecure=False)
"the --insecure option of 'runserver' is "
"used")
if not document_root:
+ path = os.path.normpath(path)
absolute_path = finders.find(path)
if not absolute_path:
raise Http404('"%s" could not be found' % path)
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 6a2825fed9..35ee74393b 100644
--- a/tests/regressiontests/staticfiles_tests/tests.py
+++ b/tests/regressiontests/staticfiles_tests/tests.py
@@ -15,7 +15,8 @@ from django.template import Template, Context
from django.test import TestCase
-TEST_ROOT = os.path.dirname(__file__)
+TEST_ROOT = os.path.normcase(os.path.dirname(__file__))
+
class StaticFilesTestCase(TestCase):
"""
@@ -51,8 +52,8 @@ class StaticFilesTestCase(TestCase):
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
settings.INSTALLED_APPS = [
- "django.contrib.staticfiles",
- "regressiontests.staticfiles_tests",
+ 'django.contrib.staticfiles',
+ 'regressiontests.staticfiles_tests',
]
# Clear the cached default_storage out, this is because when it first
@@ -121,7 +122,6 @@ class TestDefaults(object):
def test_staticfiles_dirs(self):
"""
Can find a file in a STATICFILES_DIRS directory.
-
"""
self.assertFileContains('test.txt', 'Can we find')
@@ -129,21 +129,18 @@ class TestDefaults(object):
"""
Can find a file in a subdirectory of a STATICFILES_DIRS
directory.
-
"""
self.assertFileContains('subdir/test.txt', 'Can we find')
def test_staticfiles_dirs_priority(self):
"""
File in STATICFILES_DIRS has priority over file in app.
-
"""
self.assertFileContains('test/file.txt', 'STATICFILES_DIRS')
def test_app_files(self):
"""
Can find a file in an app media/ directory.
-
"""
self.assertFileContains('test/file1.txt', 'file1 in the app dir')
@@ -249,7 +246,6 @@ if sys.platform != 'win32':
def test_links_created(self):
"""
With ``--link``, symbolic links are created.
-
"""
self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt')))
@@ -258,7 +254,7 @@ class TestServeStatic(StaticFilesTestCase):
"""
Test static asset serving view.
"""
- urls = "regressiontests.staticfiles_tests.urls.default"
+ urls = 'regressiontests.staticfiles_tests.urls.default'
def _response(self, filepath):
return self.client.get(
@@ -280,8 +276,8 @@ class TestServeDisabled(TestServeStatic):
settings.DEBUG = False
def test_disabled_serving(self):
- self.assertRaisesRegexp(ImproperlyConfigured, "The view to serve "
- "static files can only be used if the DEBUG setting is True",
+ self.assertRaisesRegexp(ImproperlyConfigured, 'The view to serve '
+ 'static files can only be used if the DEBUG setting is True',
self._response, 'test.txt')
@@ -295,7 +291,7 @@ class TestServeStaticWithURLHelper(TestServeStatic, TestDefaults):
"""
Test static asset serving view with staticfiles_urlpatterns helper.
"""
- urls = "regressiontests.staticfiles_tests.urls.helper"
+ urls = 'regressiontests.staticfiles_tests.urls.helper'
class TestServeAdminMedia(TestServeStatic):
@@ -330,9 +326,9 @@ class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
def setUp(self):
super(TestFileSystemFinder, self).setUp()
self.finder = finders.FileSystemFinder()
- test_file_path = os.path.join(TEST_ROOT, 'project/documents/test/file.txt')
- self.find_first = ("test/file.txt", test_file_path)
- self.find_all = ("test/file.txt", [test_file_path])
+ test_file_path = os.path.join(TEST_ROOT, 'project', 'documents', 'test', 'file.txt')
+ self.find_first = (os.path.join('test', 'file.txt'), test_file_path)
+ self.find_all = (os.path.join('test', 'file.txt'), [test_file_path])
class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
@@ -342,9 +338,9 @@ class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
def setUp(self):
super(TestAppDirectoriesFinder, self).setUp()
self.finder = finders.AppDirectoriesFinder()
- test_file_path = os.path.join(TEST_ROOT, 'apps/test/static/test/file1.txt')
- self.find_first = ("test/file1.txt", test_file_path)
- self.find_all = ("test/file1.txt", [test_file_path])
+ test_file_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'test', 'file1.txt')
+ self.find_first = (os.path.join('test', 'file1.txt'), test_file_path)
+ self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path])
class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase):
@@ -356,8 +352,8 @@ class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase):
self.finder = finders.DefaultStorageFinder(
storage=storage.StaticFilesStorage(location=settings.MEDIA_ROOT))
test_file_path = os.path.join(settings.MEDIA_ROOT, 'media-file.txt')
- self.find_first = ("media-file.txt", test_file_path)
- self.find_all = ("media-file.txt", [test_file_path])
+ self.find_first = ('media-file.txt', test_file_path)
+ self.find_all = ('media-file.txt', [test_file_path])
class TestMiscFinder(TestCase):
@@ -366,9 +362,9 @@ class TestMiscFinder(TestCase):
"""
def test_get_finder(self):
self.assertTrue(isinstance(finders.get_finder(
- "django.contrib.staticfiles.finders.FileSystemFinder"),
+ 'django.contrib.staticfiles.finders.FileSystemFinder'),
finders.FileSystemFinder))
self.assertRaises(ImproperlyConfigured,
- finders.get_finder, "django.contrib.staticfiles.finders.FooBarFinder")
+ finders.get_finder, 'django.contrib.staticfiles.finders.FooBarFinder')
self.assertRaises(ImproperlyConfigured,
- finders.get_finder, "foo.bar.FooBarFinder")
+ finders.get_finder, 'foo.bar.FooBarFinder')