Exemplo n.º 1
0
def test_notfound():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    request = app.request(get_environ(path=''))
    request.mounts.append(app.mounted())

    with pytest.raises(HTTPNotFound):
        publish(request)
Exemplo n.º 2
0
def test_notfound():
    class app(App):
        pass

    dectate.commit(app)

    request = app().request(get_environ(path=''))

    with pytest.raises(HTTPNotFound):
        publish(request)
Exemplo n.º 3
0
def test_notfound():
    class app(App):
        pass

    dectate.commit(app)

    request = app().request(get_environ(path=''))

    with pytest.raises(HTTPNotFound):
        publish(request)
Exemplo n.º 4
0
def test_notfound():
    config = setup()

    class app(App):
        testing_config = config

    config.commit()

    request = app().request(get_environ(path=''))

    with pytest.raises(HTTPNotFound):
        publish(request)
Exemplo n.º 5
0
def test_notfound():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    response = publish(app.request(get_environ(path='')), app.mounted())
    assert response.status == '404 NOT FOUND'
Exemplo n.º 6
0
def test_view_raises_http_error():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    def view(self, request):
        raise HTTPBadRequest()

    register_path(app, Model, 'foo', None, None, None, None, Model)
    register_view(app, Model, view)

    request = app.request(get_environ(path='foo'))
    request.mounts.append(app.mounted())

    with pytest.raises(HTTPBadRequest):
        publish(request)
Exemplo n.º 7
0
def test_predicates():
    setup()
    app = App()

    def view(request, model):
        return "all"

    def post_view(request, model):
        return "post"

    register_view(app, Model, view, predicates=dict(name=''))
    register_view(app, Model, post_view,
                      predicates=dict(name='', request_method='POST'))

    model = Model()
    assert publish(get_request(path='', app=app), model).data == 'all'
    assert (publish(get_request(path='', method='POST', app=app),
                    model).data == 'post')
Exemplo n.º 8
0
def test_notfound():
    app = App()

    c = setup()
    c.configurable(app)
    c.commit()

    response = publish(app.request(get_environ(path='')), app.mounted())
    assert response.status == '404 NOT FOUND'
Exemplo n.º 9
0
def test_view_raises_http_error():
    config = setup()

    class app(morepath.App):
        testing_config = config

    config.commit()

    def view(self, request):
        raise HTTPBadRequest()

    registry = app.registry
    register_path(registry, Model, 'foo', None, None, None, None, False, Model)
    register_view(registry, dict(model=Model), view)

    request = app().request(get_environ(path='foo'))

    with pytest.raises(HTTPBadRequest):
        publish(request)
Exemplo n.º 10
0
def test_view_raises_http_error():
    class app(morepath.App):
        pass

    dectate.commit(app)

    def view(self, request):
        raise HTTPBadRequest()

    path_registry = app.config.path_registry

    path_registry.register_path(
        Model, 'foo', None, None, None, None, False, Model)

    app.config.view_registry.register_view(dict(model=Model), view)

    request = app().request(get_environ(path='foo'))

    with pytest.raises(HTTPBadRequest):
        publish(request)
Exemplo n.º 11
0
def test_view_raises_http_error():
    class app(morepath.App):
        pass

    dectate.commit(app)

    def view(self, request):
        raise HTTPBadRequest()

    path_registry = app.config.path_registry

    path_registry.register_path(Model, 'foo', None, None, None, None, False,
                                None, Model)

    app.get_view.register(View(view), model=Model)

    request = app().request(get_environ(path='foo'))

    with pytest.raises(HTTPBadRequest):
        publish(request)
Exemplo n.º 12
0
def test_predicates():
    setup()
    app = App()

    def view(request, model):
        return "all"

    def post_view(request, model):
        return "post"

    register_view(app, Model, view, predicates=dict(name=''))
    register_view(app,
                  Model,
                  post_view,
                  predicates=dict(name='', request_method='POST'))

    model = Model()
    assert publish(get_request(path='', app=app), model).data == 'all'
    assert (publish(get_request(path='', method='POST', app=app),
                    model).data == 'post')
Exemplo n.º 13
0
def test_notfound_with_predicates():
    setup()
    app = App()

    def view(request, model):
        return "view"

    register_view(app, Model, view, predicates=dict(name=''))
    model = Model()
    response = publish(get_request(path='foo', app=app), model)
    assert response.status == '404 NOT FOUND'
