Ticket #11865: form-media-regression-test.patch

File form-media-regression-test.patch, 9.4 KB (added by Tareque Hossain, 15 years ago)

Modified regression tests to accommodate changes in form media

  • tests/regressiontests/forms/media.py

     
    88>>> settings.MEDIA_URL = 'http://media.example.com/media/'
    99
    1010# 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(){}',))
    1212>>> print m
    1313<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
    1414<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
    1515<script type="text/javascript" src="/path/to/js1"></script>
    1616<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    1717<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
     18<script type="text/javascript">
     19function mymediafunction1(){}
     20function mymediafunction2(){}
     21</script>
    1822
    1923>>> class Foo:
    2024...     css = {
     
    5862...            'all': ('path/to/css1','/path/to/css2')
    5963...         }
    6064...         js = ('/path/to/js1','http://media.other.com/path/to/js2','https://secure.other.com/path/to/js3')
     65...         raw_js = ('function myfunction1(){}',)
    6166
    6267>>> w1 = MyWidget1()
    6368>>> print w1.media
     
    6671<script type="text/javascript" src="/path/to/js1"></script>
    6772<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    6873<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
     74<script type="text/javascript">
     75function myfunction1(){}
     76</script>
    6977
    7078# Media objects can be interrogated by media type
    7179>>> print w1.media['css']
     
    7785<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    7886<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    7987
     88>>> print w1.media['raw_js']
     89<script type="text/javascript">
     90function myfunction1(){}
     91</script>
     92
    8093# Media objects can be combined. Any given media resource will appear only
    8194# once. Duplicated media definitions are ignored.
    8295>>> class MyWidget2(TextInput):
     
    8598...            'all': ('/path/to/css2','/path/to/css3')
    8699...         }
    87100...         js = ('/path/to/js1','/path/to/js4')
     101...         raw_js = ('function myfunction2(){}', 'function myfunction3(){}', )
    88102
    89103>>> class MyWidget3(TextInput):
    90104...     class Media:
     
    103117<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    104118<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    105119<script type="text/javascript" src="/path/to/js4"></script>
     120<script type="text/javascript">
     121function myfunction1(){}
     122function myfunction2(){}
     123function myfunction3(){}
     124</script>
    106125
    107126# Check that media addition hasn't affected the original objects
    108127>>> print w1.media
     
    111130<script type="text/javascript" src="/path/to/js1"></script>
    112131<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    113132<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
     133<script type="text/javascript">
     134function myfunction1(){}
     135</script>
    114136
    115137###############################################################
    116138# Property-based media definitions
     
    156178<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    157179<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    158180<script type="text/javascript" src="/other/js"></script>
     181<script type="text/javascript">
     182function myfunction1(){}
     183</script>
    159184
    160185###############################################################
    161186# Inheritance of media
     
    172197<script type="text/javascript" src="/path/to/js1"></script>
    173198<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    174199<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
     200<script type="text/javascript">
     201function myfunction1(){}
     202</script>
    175203
    176204# If a widget extends another but defines media, it extends the parent widget's media by default
    177205>>> class MyWidget8(MyWidget1):
     
    190218<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    191219<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    192220<script type="text/javascript" src="/path/to/js4"></script>
     221<script type="text/javascript">
     222function myfunction1(){}
     223</script>
    193224
    194225# If a widget extends another but defines media, it extends the parents widget's media,
    195226# even if the parent defined media using a property.
     
    241272<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    242273<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    243274<script type="text/javascript" src="/path/to/js4"></script>
     275<script type="text/javascript">
     276function myfunction1(){}
     277</script>
    244278
    245279# A widget can enable inheritance of one media type by specifying extend as a tuple
    246280>>> class MyWidget12(MyWidget1):
     
    302336<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    303337<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    304338<script type="text/javascript" src="/path/to/js4"></script>
     339<script type="text/javascript">
     340function myfunction1(){}
     341function myfunction2(){}
     342function myfunction3(){}
     343</script>
    305344
    306345###############################################################
    307346# Media processing for forms
     
    320359<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    321360<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    322361<script type="text/javascript" src="/path/to/js4"></script>
     362<script type="text/javascript">
     363function myfunction1(){}
     364function myfunction2(){}
     365function myfunction3(){}
     366</script>
    323367
    324368# Form media can be combined to produce a single media definition.
    325369>>> class AnotherForm(Form):
     
    333377<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    334378<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    335379<script type="text/javascript" src="/path/to/js4"></script>
     380<script type="text/javascript">
     381function myfunction1(){}
     382function myfunction2(){}
     383function myfunction3(){}
     384</script>
    336385
    337386# Forms can also define media, following the same rules as widgets.
    338387>>> class FormWithMedia(Form):
     
    343392...         css = {
    344393...             'all': ('/some/form/css',)
    345394...         }
     395...         raw_js = ('function myfunction4(){}',)
    346396>>> f3 = FormWithMedia()
    347397>>> print f3.media
    348398<link href="http://media.example.com/media/path/to/css1" type="text/css" media="all" rel="stylesheet" />
     
    354404<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
    355405<script type="text/javascript" src="/path/to/js4"></script>
    356406<script type="text/javascript" src="/some/form/javascript"></script>
     407<script type="text/javascript">
     408function myfunction1(){}
     409function myfunction2(){}
     410function myfunction3(){}
     411function myfunction4(){}
     412</script>
    357413
    358414# Media works in templates
    359415>>> 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}))
    361417u'<script type="text/javascript" src="/path/to/js1"></script>
    362418<script type="text/javascript" src="http://media.other.com/path/to/js2"></script>
    363419<script type="text/javascript" src="https://secure.other.com/path/to/js3"></script>
     
    365421<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" />
    366422<link href="/path/to/css2" type="text/css" media="all" rel="stylesheet" />
    367423<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">
     426function myfunction1(){}
     427function myfunction2(){}
     428function myfunction3(){}
     429function myfunction4(){}
     430</script>'
    369431
     432>>> Template("{{ form.media }}").render(Context({'form': f3}))
     433u'<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">
     442function myfunction1(){}
     443function myfunction2(){}
     444function myfunction3(){}
     445function myfunction4(){}
     446</script>'
     447
    370448>>> settings.MEDIA_URL = ORIGINAL_MEDIA_URL
    371449"""
Back to Top