~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/regressiontests/forms/tests/media.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
from django.forms import TextInput, Media, TextInput, CharField, Form, MultiWidget
3
 
from django.template import Template, Context
4
 
from django.test import TestCase
5
 
from django.test.utils import override_settings
6
 
 
7
 
 
8
 
@override_settings(
9
 
    STATIC_URL=None,
10
 
    MEDIA_URL='http://media.example.com/media/',
11
 
)
12
 
class FormsMediaTestCase(TestCase):
13
 
    """Tests for the media handling on widgets and forms"""
14
 
 
15
 
    def test_construction(self):
16
 
        # Check construction of media objects
17
 
        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'))
18
 
        self.assertEqual(str(m), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
19
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
20
 
<script type="text/javascript" src="/path/to/js1"></script>
21
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
22
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
23
 
 
24
 
        class Foo:
25
 
            css = {
26
 
               'all': ('path/to/css1','/path/to/css2')
27
 
            }
28
 
            js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
29
 
 
30
 
        m3 = Media(Foo)
31
 
        self.assertEqual(str(m3), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
32
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
33
 
<script type="text/javascript" src="/path/to/js1"></script>
34
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
35
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
36
 
 
37
 
        # A widget can exist without a media definition
38
 
        class MyWidget(TextInput):
39
 
            pass
40
 
 
41
 
        w = MyWidget()
42
 
        self.assertEqual(str(w.media), '')
43
 
 
44
 
    def test_media_dsl(self):
45
 
        ###############################################################
46
 
        # DSL Class-based media definitions
47
 
        ###############################################################
48
 
 
49
 
        # A widget can define media if it needs to.
50
 
        # Any absolute path will be preserved; relative paths are combined
51
 
        # with the value of settings.MEDIA_URL
52
 
        class MyWidget1(TextInput):
53
 
            class Media:
54
 
                css = {
55
 
                   'all': ('path/to/css1','/path/to/css2')
56
 
                }
57
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
58
 
 
59
 
        w1 = MyWidget1()
60
 
        self.assertEqual(str(w1.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
61
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
62
 
<script type="text/javascript" src="/path/to/js1"></script>
63
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
64
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
65
 
 
66
 
        # Media objects can be interrogated by media type
67
 
        self.assertEqual(str(w1.media['css']), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
68
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />""")
69
 
 
70
 
        self.assertEqual(str(w1.media['js']), """<script type="text/javascript" src="/path/to/js1"></script>
71
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
72
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
73
 
 
74
 
    def test_combine_media(self):
75
 
        # Media objects can be combined. Any given media resource will appear only
76
 
        # once. Duplicated media definitions are ignored.
77
 
        class MyWidget1(TextInput):
78
 
            class Media:
79
 
                css = {
80
 
                   'all': ('path/to/css1','/path/to/css2')
81
 
                }
82
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
83
 
 
84
 
        class MyWidget2(TextInput):
85
 
            class Media:
86
 
                css = {
87
 
                   'all': ('/path/to/css2','/path/to/css3')
88
 
                }
89
 
                js = ('/path/to/js1','/path/to/js4')
90
 
 
91
 
        class MyWidget3(TextInput):
92
 
            class Media:
93
 
                css = {
94
 
                   'all': ('/path/to/css3','path/to/css1')
95
 
                }
96
 
                js = ('/path/to/js1','/path/to/js4')
97
 
 
98
 
        w1 = MyWidget1()
99
 
        w2 = MyWidget2()
100
 
        w3 = MyWidget3()
101
 
        self.assertEqual(str(w1.media + w2.media + w3.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
102
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
103
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
104
 
<script type="text/javascript" src="/path/to/js1"></script>
105
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
106
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
107
 
<script type="text/javascript" src="/path/to/js4"></script>""")
108
 
 
109
 
        # Check that media addition hasn't affected the original objects
110
 
        self.assertEqual(str(w1.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
111
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
112
 
<script type="text/javascript" src="/path/to/js1"></script>
113
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
114
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
115
 
 
116
 
        # Regression check for #12879: specifying the same CSS or JS file
117
 
        # multiple times in a single Media instance should result in that file
118
 
        # only being included once.
119
 
        class MyWidget4(TextInput):
120
 
            class Media:
121
 
                css = {'all': ('/path/to/css1', '/path/to/css1')}
122
 
                js = ('/path/to/js1', '/path/to/js1')
123
 
 
124
 
        w4 = MyWidget4()
125
 
        self.assertEqual(str(w4.media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" />
126
 
<script type="text/javascript" src="/path/to/js1"></script>""")
127
 
 
128
 
    def test_media_property(self):
129
 
        ###############################################################
130
 
        # Property-based media definitions
131
 
        ###############################################################
132
 
 
133
 
        # Widget media can be defined as a property
134
 
        class MyWidget4(TextInput):
135
 
            def _media(self):
136
 
                return Media(css={'all': ('/some/path',)}, js = ('/some/js',))
137
 
            media = property(_media)
138
 
 
139
 
        w4 = MyWidget4()
140
 
        self.assertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
141
 
<script type="text/javascript" src="/some/js"></script>""")
142
 
 
143
 
        # Media properties can reference the media of their parents
144
 
        class MyWidget5(MyWidget4):
145
 
            def _media(self):
146
 
                return super(MyWidget5, self).media + Media(css={'all': ('/other/path',)}, js = ('/other/js',))
147
 
            media = property(_media)
148
 
 
149
 
        w5 = MyWidget5()
150
 
        self.assertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
151
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
152
 
<script type="text/javascript" src="/some/js"></script>
153
 
<script type="text/javascript" src="/other/js"></script>""")
154
 
 
155
 
    def test_media_property_parent_references(self):
156
 
        # Media properties can reference the media of their parents,
157
 
        # even if the parent media was defined using a class
158
 
        class MyWidget1(TextInput):
159
 
            class Media:
160
 
                css = {
161
 
                   'all': ('path/to/css1','/path/to/css2')
162
 
                }
163
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
164
 
 
165
 
        class MyWidget6(MyWidget1):
166
 
            def _media(self):
167
 
                return super(MyWidget6, self).media + Media(css={'all': ('/other/path',)}, js = ('/other/js',))
168
 
            media = property(_media)
169
 
 
170
 
        w6 = MyWidget6()
171
 
        self.assertEqual(str(w6.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
172
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
173
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
174
 
<script type="text/javascript" src="/path/to/js1"></script>
175
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
176
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
177
 
<script type="text/javascript" src="/other/js"></script>""")
178
 
 
179
 
    def test_media_inheritance(self):
180
 
        ###############################################################
181
 
        # Inheritance of media
182
 
        ###############################################################
183
 
 
184
 
        # If a widget extends another but provides no media definition, it inherits the parent widget's media
185
 
        class MyWidget1(TextInput):
186
 
            class Media:
187
 
                css = {
188
 
                   'all': ('path/to/css1','/path/to/css2')
189
 
                }
190
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
191
 
 
192
 
        class MyWidget7(MyWidget1):
193
 
            pass
194
 
 
195
 
        w7 = MyWidget7()
196
 
        self.assertEqual(str(w7.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
197
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
198
 
<script type="text/javascript" src="/path/to/js1"></script>
199
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
200
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
201
 
 
202
 
        # If a widget extends another but defines media, it extends the parent widget's media by default
203
 
        class MyWidget8(MyWidget1):
204
 
            class Media:
205
 
                css = {
206
 
                   'all': ('/path/to/css3','path/to/css1')
207
 
                }
208
 
                js = ('/path/to/js1','/path/to/js4')
209
 
 
210
 
        w8 = MyWidget8()
211
 
        self.assertEqual(str(w8.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
212
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
213
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
214
 
<script type="text/javascript" src="/path/to/js1"></script>
215
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
216
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
217
 
<script type="text/javascript" src="/path/to/js4"></script>""")
218
 
 
219
 
    def test_media_inheritance_from_property(self):
220
 
        # If a widget extends another but defines media, it extends the parents widget's media,
221
 
        # even if the parent defined media using a property.
222
 
        class MyWidget1(TextInput):
223
 
            class Media:
224
 
                css = {
225
 
                   'all': ('path/to/css1','/path/to/css2')
226
 
                }
227
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
228
 
 
229
 
        class MyWidget4(TextInput):
230
 
            def _media(self):
231
 
                return Media(css={'all': ('/some/path',)}, js = ('/some/js',))
232
 
            media = property(_media)
233
 
 
234
 
        class MyWidget9(MyWidget4):
235
 
            class Media:
236
 
                css = {
237
 
                    'all': ('/other/path',)
238
 
                }
239
 
                js = ('/other/js',)
240
 
 
241
 
        w9 = MyWidget9()
242
 
        self.assertEqual(str(w9.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
243
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
244
 
<script type="text/javascript" src="/some/js"></script>
245
 
<script type="text/javascript" src="/other/js"></script>""")
246
 
 
247
 
        # A widget can disable media inheritance by specifying 'extend=False'
248
 
        class MyWidget10(MyWidget1):
249
 
            class Media:
250
 
                extend = False
251
 
                css = {
252
 
                   'all': ('/path/to/css3','path/to/css1')
253
 
                }
254
 
                js = ('/path/to/js1','/path/to/js4')
255
 
 
256
 
        w10 = MyWidget10()
257
 
        self.assertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
258
 
<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
259
 
<script type="text/javascript" src="/path/to/js1"></script>
260
 
<script type="text/javascript" src="/path/to/js4"></script>""")
261
 
 
262
 
    def test_media_inheritance_extends(self):
263
 
        # A widget can explicitly enable full media inheritance by specifying 'extend=True'
264
 
        class MyWidget1(TextInput):
265
 
            class Media:
266
 
                css = {
267
 
                   'all': ('path/to/css1','/path/to/css2')
268
 
                }
269
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
270
 
 
271
 
        class MyWidget11(MyWidget1):
272
 
            class Media:
273
 
                extend = True
274
 
                css = {
275
 
                   'all': ('/path/to/css3','path/to/css1')
276
 
                }
277
 
                js = ('/path/to/js1','/path/to/js4')
278
 
 
279
 
        w11 = MyWidget11()
280
 
        self.assertEqual(str(w11.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
281
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
282
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
283
 
<script type="text/javascript" src="/path/to/js1"></script>
284
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
285
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
286
 
<script type="text/javascript" src="/path/to/js4"></script>""")
287
 
 
288
 
    def test_media_inheritance_single_type(self):
289
 
        # A widget can enable inheritance of one media type by specifying extend as a tuple
290
 
        class MyWidget1(TextInput):
291
 
            class Media:
292
 
                css = {
293
 
                   'all': ('path/to/css1','/path/to/css2')
294
 
                }
295
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
296
 
 
297
 
        class MyWidget12(MyWidget1):
298
 
            class Media:
299
 
                extend = ('css',)
300
 
                css = {
301
 
                   'all': ('/path/to/css3','path/to/css1')
302
 
                }
303
 
                js = ('/path/to/js1','/path/to/js4')
304
 
 
305
 
        w12 = MyWidget12()
306
 
        self.assertEqual(str(w12.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
307
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
308
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
309
 
<script type="text/javascript" src="/path/to/js1"></script>
310
 
<script type="text/javascript" src="/path/to/js4"></script>""")
311
 
 
312
 
    def test_multi_media(self):
313
 
        ###############################################################
314
 
        # Multi-media handling for CSS
315
 
        ###############################################################
316
 
 
317
 
        # A widget can define CSS media for multiple output media types
318
 
        class MultimediaWidget(TextInput):
319
 
            class Media:
320
 
                css = {
321
 
                   'screen, print': ('/file1','/file2'),
322
 
                   'screen': ('/file3',),
323
 
                   'print': ('/file4',)
324
 
                }
325
 
                js = ('/path/to/js1','/path/to/js4')
326
 
 
327
 
        multimedia = MultimediaWidget()
328
 
        self.assertEqual(str(multimedia.media), """<link href="/file4" type="text/css" media="print" rel="stylesheet" />
329
 
<link href="/file3" type="text/css" media="screen" rel="stylesheet" />
330
 
<link href="/file1" type="text/css" media="screen, print" rel="stylesheet" />
331
 
<link href="/file2" type="text/css" media="screen, print" rel="stylesheet" />
332
 
<script type="text/javascript" src="/path/to/js1"></script>
333
 
<script type="text/javascript" src="/path/to/js4"></script>""")
334
 
 
335
 
    def test_multi_widget(self):
336
 
        ###############################################################
337
 
        # Multiwidget media handling
338
 
        ###############################################################
339
 
 
340
 
        class MyWidget1(TextInput):
341
 
            class Media:
342
 
                css = {
343
 
                   'all': ('path/to/css1','/path/to/css2')
344
 
                }
345
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
346
 
 
347
 
        class MyWidget2(TextInput):
348
 
            class Media:
349
 
                css = {
350
 
                   'all': ('/path/to/css2','/path/to/css3')
351
 
                }
352
 
                js = ('/path/to/js1','/path/to/js4')
353
 
 
354
 
        class MyWidget3(TextInput):
355
 
            class Media:
356
 
                css = {
357
 
                   'all': ('/path/to/css3','path/to/css1')
358
 
                }
359
 
                js = ('/path/to/js1','/path/to/js4')
360
 
 
361
 
        # MultiWidgets have a default media definition that gets all the
362
 
        # media from the component widgets
363
 
        class MyMultiWidget(MultiWidget):
364
 
            def __init__(self, attrs=None):
365
 
                widgets = [MyWidget1, MyWidget2, MyWidget3]
366
 
                super(MyMultiWidget, self).__init__(widgets, attrs)
367
 
 
368
 
        mymulti = MyMultiWidget()
369
 
        self.assertEqual(str(mymulti.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
370
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
371
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
372
 
<script type="text/javascript" src="/path/to/js1"></script>
373
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
374
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
375
 
<script type="text/javascript" src="/path/to/js4"></script>""")
376
 
 
377
 
    def test_form_media(self):
378
 
        ###############################################################
379
 
        # Media processing for forms
380
 
        ###############################################################
381
 
 
382
 
        class MyWidget1(TextInput):
383
 
            class Media:
384
 
                css = {
385
 
                   'all': ('path/to/css1','/path/to/css2')
386
 
                }
387
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
388
 
 
389
 
        class MyWidget2(TextInput):
390
 
            class Media:
391
 
                css = {
392
 
                   'all': ('/path/to/css2','/path/to/css3')
393
 
                }
394
 
                js = ('/path/to/js1','/path/to/js4')
395
 
 
396
 
        class MyWidget3(TextInput):
397
 
            class Media:
398
 
                css = {
399
 
                   'all': ('/path/to/css3','path/to/css1')
400
 
                }
401
 
                js = ('/path/to/js1','/path/to/js4')
402
 
 
403
 
        # You can ask a form for the media required by its widgets.
404
 
        class MyForm(Form):
405
 
            field1 = CharField(max_length=20, widget=MyWidget1())
406
 
            field2 = CharField(max_length=20, widget=MyWidget2())
407
 
        f1 = MyForm()
408
 
        self.assertEqual(str(f1.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
409
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
410
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
411
 
<script type="text/javascript" src="/path/to/js1"></script>
412
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
413
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
414
 
<script type="text/javascript" src="/path/to/js4"></script>""")
415
 
 
416
 
        # Form media can be combined to produce a single media definition.
417
 
        class AnotherForm(Form):
418
 
            field3 = CharField(max_length=20, widget=MyWidget3())
419
 
        f2 = AnotherForm()
420
 
        self.assertEqual(str(f1.media + f2.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
421
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
422
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
423
 
<script type="text/javascript" src="/path/to/js1"></script>
424
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
425
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
426
 
<script type="text/javascript" src="/path/to/js4"></script>""")
427
 
 
428
 
        # Forms can also define media, following the same rules as widgets.
429
 
        class FormWithMedia(Form):
430
 
            field1 = CharField(max_length=20, widget=MyWidget1())
431
 
            field2 = CharField(max_length=20, widget=MyWidget2())
432
 
            class Media:
433
 
                js = ('/some/form/javascript',)
434
 
                css = {
435
 
                    'all': ('/some/form/css',)
436
 
                }
437
 
        f3 = FormWithMedia()
438
 
        self.assertEqual(str(f3.media), """<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
439
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
440
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
441
 
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
442
 
<script type="text/javascript" src="/path/to/js1"></script>
443
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
444
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
445
 
<script type="text/javascript" src="/path/to/js4"></script>
446
 
<script type="text/javascript" src="/some/form/javascript"></script>""")
447
 
 
448
 
        # Media works in templates
449
 
        self.assertEqual(Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3})), """<script type="text/javascript" src="/path/to/js1"></script>
450
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
451
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
452
 
<script type="text/javascript" src="/path/to/js4"></script>
453
 
<script type="text/javascript" src="/some/form/javascript"></script><link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
454
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
455
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
456
 
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")
457
 
 
458
 
 
459
 
@override_settings(
460
 
    STATIC_URL='http://media.example.com/static/',
461
 
    MEDIA_URL='http://media.example.com/media/',
462
 
)
463
 
class StaticFormsMediaTestCase(TestCase):
464
 
    """Tests for the media handling on widgets and forms"""
465
 
 
466
 
    def test_construction(self):
467
 
        # Check construction of media objects
468
 
        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'))
469
 
        self.assertEqual(str(m), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
470
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
471
 
<script type="text/javascript" src="/path/to/js1"></script>
472
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
473
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
474
 
 
475
 
        class Foo:
476
 
            css = {
477
 
               'all': ('path/to/css1','/path/to/css2')
478
 
            }
479
 
            js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
480
 
 
481
 
        m3 = Media(Foo)
482
 
        self.assertEqual(str(m3), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
483
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
484
 
<script type="text/javascript" src="/path/to/js1"></script>
485
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
486
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
487
 
 
488
 
        # A widget can exist without a media definition
489
 
        class MyWidget(TextInput):
490
 
            pass
491
 
 
492
 
        w = MyWidget()
493
 
        self.assertEqual(str(w.media), '')
494
 
 
495
 
    def test_media_dsl(self):
496
 
        ###############################################################
497
 
        # DSL Class-based media definitions
498
 
        ###############################################################
499
 
 
500
 
        # A widget can define media if it needs to.
501
 
        # Any absolute path will be preserved; relative paths are combined
502
 
        # with the value of settings.MEDIA_URL
503
 
        class MyWidget1(TextInput):
504
 
            class Media:
505
 
                css = {
506
 
                   'all': ('path/to/css1','/path/to/css2')
507
 
                }
508
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
509
 
 
510
 
        w1 = MyWidget1()
511
 
        self.assertEqual(str(w1.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
512
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
513
 
<script type="text/javascript" src="/path/to/js1"></script>
514
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
515
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
516
 
 
517
 
        # Media objects can be interrogated by media type
518
 
        self.assertEqual(str(w1.media['css']), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
519
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />""")
520
 
 
521
 
        self.assertEqual(str(w1.media['js']), """<script type="text/javascript" src="/path/to/js1"></script>
522
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
523
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
524
 
 
525
 
    def test_combine_media(self):
526
 
        # Media objects can be combined. Any given media resource will appear only
527
 
        # once. Duplicated media definitions are ignored.
528
 
        class MyWidget1(TextInput):
529
 
            class Media:
530
 
                css = {
531
 
                   'all': ('path/to/css1','/path/to/css2')
532
 
                }
533
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
534
 
 
535
 
        class MyWidget2(TextInput):
536
 
            class Media:
537
 
                css = {
538
 
                   'all': ('/path/to/css2','/path/to/css3')
539
 
                }
540
 
                js = ('/path/to/js1','/path/to/js4')
541
 
 
542
 
        class MyWidget3(TextInput):
543
 
            class Media:
544
 
                css = {
545
 
                   'all': ('/path/to/css3','path/to/css1')
546
 
                }
547
 
                js = ('/path/to/js1','/path/to/js4')
548
 
 
549
 
        w1 = MyWidget1()
550
 
        w2 = MyWidget2()
551
 
        w3 = MyWidget3()
552
 
        self.assertEqual(str(w1.media + w2.media + w3.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
553
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
554
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
555
 
<script type="text/javascript" src="/path/to/js1"></script>
556
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
557
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
558
 
<script type="text/javascript" src="/path/to/js4"></script>""")
559
 
 
560
 
        # Check that media addition hasn't affected the original objects
561
 
        self.assertEqual(str(w1.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
562
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
563
 
<script type="text/javascript" src="/path/to/js1"></script>
564
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
565
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
566
 
 
567
 
        # Regression check for #12879: specifying the same CSS or JS file
568
 
        # multiple times in a single Media instance should result in that file
569
 
        # only being included once.
570
 
        class MyWidget4(TextInput):
571
 
            class Media:
572
 
                css = {'all': ('/path/to/css1', '/path/to/css1')}
573
 
                js = ('/path/to/js1', '/path/to/js1')
574
 
 
575
 
        w4 = MyWidget4()
576
 
        self.assertEqual(str(w4.media), """<link href="/path/to/css1" type="text/css" media="all" rel="stylesheet" />
577
 
<script type="text/javascript" src="/path/to/js1"></script>""")
578
 
 
579
 
    def test_media_property(self):
580
 
        ###############################################################
581
 
        # Property-based media definitions
582
 
        ###############################################################
583
 
 
584
 
        # Widget media can be defined as a property
585
 
        class MyWidget4(TextInput):
586
 
            def _media(self):
587
 
                return Media(css={'all': ('/some/path',)}, js = ('/some/js',))
588
 
            media = property(_media)
589
 
 
590
 
        w4 = MyWidget4()
591
 
        self.assertEqual(str(w4.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
592
 
<script type="text/javascript" src="/some/js"></script>""")
593
 
 
594
 
        # Media properties can reference the media of their parents
595
 
        class MyWidget5(MyWidget4):
596
 
            def _media(self):
597
 
                return super(MyWidget5, self).media + Media(css={'all': ('/other/path',)}, js = ('/other/js',))
598
 
            media = property(_media)
599
 
 
600
 
        w5 = MyWidget5()
601
 
        self.assertEqual(str(w5.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
602
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
603
 
<script type="text/javascript" src="/some/js"></script>
604
 
<script type="text/javascript" src="/other/js"></script>""")
605
 
 
606
 
    def test_media_property_parent_references(self):
607
 
        # Media properties can reference the media of their parents,
608
 
        # even if the parent media was defined using a class
609
 
        class MyWidget1(TextInput):
610
 
            class Media:
611
 
                css = {
612
 
                   'all': ('path/to/css1','/path/to/css2')
613
 
                }
614
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
615
 
 
616
 
        class MyWidget6(MyWidget1):
617
 
            def _media(self):
618
 
                return super(MyWidget6, self).media + Media(css={'all': ('/other/path',)}, js = ('/other/js',))
619
 
            media = property(_media)
620
 
 
621
 
        w6 = MyWidget6()
622
 
        self.assertEqual(str(w6.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
623
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
624
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
625
 
<script type="text/javascript" src="/path/to/js1"></script>
626
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
627
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
628
 
<script type="text/javascript" src="/other/js"></script>""")
629
 
 
630
 
    def test_media_inheritance(self):
631
 
        ###############################################################
632
 
        # Inheritance of media
633
 
        ###############################################################
634
 
 
635
 
        # If a widget extends another but provides no media definition, it inherits the parent widget's media
636
 
        class MyWidget1(TextInput):
637
 
            class Media:
638
 
                css = {
639
 
                   'all': ('path/to/css1','/path/to/css2')
640
 
                }
641
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
642
 
 
643
 
        class MyWidget7(MyWidget1):
644
 
            pass
645
 
 
646
 
        w7 = MyWidget7()
647
 
        self.assertEqual(str(w7.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
648
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
649
 
<script type="text/javascript" src="/path/to/js1"></script>
650
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
651
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>""")
652
 
 
653
 
        # If a widget extends another but defines media, it extends the parent widget's media by default
654
 
        class MyWidget8(MyWidget1):
655
 
            class Media:
656
 
                css = {
657
 
                   'all': ('/path/to/css3','path/to/css1')
658
 
                }
659
 
                js = ('/path/to/js1','/path/to/js4')
660
 
 
661
 
        w8 = MyWidget8()
662
 
        self.assertEqual(str(w8.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
663
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
664
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
665
 
<script type="text/javascript" src="/path/to/js1"></script>
666
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
667
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
668
 
<script type="text/javascript" src="/path/to/js4"></script>""")
669
 
 
670
 
    def test_media_inheritance_from_property(self):
671
 
        # If a widget extends another but defines media, it extends the parents widget's media,
672
 
        # even if the parent defined media using a property.
673
 
        class MyWidget1(TextInput):
674
 
            class Media:
675
 
                css = {
676
 
                   'all': ('path/to/css1','/path/to/css2')
677
 
                }
678
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
679
 
 
680
 
        class MyWidget4(TextInput):
681
 
            def _media(self):
682
 
                return Media(css={'all': ('/some/path',)}, js = ('/some/js',))
683
 
            media = property(_media)
684
 
 
685
 
        class MyWidget9(MyWidget4):
686
 
            class Media:
687
 
                css = {
688
 
                    'all': ('/other/path',)
689
 
                }
690
 
                js = ('/other/js',)
691
 
 
692
 
        w9 = MyWidget9()
693
 
        self.assertEqual(str(w9.media), """<link href="/some/path" type="text/css" media="all" rel="stylesheet" />
694
 
<link href="/other/path" type="text/css" media="all" rel="stylesheet" />
695
 
<script type="text/javascript" src="/some/js"></script>
696
 
<script type="text/javascript" src="/other/js"></script>""")
697
 
 
698
 
        # A widget can disable media inheritance by specifying 'extend=False'
699
 
        class MyWidget10(MyWidget1):
700
 
            class Media:
701
 
                extend = False
702
 
                css = {
703
 
                   'all': ('/path/to/css3','path/to/css1')
704
 
                }
705
 
                js = ('/path/to/js1','/path/to/js4')
706
 
 
707
 
        w10 = MyWidget10()
708
 
        self.assertEqual(str(w10.media), """<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
709
 
<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
710
 
<script type="text/javascript" src="/path/to/js1"></script>
711
 
<script type="text/javascript" src="/path/to/js4"></script>""")
712
 
 
713
 
    def test_media_inheritance_extends(self):
714
 
        # A widget can explicitly enable full media inheritance by specifying 'extend=True'
715
 
        class MyWidget1(TextInput):
716
 
            class Media:
717
 
                css = {
718
 
                   'all': ('path/to/css1','/path/to/css2')
719
 
                }
720
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
721
 
 
722
 
        class MyWidget11(MyWidget1):
723
 
            class Media:
724
 
                extend = True
725
 
                css = {
726
 
                   'all': ('/path/to/css3','path/to/css1')
727
 
                }
728
 
                js = ('/path/to/js1','/path/to/js4')
729
 
 
730
 
        w11 = MyWidget11()
731
 
        self.assertEqual(str(w11.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
732
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
733
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
734
 
<script type="text/javascript" src="/path/to/js1"></script>
735
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
736
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
737
 
<script type="text/javascript" src="/path/to/js4"></script>""")
738
 
 
739
 
    def test_media_inheritance_single_type(self):
740
 
        # A widget can enable inheritance of one media type by specifying extend as a tuple
741
 
        class MyWidget1(TextInput):
742
 
            class Media:
743
 
                css = {
744
 
                   'all': ('path/to/css1','/path/to/css2')
745
 
                }
746
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
747
 
 
748
 
        class MyWidget12(MyWidget1):
749
 
            class Media:
750
 
                extend = ('css',)
751
 
                css = {
752
 
                   'all': ('/path/to/css3','path/to/css1')
753
 
                }
754
 
                js = ('/path/to/js1','/path/to/js4')
755
 
 
756
 
        w12 = MyWidget12()
757
 
        self.assertEqual(str(w12.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
758
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
759
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
760
 
<script type="text/javascript" src="/path/to/js1"></script>
761
 
<script type="text/javascript" src="/path/to/js4"></script>""")
762
 
 
763
 
    def test_multi_media(self):
764
 
        ###############################################################
765
 
        # Multi-media handling for CSS
766
 
        ###############################################################
767
 
 
768
 
        # A widget can define CSS media for multiple output media types
769
 
        class MultimediaWidget(TextInput):
770
 
            class Media:
771
 
                css = {
772
 
                   'screen, print': ('/file1','/file2'),
773
 
                   'screen': ('/file3',),
774
 
                   'print': ('/file4',)
775
 
                }
776
 
                js = ('/path/to/js1','/path/to/js4')
777
 
 
778
 
        multimedia = MultimediaWidget()
779
 
        self.assertEqual(str(multimedia.media), """<link href="/file4" type="text/css" media="print" rel="stylesheet" />
780
 
<link href="/file3" type="text/css" media="screen" rel="stylesheet" />
781
 
<link href="/file1" type="text/css" media="screen, print" rel="stylesheet" />
782
 
<link href="/file2" type="text/css" media="screen, print" rel="stylesheet" />
783
 
<script type="text/javascript" src="/path/to/js1"></script>
784
 
<script type="text/javascript" src="/path/to/js4"></script>""")
785
 
 
786
 
    def test_multi_widget(self):
787
 
        ###############################################################
788
 
        # Multiwidget media handling
789
 
        ###############################################################
790
 
 
791
 
        class MyWidget1(TextInput):
792
 
            class Media:
793
 
                css = {
794
 
                   'all': ('path/to/css1','/path/to/css2')
795
 
                }
796
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
797
 
 
798
 
        class MyWidget2(TextInput):
799
 
            class Media:
800
 
                css = {
801
 
                   'all': ('/path/to/css2','/path/to/css3')
802
 
                }
803
 
                js = ('/path/to/js1','/path/to/js4')
804
 
 
805
 
        class MyWidget3(TextInput):
806
 
            class Media:
807
 
                css = {
808
 
                   'all': ('/path/to/css3','path/to/css1')
809
 
                }
810
 
                js = ('/path/to/js1','/path/to/js4')
811
 
 
812
 
        # MultiWidgets have a default media definition that gets all the
813
 
        # media from the component widgets
814
 
        class MyMultiWidget(MultiWidget):
815
 
            def __init__(self, attrs=None):
816
 
                widgets = [MyWidget1, MyWidget2, MyWidget3]
817
 
                super(MyMultiWidget, self).__init__(widgets, attrs)
818
 
 
819
 
        mymulti = MyMultiWidget()
820
 
        self.assertEqual(str(mymulti.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
821
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
822
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
823
 
<script type="text/javascript" src="/path/to/js1"></script>
824
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
825
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
826
 
<script type="text/javascript" src="/path/to/js4"></script>""")
827
 
 
828
 
    def test_form_media(self):
829
 
        ###############################################################
830
 
        # Media processing for forms
831
 
        ###############################################################
832
 
 
833
 
        class MyWidget1(TextInput):
834
 
            class Media:
835
 
                css = {
836
 
                   'all': ('path/to/css1','/path/to/css2')
837
 
                }
838
 
                js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
839
 
 
840
 
        class MyWidget2(TextInput):
841
 
            class Media:
842
 
                css = {
843
 
                   'all': ('/path/to/css2','/path/to/css3')
844
 
                }
845
 
                js = ('/path/to/js1','/path/to/js4')
846
 
 
847
 
        class MyWidget3(TextInput):
848
 
            class Media:
849
 
                css = {
850
 
                   'all': ('/path/to/css3','path/to/css1')
851
 
                }
852
 
                js = ('/path/to/js1','/path/to/js4')
853
 
 
854
 
        # You can ask a form for the media required by its widgets.
855
 
        class MyForm(Form):
856
 
            field1 = CharField(max_length=20, widget=MyWidget1())
857
 
            field2 = CharField(max_length=20, widget=MyWidget2())
858
 
        f1 = MyForm()
859
 
        self.assertEqual(str(f1.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
860
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
861
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
862
 
<script type="text/javascript" src="/path/to/js1"></script>
863
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
864
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
865
 
<script type="text/javascript" src="/path/to/js4"></script>""")
866
 
 
867
 
        # Form media can be combined to produce a single media definition.
868
 
        class AnotherForm(Form):
869
 
            field3 = CharField(max_length=20, widget=MyWidget3())
870
 
        f2 = AnotherForm()
871
 
        self.assertEqual(str(f1.media + f2.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
872
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
873
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
874
 
<script type="text/javascript" src="/path/to/js1"></script>
875
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
876
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
877
 
<script type="text/javascript" src="/path/to/js4"></script>""")
878
 
 
879
 
        # Forms can also define media, following the same rules as widgets.
880
 
        class FormWithMedia(Form):
881
 
            field1 = CharField(max_length=20, widget=MyWidget1())
882
 
            field2 = CharField(max_length=20, widget=MyWidget2())
883
 
            class Media:
884
 
                js = ('/some/form/javascript',)
885
 
                css = {
886
 
                    'all': ('/some/form/css',)
887
 
                }
888
 
        f3 = FormWithMedia()
889
 
        self.assertEqual(str(f3.media), """<link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
890
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
891
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
892
 
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
893
 
<script type="text/javascript" src="/path/to/js1"></script>
894
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
895
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
896
 
<script type="text/javascript" src="/path/to/js4"></script>
897
 
<script type="text/javascript" src="/some/form/javascript"></script>""")
898
 
 
899
 
        # Media works in templates
900
 
        self.assertEqual(Template("{{ form.media.js }}{{ form.media.css }}").render(Context({'form': f3})), """<script type="text/javascript" src="/path/to/js1"></script>
901
 
<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
902
 
<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
903
 
<script type="text/javascript" src="/path/to/js4"></script>
904
 
<script type="text/javascript" src="/some/form/javascript"></script><link href="http://media.example.com/static/path/to/css1" type="text/css" media="all" rel="stylesheet" />
905
 
<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
906
 
<link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" />
907
 
<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />""")