def test_perform_post_with_no_dispatch_parameter(): target = Page().bind(request=req('post')) with pytest.raises(AssertionError) as e: target.render_to_response() assert str(e.value) == 'This request was a POST, but there was no dispatch command present.'
def test_custom_endpoint_on_page(): p = Page(endpoints__test__func=lambda value, **_: 7).bind( request=req('get', **{'/test': ''})) assert p.endpoints.test.include is True assert p.endpoints.test.endpoint_path == '/test' assert p.render_to_response().content == b'7'
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_invalid_enpoint_path(settings): p = Page().bind(request=req('get', **{'/foo': ''})) assert p.render_to_response( ).content == b'{"error": "Invalid endpoint path"}' settings.DEBUG = True with pytest.raises(InvalidEndpointPathException) as e: p.render_to_response() assert str(e.value) == """ Given path /foo not found. Short alternatives: '' debug_tree Long alternatives: '' endpoints/debug_tree """.strip()