def test_post_not_trigger_bind(): p = Page( parts=dict( form=Form( fields__foo=Field(), ), exploding_form=ExplodingForm(), ) ) p = p.bind( request=req( 'post', **{ '-': '', 'foo': 'bar', }, ) ) assert p.parts.form.fields.foo.value == 'bar' with pytest.raises(Exception) as e: # noinspection PyStatementEffect p.parts.exploding_form assert str(e.value) == 'Boom'
def test_ajax_not_trigger_bind(): p = Page( parts=dict( form=Form( endpoints__foo__func=lambda value, **_: HttpResponse('bar'), ), exploding_form=ExplodingForm(), ) ) p = p.bind( request=req( 'get', **{ '/foo': '', }, ) ) assert p.render_to_response().content == b'bar' with pytest.raises(Exception) as e: # noinspection PyStatementEffect p.parts.exploding_form assert str(e.value) == 'Boom'
def test_context_processor_is_called_on_render_root(): part = Page( context__root_part_context_variable='root_part_context_variable', ) t = render_root( part=part.bind(request=req('get')), template_name='test_context_processor_is_called_on_render_root.html', context=dict(my_context_variable='my_context_variable'), ) assert t == 'context_processor_is_called\nroot_part_context_variable\nmy_context_variable\n'
def test_context_processor_is_called_on_render_root(): style_name = 'test_context_processor_is_called_on_render_root' style = Style( base, base_template='test_context_processor_is_called_on_render_root.html', ) register_style(style_name, style) part = Page( context__root_part_context_variable='root_part_context_variable', iommi_style=style_name, ) t = render_root( part=part.bind(request=req('get')), context=dict(my_context_variable='my_context_variable'), ) assert t == 'context_processor_is_called\nroot_part_context_variable\nmy_context_variable\n'