diff options
| author | Johannes Hoppe <info@johanneshoppe.com> | 2015-11-07 12:24:38 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-12-10 14:30:19 -0500 |
| commit | cf546e11ac76c8dec527e39ff8ce8249a195ab42 (patch) | |
| tree | c86d039e94099e47382bbeaf4361fef22bbcf55e /tests/staticfiles_tests | |
| parent | 6be9589eb34f79914666c9d9e1e15bdb7fc44df2 (diff) | |
Fixed #21221 -- Made form Media and static template tag use staticfiles if installed.
Diffstat (limited to 'tests/staticfiles_tests')
| -rw-r--r-- | tests/staticfiles_tests/test_forms.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/test_forms.py b/tests/staticfiles_tests/test_forms.py new file mode 100644 index 0000000000..f5bd24186b --- /dev/null +++ b/tests/staticfiles_tests/test_forms.py @@ -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>""" + ) |
