2017-01-07 11:11:46 +00:00
|
|
|
from urllib.parse import urljoin
|
|
|
|
|
2015-11-07 11:24:38 +00:00
|
|
|
from django.contrib.staticfiles import storage
|
|
|
|
from django.forms import Media
|
2018-01-21 21:38:52 +00:00
|
|
|
from django.templatetags.static import static
|
2015-11-07 11:24:38 +00:00
|
|
|
from django.test import SimpleTestCase, override_settings
|
|
|
|
|
|
|
|
|
|
|
|
class StaticTestStorage(storage.StaticFilesStorage):
|
|
|
|
def url(self, name):
|
|
|
|
return urljoin("https://example.com/assets/", name)
|
|
|
|
|
|
|
|
|
|
|
|
@override_settings(
|
|
|
|
STATIC_URL="http://media.example.com/static/",
|
2017-12-28 20:07:29 +00:00
|
|
|
INSTALLED_APPS=("django.contrib.staticfiles",),
|
2015-11-07 11:24:38 +00:00
|
|
|
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")},
|
2016-01-14 17:16:42 +00:00
|
|
|
js=(
|
|
|
|
"/path/to/js1",
|
|
|
|
"http://media.other.com/path/to/js2",
|
|
|
|
"https://secure.other.com/path/to/js3",
|
|
|
|
static("relative/path/to/js4"),
|
|
|
|
),
|
2015-11-07 11:24:38 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
str(m),
|
2022-01-21 14:46:37 +00:00
|
|
|
'<link href="https://example.com/assets/path/to/css1" media="all" '
|
|
|
|
'rel="stylesheet">\n'
|
|
|
|
'<link href="/path/to/css2" media="all" rel="stylesheet">\n'
|
2019-12-11 08:49:54 +00:00
|
|
|
'<script src="/path/to/js1"></script>\n'
|
|
|
|
'<script src="http://media.other.com/path/to/js2"></script>\n'
|
|
|
|
'<script src="https://secure.other.com/path/to/js3"></script>\n'
|
|
|
|
'<script src="https://example.com/assets/relative/path/to/js4"></script>',
|
2015-11-07 11:24:38 +00:00
|
|
|
)
|