diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-01-21 13:38:52 -0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-01-23 10:30:10 -0500 |
| commit | 7d607127e39792aa45b6abc2619b99fc55bcc672 (patch) | |
| tree | bec3a8e16ac489b669d63fb5025b0f05896f683c /tests | |
| parent | f0f383b6350c7b2f64bb2a6491a395abdd3313d6 (diff) | |
Refs #21221 -- Deprecated staticfiles and admin_static template tag libraries.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_views/test_static_deprecation.py | 30 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 14 | ||||
| -rw-r--r-- | tests/staticfiles_tests/cases.py | 4 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_forms.py | 2 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_templatetag_deprecation.py | 45 |
5 files changed, 78 insertions, 17 deletions
diff --git a/tests/admin_views/test_static_deprecation.py b/tests/admin_views/test_static_deprecation.py new file mode 100644 index 0000000000..fb64df6f5f --- /dev/null +++ b/tests/admin_views/test_static_deprecation.py @@ -0,0 +1,30 @@ +import warnings + +from django.contrib.admin.templatetags.admin_static import static +from django.contrib.staticfiles.storage import staticfiles_storage +from django.test import SimpleTestCase +from django.utils.deprecation import RemovedInDjango30Warning + + +class AdminStaticDeprecationTests(SimpleTestCase): + def test(self): + """ + admin_static.static points to the collectstatic version + (as django.contrib.collectstatic is in INSTALLED_APPS). + """ + msg = ( + '{% load admin_static %} is deprecated in favor of ' + '{% load static %}.' + ) + old_url = staticfiles_storage.base_url + staticfiles_storage.base_url = '/test/' + try: + with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') + url = static('path') + self.assertEqual(url, '/test/path') + self.assertEqual(len(recorded), 1) + self.assertIs(recorded[0].category, RemovedInDjango30Warning) + self.assertEqual(str(recorded[0].message), msg) + finally: + staticfiles_storage.base_url = old_url diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index a9746d9add..68094e0053 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -10,7 +10,6 @@ from django.contrib.admin import AdminSite, ModelAdmin from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME from django.contrib.admin.models import ADDITION, DELETION, LogEntry from django.contrib.admin.options import TO_FIELD_VAR -from django.contrib.admin.templatetags.admin_static import static from django.contrib.admin.templatetags.admin_urls import add_preserved_filters from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.admin.utils import quote @@ -18,7 +17,6 @@ from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.auth import REDIRECT_FIELD_NAME, get_permission_codename from django.contrib.auth.models import Group, Permission, User from django.contrib.contenttypes.models import ContentType -from django.contrib.staticfiles.storage import staticfiles_storage from django.core import mail from django.core.checks import Error from django.core.files import temp as tempfile @@ -200,18 +198,6 @@ class AdminViewBasicTest(AdminViewBasicTestCase): response = self.client.get(add_url[:-1]) self.assertRedirects(response, add_url, status_code=301) - def test_admin_static_template_tag(self): - """ - admin_static.static points to the collectstatic version - (as django.contrib.collectstatic is in INSTALLED_APPS). - """ - old_url = staticfiles_storage.base_url - staticfiles_storage.base_url = '/test/' - try: - self.assertEqual(static('path'), '/test/path') - finally: - staticfiles_storage.base_url = old_url - def test_basic_add_GET(self): """ A smoke test to ensure GET on the add_view works. diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py index 3adf5cf211..918ec4f99e 100644 --- a/tests/staticfiles_tests/cases.py +++ b/tests/staticfiles_tests/cases.py @@ -34,8 +34,8 @@ class BaseStaticFilesMixin: def static_template_snippet(self, path, asvar=False): if asvar: - return "{%% load static from staticfiles %%}{%% static '%s' as var %%}{{ var }}" % path - return "{%% load static from staticfiles %%}{%% static '%s' %%}" % path + return "{%% load static from static %%}{%% static '%s' as var %%}{{ var }}" % path + return "{%% load static from static %%}{%% static '%s' %%}" % path def assertStaticRenders(self, path, result, asvar=False, **kwargs): template = self.static_template_snippet(path, asvar) diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py index c5dc66de61..0178bab931 100644 --- a/tests/staticfiles_tests/test_forms.py +++ b/tests/staticfiles_tests/test_forms.py @@ -1,8 +1,8 @@ from urllib.parse import urljoin from django.contrib.staticfiles import storage -from django.contrib.staticfiles.templatetags.staticfiles import static from django.forms import Media +from django.templatetags.static import static from django.test import SimpleTestCase, override_settings diff --git a/tests/staticfiles_tests/test_templatetag_deprecation.py b/tests/staticfiles_tests/test_templatetag_deprecation.py new file mode 100644 index 0000000000..0194b0745e --- /dev/null +++ b/tests/staticfiles_tests/test_templatetag_deprecation.py @@ -0,0 +1,45 @@ +import warnings +from urllib.parse import urljoin + +from django.contrib.staticfiles import storage +from django.contrib.staticfiles.templatetags.staticfiles import static +from django.template import Context, Template +from django.test import SimpleTestCase, override_settings +from django.utils.deprecation import RemovedInDjango30Warning + + +class StaticTestStorage(storage.StaticFilesStorage): + def url(self, name): + return urljoin('https://example.com/assets/', name) + + +@override_settings( + STATIC_URL='http://media.example.com/static/', + INSTALLED_APPS=('django.contrib.staticfiles',), + STATICFILES_STORAGE='staticfiles_tests.test_forms.StaticTestStorage', +) +class StaticDeprecationTests(SimpleTestCase): + def test_templatetag_deprecated(self): + msg = '{% load staticfiles %} is deprecated in favor of {% load static %}.' + template = "{% load staticfiles %}{% static 'main.js' %}" + with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') + template = Template(template) + rendered = template.render(Context()) + self.assertEqual(rendered, 'https://example.com/assets/main.js') + self.assertEqual(len(recorded), 1) + self.assertIs(recorded[0].category, RemovedInDjango30Warning) + self.assertEqual(str(recorded[0].message), msg) + + def test_static_deprecated(self): + msg = ( + 'django.contrib.staticfiles.templatetags.static() is deprecated in ' + 'favor of django.templatetags.static.static().' + ) + with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') + url = static('main.js') + self.assertEqual(url, 'https://example.com/assets/main.js') + self.assertEqual(len(recorded), 1) + self.assertIs(recorded[0].category, RemovedInDjango30Warning) + self.assertEqual(str(recorded[0].message), msg) |
