Projet

Général

Profil

0001-utils-do-not-raise-on-Django-syntax-error-in-templat.patch

Nicolas Roche, 25 septembre 2019 19:10

Télécharger (2,99 ko)

Voir les différences:

Subject: [PATCH] utils: do not raise on Django syntax error in templated_url
 (#34518)

 combo/utils/urls.py  |  2 +-
 tests/test_pages.py  | 10 ++++++++++
 tests/test_public.py |  3 ++-
 tests/test_utils.py  |  3 +--
 4 files changed, 14 insertions(+), 4 deletions(-)
combo/utils/urls.py
55 55
        except VariableDoesNotExist as e:
56 56
            raise TemplateError(e.msg, e.params)
57 57
        except TemplateSyntaxError:
58
            raise TemplateError('syntax error')
58
            return 'TEMPLATE ERROR'
59 59
    # ezt-like template
60 60
    def repl(matchobj):
61 61
        varname = matchobj.group(0)[1:-1]
tests/test_pages.py
296 296
    response = app.get(page.get_online_url())
297 297
    assert '<meta name="description" content="page description" />' in response.text
298 298
    assert '<title>Combo - foo</title>' in response.text
299

  
300
def test_render_cell_having_href_template_error(app):
301
    page = Page(title=u'foo', slug='foo', template_name='standard-sidebar', order=0, description="page description")
302
    page.save()
303
    cell = TextCell(page=page,
304
                    text='<a href="{{e-service_url}}backoffice/...">link</a>',
305
                    order=0, placeholder='content')
306
    cell.save()
307
    response = app.get(page.get_online_url())
308
    assert '<a href="TEMPLATE ERROR">link</a>' in response.text
tests/test_public.py
225 225

  
226 226
        page.redirect_url = '{% if error %}'
227 227
        page.save()
228
        resp = app.get('/elsewhere/', status=404)
228
        resp = app.get('/elsewhere/', status=302)
229
        assert resp.location == 'TEMPLATE%20ERROR'
229 230

  
230 231
def test_page_private_unlogged(app):
231 232
    Page.objects.all().delete()
tests/test_utils.py
131 131
    assert get_templated_url('{{ foo.0.bar }}{{ foo.0.zoo }}', context={'foo': [{'bar': 'ok'}, 'ko']}) == 'ok'
132 132
    # catch django syntax errors in TemplateError
133 133
    for template in ('{% foobar %}', '{% if "coucou" %}', '{{}}', '{{ if "x" }}', '{{ _private }}'):
134
        with pytest.raises(TemplateError, match='syntax error'):
135
            assert get_templated_url(template, context=ctx) == 'bar'
134
        assert get_templated_url(template, context=ctx) == 'TEMPLATE ERROR'
136 135

  
137 136
    # requestcontext
138 137
    with override_settings(TEMPLATE_VARS={'test_url': 'http://www.example.net'}):
139
-