From 56ea394dfd6c8e4ab7507c4991e2fcc3608893b7 Mon Sep 17 00:00:00 2001 From: Anton Samarchyan Date: Fri, 27 Jan 2017 16:12:09 -0500 Subject: [PATCH] Improved test coverage for conf.urls.static. --- tests/view_tests/tests/test_static.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py index e2d22eb54c..01b4c2de7d 100644 --- a/tests/view_tests/tests/test_static.py +++ b/tests/view_tests/tests/test_static.py @@ -3,6 +3,7 @@ import unittest from os import path from django.conf.urls.static import static +from django.core.exceptions import ImproperlyConfigured from django.http import FileResponse, HttpResponseNotModified from django.test import SimpleTestCase, override_settings from django.utils.http import http_date @@ -124,6 +125,22 @@ class StaticHelperTest(StaticTests): super().tearDown() urls.urlpatterns = self._old_views_urlpatterns + def test_prefix(self): + self.assertEqual(static('test')[0].regex.pattern, '^test(?P.*)$') + + @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): def test_was_modified_since_fp(self):