コード例 #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
ファイル: test_expose.py プロジェクト: olivierh59500/weppy
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
ファイル: test_expose.py プロジェクト: feitianyiren/weppy
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
ファイル: test_expose.py プロジェクト: feitianyiren/weppy
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
ファイル: test_expose.py プロジェクト: feitianyiren/weppy
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
ファイル: test_expose.py プロジェクト: javierbarre/weppy
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
ファイル: test_expose.py プロジェクト: javierbarre/weppy
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
ファイル: test_expose.py プロジェクト: diegoteixeir4/weppy
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
ファイル: test_expose.py プロジェクト: diegoteixeir4/weppy
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
ファイル: test_expose.py プロジェクト: feitianyiren/weppy
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
ファイル: test_expose.py プロジェクト: feitianyiren/weppy
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
ファイル: test_pipeline.py プロジェクト: gi0baro/weppy
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