@@ -980,6 +980,31 @@ def test_full_url_dump_class_es6(self):
980980 self .test_full_url_dump (es5 = False )
981981 self .class_mode = None
982982
983+ @override_settings (STATIC_TEMPLATES = {
984+ 'ENGINES' : [{
985+ 'BACKEND' : 'render_static.backends.StaticDjangoTemplates' ,
986+ 'OPTIONS' : {
987+ 'loaders' : [
988+ ('render_static.loaders.StaticLocMemLoader' , {
989+ 'urls.js' : 'var urls = {\n '
990+ '{% urls_to_js include=include %}'
991+ '\n };'
992+ })
993+ ],
994+ 'builtins' : ['render_static.templatetags.render_static' ]
995+ },
996+ }],
997+ 'context' : {
998+ 'include' : ['admin' ]
999+ }
1000+ })
1001+ def test_admin_urls (self ):
1002+ """
1003+ Admin urls should work out-of-box - just check that it doesnt raise
1004+ """
1005+ call_command ('render_static' , 'urls.js' )
1006+ self .assertTrue (True )
1007+
9831008 @override_settings (STATIC_TEMPLATES = {
9841009 'ENGINES' : [{
9851010 'BACKEND' : 'render_static.backends.StaticDjangoTemplates' ,
@@ -1512,6 +1537,162 @@ def tearDown(self):
15121537 pass
15131538
15141539
1540+ @override_settings (ROOT_URLCONF = 'render_static.tests.urls2' )
1541+ class UnregisteredURLTest (URLJavascriptMixin , BaseTestCase ):
1542+
1543+ def setUp (self ):
1544+ self .clear_placeholder_registries ()
1545+
1546+ @override_settings (STATIC_TEMPLATES = {
1547+ 'ENGINES' : [{
1548+ 'BACKEND' : 'render_static.backends.StaticDjangoTemplates' ,
1549+ 'OPTIONS' : {
1550+ 'loaders' : [
1551+ ('render_static.loaders.StaticLocMemLoader' , {
1552+ 'urls.js' : ('{% urls_to_js '
1553+ 'visitor="render_static.ClassURLWriter" '
1554+ 'include=include '
1555+ '%}' )
1556+ })
1557+ ],
1558+ 'builtins' : ['render_static.templatetags.render_static' ]
1559+ },
1560+ }],
1561+ 'templates' : {'urls.js' : {'context' : {'include' : ['default' ]}}}
1562+ })
1563+ def test_no_default_registered (self ):
1564+ """
1565+ Tests: https://github.com/bckohan/django-render-static/issues/8
1566+ :return:
1567+ """
1568+ self .es6_mode = True
1569+ self .url_js = None
1570+ self .class_mode = ClassURLWriter .class_name_
1571+
1572+ call_command ('render_static' , 'urls.js' )
1573+ self .compare ('default' , kwargs = {'def' : 'named' })
1574+ self .compare ('default' , args = ['unnamed' ])
1575+
1576+ @override_settings (STATIC_TEMPLATES = {
1577+ 'context' : {'include' : ['default' ]},
1578+ 'ENGINES' : [{
1579+ 'BACKEND' : 'render_static.backends.StaticDjangoTemplates' ,
1580+ 'OPTIONS' : {
1581+ 'loaders' : [
1582+ ('render_static.loaders.StaticLocMemLoader' , {
1583+ 'urls.js' : ('{% urls_to_js '
1584+ 'visitor="render_static.ClassURLWriter" '
1585+ 'include=include '
1586+ '%}' )
1587+ })
1588+ ],
1589+ 'builtins' : ['render_static.templatetags.render_static' ]
1590+ },
1591+ }],
1592+ 'templates' : {'urls.js' : {'context' : {'include' : ['special' ]}}}
1593+ })
1594+ def test_named_unnamed_conflation1 (self ):
1595+ """
1596+ https://github.com/bckohan/django-render-static/issues/9
1597+ """
1598+ self .es6_mode = True
1599+ self .url_js = None
1600+ self .class_mode = ClassURLWriter .class_name_
1601+
1602+ print (reverse ('special' , kwargs = {'choice' : 'first' }))
1603+ print (reverse ('special' , args = ['first' ]))
1604+
1605+ self .assertRaises (CommandError , lambda : call_command ('render_static' , 'urls.js' ))
1606+
1607+ placeholders .register_variable_placeholder ('choice' , 'first' )
1608+ self .assertRaises (CommandError , lambda : call_command ('render_static' , 'urls.js' ))
1609+ placeholders .register_unnamed_placeholders ('special' , ['first' ])
1610+
1611+ call_command ('render_static' , 'urls.js' )
1612+ self .compare ('special' , {'choice' : 'first' })
1613+ self .compare ('special' , ['first' ])
1614+
1615+
1616+ @override_settings (
1617+ ROOT_URLCONF = 'render_static.tests.urls2' ,
1618+ STATIC_TEMPLATES = {
1619+ 'context' : {'include' : ['default' ]},
1620+ 'ENGINES' : [{
1621+ 'BACKEND' : 'render_static.backends.StaticDjangoTemplates' ,
1622+ 'OPTIONS' : {
1623+ 'loaders' : [
1624+ ('render_static.loaders.StaticLocMemLoader' , {
1625+ 'urls.js' : ('{% urls_to_js '
1626+ 'visitor="render_static.ClassURLWriter" '
1627+ 'include=include '
1628+ '%}' )
1629+ })
1630+ ],
1631+ 'builtins' : ['render_static.templatetags.render_static' ]
1632+ },
1633+ }],
1634+ 'templates' : {'urls.js' : {'context' : {'include' : ['special' ]}}}
1635+ }
1636+ )
1637+ def test_named_unnamed_conflation2 (self ):
1638+ """
1639+ https://github.com/bckohan/django-render-static/issues/9
1640+ """
1641+ self .es6_mode = True
1642+ self .url_js = None
1643+ self .class_mode = ClassURLWriter .class_name_
1644+
1645+ print (reverse ('special' , kwargs = {'choice' : 'first' }))
1646+ print (reverse ('special' , args = ['first' ]))
1647+
1648+ self .assertRaises (CommandError , lambda : call_command ('render_static' , 'urls.js' ))
1649+
1650+ placeholders .register_variable_placeholder ('choice' , 'first' )
1651+ self .assertRaises (CommandError , lambda : call_command ('render_static' , 'urls.js' ))
1652+ placeholders .register_unnamed_placeholders ('special' , ['first' ])
1653+
1654+ call_command ('render_static' , 'urls.js' )
1655+ self .compare ('special' , {'choice' : 'first' })
1656+ self .compare ('special' , ['first' ])
1657+
1658+
1659+ """
1660+ @override_settings(STATIC_TEMPLATES={
1661+ 'context': {'include': ['default']},
1662+ 'ENGINES': [{
1663+ 'BACKEND': 'render_static.backends.StaticDjangoTemplates',
1664+ 'OPTIONS': {
1665+ 'loaders': [
1666+ ('render_static.loaders.StaticLocMemLoader', {
1667+ 'urls.js': ('{% urls_to_js '
1668+ 'visitor="render_static.ClassURLWriter" '
1669+ 'include=include '
1670+ '%}')
1671+ })
1672+ ],
1673+ 'builtins': ['render_static.templatetags.render_static']
1674+ },
1675+ }],
1676+ 'templates': {'urls.js': {'context': {'include': ['special']}}}
1677+ })
1678+ def test_complexity_boundary(self):
1679+ https://github.com/bckohan/django-render-static/issues/10
1680+ For URLs with lots of unregistered arguments, the reversal attempts may produce an explosion
1681+ of complexity. If there are
1682+ :return:
1683+ self.es6_mode = True
1684+ self.url_js = None
1685+
1686+ self.assertRaises(CommandError, call_command('render_static', 'urls.js'))
1687+
1688+ self.compare('default')
1689+ """
1690+
1691+ # uncomment to not delete generated js
1692+ def tearDown (self ):
1693+ pass
1694+
1695+
15151696class URLSToJavascriptOffNominalTest (URLJavascriptMixin , BaseTestCase ):
15161697
15171698 def setUp (self ):
0 commit comments