예제 #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)
예제 #2
0
def test_notfound():
    class app(App):
        pass

    dectate.commit(app)

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

    with pytest.raises(HTTPNotFound):
        publish(request)
예제 #3
0
def test_notfound():
    class app(App):
        pass

    dectate.commit(app)

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

    with pytest.raises(HTTPNotFound):
        publish(request)
예제 #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)
예제 #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'
예제 #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)
예제 #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')
예제 #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'
예제 #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)
예제 #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)
예제 #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)
예제 #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')
예제 #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'
예제 #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!'
예제 #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'
예제 #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!'
예제 #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!'
예제 #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!'
예제 #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'
예제 #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'
예제 #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'
예제 #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'
예제 #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'}
예제 #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'}
예제 #25
0
def test_notfound():
    setup()
    app = App()
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.status == '404 NOT FOUND'
예제 #26
0
파일: path.py 프로젝트: iapilgrim/morepath
 def __call__(self, environ, start_response):
     request = self.app.request(environ)
     response = publish(request, self)
     return response(environ, start_response)
예제 #27
0
def test_notfound():
    setup()
    app = App()
    model = Model()
    response = publish(get_request(path='', app=app), model)
    assert response.status == '404 NOT FOUND'