mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.
This commit is contained in:
parent
6be9589eb3
commit
cf546e11ac
34 changed files with 145 additions and 144 deletions
30
tests/staticfiles_tests/test_forms.py
Normal file
30
tests/staticfiles_tests/test_forms.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from django.contrib.staticfiles import storage
|
||||
from django.forms import Media
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
from django.utils.six.moves.urllib.parse import urljoin
|
||||
|
||||
|
||||
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 StaticFilesFormsMediaTestCase(SimpleTestCase):
|
||||
def test_absolute_url(self):
|
||||
m = Media(
|
||||
css={'all': ('path/to/css1', '/path/to/css2')},
|
||||
js=('/path/to/js1', 'http://media.other.com/path/to/js2', 'https://secure.other.com/path/to/js3'),
|
||||
)
|
||||
self.assertEqual(
|
||||
str(m),
|
||||
"""<link href="https://example.com/assets/path/to/css1" type="text/css" media="all" rel="stylesheet" />
|
||||
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
|
||||
<script type="text/javascript" src="/path/to/js1"></script>
|
||||
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
|
||||
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>"""
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue