Improved test coverage for conf.urls.static.

This commit is contained in:
Anton Samarchyan 2017-01-27 16:12:09 -05:00 committed by Tim Graham
parent 751d77cdd9
commit 56ea394dfd
1 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import unittest
from os import path from os import path
from django.conf.urls.static import static from django.conf.urls.static import static
from django.core.exceptions import ImproperlyConfigured
from django.http import FileResponse, HttpResponseNotModified from django.http import FileResponse, HttpResponseNotModified
from django.test import SimpleTestCase, override_settings from django.test import SimpleTestCase, override_settings
from django.utils.http import http_date from django.utils.http import http_date
@ -124,6 +125,22 @@ class StaticHelperTest(StaticTests):
super().tearDown() super().tearDown()
urls.urlpatterns = self._old_views_urlpatterns urls.urlpatterns = self._old_views_urlpatterns
def test_prefix(self):
self.assertEqual(static('test')[0].regex.pattern, '^test(?P<path>.*)$')
@override_settings(DEBUG=False)
def test_debug_off(self):
"""No URLs are served if DEBUG=False."""
self.assertEqual(static('test'), [])
def test_empty_prefix(self):
with self.assertRaisesMessage(ImproperlyConfigured, 'Empty static prefix not permitted'):
static('')
def test_special_prefix(self):
"""No URLs are served if prefix contains '://'."""
self.assertEqual(static('http://'), [])
class StaticUtilsTests(unittest.TestCase): class StaticUtilsTests(unittest.TestCase):
def test_was_modified_since_fp(self): def test_was_modified_since_fp(self):