示例#1
0
def test_response():
    builder = EnvironBuilder(
        path='/?foo=bar',
        method='GET',
    )
    response = Response(builder.get_environ())

    assert response.status == 200
    assert response.headers == {'Content-Type': 'text/html; charset=utf-8'}
示例#2
0
def test_request():
    builder = EnvironBuilder(
        path='/?foo=bar',
        method='GET',
    )
    request = Request(builder.get_environ())

    assert request.params == {'foo': 'bar'}
    assert request.client == '127.0.0.1'
示例#3
0
def test_module_url(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())
    current.request.language = 'it'

    @app.route()
    def test_route():
        return 'Test Router'

    link = url('test_route')
    assert link == '/it/test_route'
示例#4
0
def test_current():
    builder = EnvironBuilder(
        path='/?foo=bar',
        method='GET',
    )
    current = Current()
    environ = builder.get_environ()
    current.initialize(environ)

    assert current.environ == environ
    assert isinstance(current.request, Request)
    assert isinstance(current.response, Response)
示例#5
0
def test_expose_exception_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/test_route')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        raise HTTP(404, 'Not found, dude')

    with pytest.raises(HTTP) as excinfo:
        app.route.dispatch()
    assert excinfo.value.status_code == 404
    assert excinfo.value.body == [b'Not found, dude']
示例#6
0
def test_expose_not_found_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        return 'Test Router'

    with pytest.raises(HTTP) as excinfo:
        app.route.dispatch()
    assert excinfo.value.status_code == 404
    assert excinfo.value.body == [b'Resource not found\n']
示例#7
0
def test_expose_valid_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/it/test_route')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        return 'Test Router'

    response = current.response
    app.route.dispatch()
    assert response.status == 200
    assert response.output == 'Test Router'
    assert current.request.language == 'it'
示例#8
0
def test_expose_exception_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/test_route')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        raise HTTP(404, 'Not found')

    try:
        app.route.dispatch()
    except HTTP as exc:
        assert exc.status_code == 404
        assert exc.body == [b'Not found']
示例#9
0
def test_expose_not_found_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        return 'Test Router'

    try:
        app.route.dispatch()
    except HTTP as exc:
        assert exc.status_code == 404
        assert exc.body == [b'Invalid action\n']
示例#10
0
def test_expose_exception_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/test_route')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        raise HTTP(404, 'Not found')

    try:
        app.route.dispatch()
    except HTTP as exc:
        assert exc.status_code == 404
        assert exc.body == [b'Not found']
示例#11
0
def test_expose_not_found_route(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())

    @app.route()
    def test_route():
        return 'Test Router'

    try:
        app.route.dispatch()
    except HTTP as exc:
        assert exc.status_code == 404
        assert exc.body == [b'Invalid action\n']
示例#12
0
def test_global_url_prefix(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())

    app.route._bind_app_(app, 'foo')

    @app.route('/test')
    def test_route():
        return 'Test Router'

    app.config.static_version_urls = False
    current.request.language = 'en'

    link = url('test_route')
    assert link == '/foo/test'

    link = url('static', 'js/foo.js')
    assert link == '/foo/static/js/foo.js'

    app.config.static_version_urls = True
    app.config.static_version = '1.0.0'

    link = url('static', 'js/foo.js')
    assert link == '/foo/static/_1.0.0/js/foo.js'

    app.config.static_version_urls = False
    current.request.language = 'it'

    link = url('test_route')
    assert link == '/foo/it/test'

    link = url('static', 'js/foo.js')
    assert link == '/foo/it/static/js/foo.js'

    app.config.static_version_urls = True
    app.config.static_version = '1.0.0'

    link = url('static', 'js/foo.js')
    assert link == '/foo/it/static/_1.0.0/js/foo.js'
示例#13
0
def test_module_url(app):
    from weppy.globals import current
    builder = EnvironBuilder('/')
    current.initialize(builder.get_environ())
    current.request.language = 'it'

    @app.route('/test')
    def test_route():
        return 'Test Router'

    @app.route('/test2/<int:a>/<str:b>')
    def test_route2(a, b):
        return 'Test Router'

    @app.route('/test3/<int:a>/foo(/<str:b>)?(.<str:c>)?')
    def test_route3(a, b, c):
        return 'Test Router'

    link = url('test_route')
    assert link == '/it/test'
    link = url('test_route2')
    assert link == '/it/test2'
    link = url('test_route2', [2])
    assert link == '/it/test2/2'
    link = url('test_route2', [2, 'foo'])
    assert link == '/it/test2/2/foo'
    link = url('test_route3')
    assert link == '/it/test3'
    link = url('test_route3', [2])
    assert link == '/it/test3/2/foo'
    link = url('test_route3', [2, 'bar'])
    assert link == '/it/test3/2/foo/bar'
    link = url('test_route3', [2, 'bar', 'json'])
    assert link == '/it/test3/2/foo/bar.json'
    link = url('test_route3', [2, 'bar', 'json'], {'foo': 'bar', 'bar': 'foo'})
    lsplit = link.split('?')
    assert lsplit[0] == '/it/test3/2/foo/bar.json'
    assert lsplit[1] in ['foo=bar&bar=foo', 'bar=foo&foo=bar']
示例#14
0
文件: test_session.py 项目: yws/weppy
def current():
    from weppy.globals import current
    builder = EnvironBuilder()
    current.initialize(builder.get_environ())
    return current
示例#15
0
def init_current(url):
    builder = EnvironBuilder(url)
    current.initialize(builder.get_environ())
    current._pipeline_storage = []
    return builder
示例#16
0
def init_current(url):
    builder = EnvironBuilder(url)
    current.initialize(builder.get_environ())
    current._pipeline_storage = []
    return builder