mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Refs #21221 -- Deprecated staticfiles and admin_static template tag libraries.
This commit is contained in:
parent
f0f383b635
commit
7d607127e3
9 changed files with 109 additions and 23 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
45
tests/staticfiles_tests/test_templatetag_deprecation.py
Normal file
45
tests/staticfiles_tests/test_templatetag_deprecation.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue