mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	Before cf546e1, static files in form or widget Media were usually
wrapped with contrib.staticfiles.templatetags.staticfiles.static.
This test ensures compatibility with third-party code that's still
using this pattern.
		
	
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from django.contrib.staticfiles import storage
 | |
| from django.contrib.staticfiles.templatetags.staticfiles import static
 | |
| 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',
 | |
|                 static('relative/path/to/js4'),
 | |
|             ),
 | |
|         )
 | |
|         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>
 | |
| <script type="text/javascript" src="https://example.com/assets/relative/path/to/js4"></script>"""
 | |
|         )
 |