Exemplo n.º 14
0
def test_response_returned():
    setup()
    app = App()

    def view(request, model):
        return Response('Hello world!')

    register_view(app, Model, view)
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.data == 'Hello world!'
Exemplo n.º 15
0
def test_notfound_with_predicates():
    setup()
    app = App()

    def view(request, model):
        return "view"

    register_view(app, Model, view, predicates=dict(name=''))
    model = Model()
    response = publish(get_request(path='foo', app=app), model)
    assert response.status == '404 NOT FOUND'
Exemplo n.º 16
0
def test_response_returned():
    setup()
    app = App()

    def view(request, model):
        return Response('Hello world!')

    register_view(app, Model, view)
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.data == 'Hello world!'
Exemplo n.º 17
0
def test_view():
    setup()
    app = App()

    def view(request, model):
        return "View!"

    register_view(app, Model, view, predicates=dict(name=''))

    model = Model()
    result = publish(get_request(path='', app=app), model)
    assert result.data == 'View!'
Exemplo n.º 18
0
def test_view():
    setup()
    app = App()

    def view(request, model):
        return "View!"

    register_view(app, Model, view, predicates=dict(name=''))

    model = Model()
    result = publish(get_request(path='', app=app), model)
    assert result.data == 'View!'
Exemplo n.º 19
0
def test_render_html():
    setup()
    app = App()

    def view(request, model):
        return '<p>Hello world!</p>'

    register_view(app, Model, view, render=render_html)

    request = get_request(path='', app=app)
    model = Model()
    response = publish(request, model)
    assert response.data == '<p>Hello world!</p>'
    assert response.content_type == 'text/html'
Exemplo n.º 20
0
def test_render_html():
    setup()
    app = App()

    def view(request, model):
        return '<p>Hello world!</p>'

    register_view(app, Model, view, render=render_html)

    request = get_request(path='', app=app)
    model = Model()
    response = publish(request, model)
    assert response.data == '<p>Hello world!</p>'
    assert response.content_type == 'text/html'
Exemplo n.º 21
0
def test_view_raises_http_error():
    config = setup()
    app = App(testing_config=config)
    config.commit()

    from werkzeug.exceptions import BadRequest
    def view(self, request):
        raise BadRequest()

    register_path(app, Model, 'foo', None, None, None, Model)
    register_view(app, Model, view)

    response = publish(app.request(get_environ(path='foo')), app.mounted())

    assert response.status == '400 BAD REQUEST'
Exemplo n.º 22
0
def test_view_raises_http_error():
    app = App()

    c = setup()
    c.configurable(app)
    c.commit()

    from werkzeug.exceptions import BadRequest
    def view(request, model):
        raise BadRequest()

    register_model(app, Model, 'foo', None, Model)
    register_view(app, Model, view)

    response = publish(app.request(get_environ(path='foo')), app.mounted())

    assert response.status == '400 BAD REQUEST'
Exemplo n.º 23
0
def test_request_view():
    setup()
    app = App()

    def view(request, model):
        return {'hey': 'hey'}

    register_view(app, Model, view, render=render_json)

    request = get_request(path='', app=app)
    model = Model()
    response = publish(request, model)
    # when we get the response, the json will be rendered
    assert response.data == '{"hey": "hey"}'
    assert response.content_type == 'application/json'
    # but we get the original json out when we access the view
    assert request.view(model) == {'hey': 'hey'}
Exemplo n.º 24
0
def test_request_view():
    setup()
    app = App()

    def view(request, model):
        return {'hey': 'hey'}

    register_view(app, Model, view, render=render_json)

    request = get_request(path='', app=app)
    model = Model()
    response = publish(request, model)
    # when we get the response, the json will be rendered
    assert response.data == '{"hey": "hey"}'
    assert response.content_type == 'application/json'
    # but we get the original json out when we access the view
    assert request.view(model) == {'hey': 'hey'}
Exemplo n.º 25
0
def test_notfound():
    setup()
    app = App()
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.status == '404 NOT FOUND'
Exemplo n.º 26
0
 def __call__(self, environ, start_response):
     request = self.app.request(environ)
     response = publish(request, self)
     return response(environ, start_response)
Exemplo n.º 27
0
def test_notfound():
    setup()
    app = App()
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.status == '404 NOT FOUND'