Ticket #11865: form-media-regression-test.patch
File form-media-regression-test.patch, 9.4 KB (added by , 15 years ago) |
---|
-
tests/regressiontests/forms/media.py
8 8 >>> settings.MEDIA_URL = 'http://media.example.com/media/' 9 9 10 10 # Check construction of media objects 11 >>> 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') )11 >>> 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'), raw_js=('function mymediafunction1(){}', 'function mymediafunction2(){}',)) 12 12 >>> print m 13 13 <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" /> 14 14 <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> 15 15 <script type="text/javascript" src="/path/to/js1"></script> 16 16 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 17 17 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 18 <script type="text/javascript"> 19 function mymediafunction1(){} 20 function mymediafunction2(){} 21 </script> 18 22 19 23 >>> class Foo: 20 24 ... css = { … … 58 62 ... 'all': ('path/to/css1','/path/to/css2') 59 63 ... } 60 64 ... js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3') 65 ... raw_js = ('function myfunction1(){}',) 61 66 62 67 >>> w1 = MyWidget1() 63 68 >>> print w1.media … … 66 71 <script type="text/javascript" src="/path/to/js1"></script> 67 72 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 68 73 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 74 <script type="text/javascript"> 75 function myfunction1(){} 76 </script> 69 77 70 78 # Media objects can be interrogated by media type 71 79 >>> print w1.media['css'] … … 77 85 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 78 86 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 79 87 88 >>> print w1.media['raw_js'] 89 <script type="text/javascript"> 90 function myfunction1(){} 91 </script> 92 80 93 # Media objects can be combined. Any given media resource will appear only 81 94 # once. Duplicated media definitions are ignored. 82 95 >>> class MyWidget2(TextInput): … … 85 98 ... 'all': ('/path/to/css2','/path/to/css3') 86 99 ... } 87 100 ... js = ('/path/to/js1','/path/to/js4') 101 ... raw_js = ('function myfunction2(){}', 'function myfunction3(){}', ) 88 102 89 103 >>> class MyWidget3(TextInput): 90 104 ... class Media: … … 103 117 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 104 118 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 105 119 <script type="text/javascript" src="/path/to/js4"></script> 120 <script type="text/javascript"> 121 function myfunction1(){} 122 function myfunction2(){} 123 function myfunction3(){} 124 </script> 106 125 107 126 # Check that media addition hasn't affected the original objects 108 127 >>> print w1.media … … 111 130 <script type="text/javascript" src="/path/to/js1"></script> 112 131 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 113 132 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 133 <script type="text/javascript"> 134 function myfunction1(){} 135 </script> 114 136 115 137 ############################################################### 116 138 # Property-based media definitions … … 156 178 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 157 179 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 158 180 <script type="text/javascript" src="/other/js"></script> 181 <script type="text/javascript"> 182 function myfunction1(){} 183 </script> 159 184 160 185 ############################################################### 161 186 # Inheritance of media … … 172 197 <script type="text/javascript" src="/path/to/js1"></script> 173 198 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 174 199 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 200 <script type="text/javascript"> 201 function myfunction1(){} 202 </script> 175 203 176 204 # If a widget extends another but defines media, it extends the parent widget's media by default 177 205 >>> class MyWidget8(MyWidget1): … … 190 218 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 191 219 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 192 220 <script type="text/javascript" src="/path/to/js4"></script> 221 <script type="text/javascript"> 222 function myfunction1(){} 223 </script> 193 224 194 225 # If a widget extends another but defines media, it extends the parents widget's media, 195 226 # even if the parent defined media using a property. … … 241 272 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 242 273 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 243 274 <script type="text/javascript" src="/path/to/js4"></script> 275 <script type="text/javascript"> 276 function myfunction1(){} 277 </script> 244 278 245 279 # A widget can enable inheritance of one media type by specifying extend as a tuple 246 280 >>> class MyWidget12(MyWidget1): … … 302 336 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 303 337 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 304 338 <script type="text/javascript" src="/path/to/js4"></script> 339 <script type="text/javascript"> 340 function myfunction1(){} 341 function myfunction2(){} 342 function myfunction3(){} 343 </script> 305 344 306 345 ############################################################### 307 346 # Media processing for forms … … 320 359 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 321 360 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 322 361 <script type="text/javascript" src="/path/to/js4"></script> 362 <script type="text/javascript"> 363 function myfunction1(){} 364 function myfunction2(){} 365 function myfunction3(){} 366 </script> 323 367 324 368 # Form media can be combined to produce a single media definition. 325 369 >>> class AnotherForm(Form): … … 333 377 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 334 378 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 335 379 <script type="text/javascript" src="/path/to/js4"></script> 380 <script type="text/javascript"> 381 function myfunction1(){} 382 function myfunction2(){} 383 function myfunction3(){} 384 </script> 336 385 337 386 # Forms can also define media, following the same rules as widgets. 338 387 >>> class FormWithMedia(Form): … … 343 392 ... css = { 344 393 ... 'all': ('/some/form/css',) 345 394 ... } 395 ... raw_js = ('function myfunction4(){}',) 346 396 >>> f3 = FormWithMedia() 347 397 >>> print f3.media 348 398 <link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" /> … … 354 404 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 355 405 <script type="text/javascript" src="/path/to/js4"></script> 356 406 <script type="text/javascript" src="/some/form/javascript"></script> 407 <script type="text/javascript"> 408 function myfunction1(){} 409 function myfunction2(){} 410 function myfunction3(){} 411 function myfunction4(){} 412 </script> 357 413 358 414 # Media works in templates 359 415 >>> from django.template import Template, Context 360 >>> Template("{{ form.media.js }}{{ form.media.css }} ").render(Context({'form': f3}))416 >>> Template("{{ form.media.js }}{{ form.media.css }}{{ form.media.raw_js }}").render(Context({'form': f3})) 361 417 u'<script type="text/javascript" src="/path/to/js1"></script> 362 418 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 363 419 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> … … 365 421 <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" /> 366 422 <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> 367 423 <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> 368 <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />' 424 <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" /> 425 <script type="text/javascript"> 426 function myfunction1(){} 427 function myfunction2(){} 428 function myfunction3(){} 429 function myfunction4(){} 430 </script>' 369 431 432 >>> Template("{{ form.media }}").render(Context({'form': f3})) 433 u'<script type="text/javascript" src="/path/to/js1"></script> 434 <script type="text/javascript" src="http://media.other.com/path/to/js2"></script> 435 <script type="text/javascript" src="https://secure.other.com/path/to/js3"></script> 436 <script type="text/javascript" src="/path/to/js4"></script> 437 <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" /> 438 <link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" /> 439 <link href="/path/to/css3" type="text/css" media="all" rel="stylesheet" /> 440 <link href="/some/form/css" type="text/css" media="all" rel="stylesheet" /> 441 <script type="text/javascript"> 442 function myfunction1(){} 443 function myfunction2(){} 444 function myfunction3(){} 445 function myfunction4(){} 446 </script>' 447 370 448 >>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL 371 449 """