Ejemplo n.º 1
0
def test_meta(app):
    current.initialize({
        'PATH_INFO': '/', 'wpp.appnow': '', 'wpp.now.utc': '',
        'wpp.now.local': '', 'wpp.application': ''})
    current.response.meta.foo = "bar"
    current.response.meta_prop.foo = "bar"
    templater = Templater(app)
    r = templater.render(
        source="{{include_meta}}", filename='mtest',
        context={'current': current})
    assert r == '<meta name="foo" content="bar" />\n' + \
        '<meta property="foo" content="bar" />\n'
Ejemplo n.º 2
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'
Ejemplo n.º 3
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']
Ejemplo n.º 4
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']
Ejemplo n.º 5
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'
Ejemplo n.º 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'

    try:
        app.route.dispatch()
    except HTTP as exc:
        assert exc.status_code == 404
        assert exc.body == [b'Invalid action\n']
Ejemplo n.º 7
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']
Ejemplo n.º 8
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']
Ejemplo n.º 9
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']
Ejemplo n.º 10
0
def test_redirect():
    from weppy.globals import current
    current.initialize({
        'PATH_INFO': '/',
        'wpp.appnow': 'test',
        'wpp.now.utc': 'test',
        'wpp.now.local': 'test',
        'wpp.application': 'test',
    })

    try:
        redirect('/redirect', 302)
    except HTTP as http_redirect:
        assert current.response.status == 302
        assert http_redirect.status_code == 302
        assert http_redirect.headers == [('Location', '/redirect')]
Ejemplo n.º 11
0
def test_redirect():
    from weppy.globals import current
    current.initialize({
        'PATH_INFO': '/',
        'wpp.appnow': 'test',
        'wpp.now.utc': 'test',
        'wpp.now.local': 'test',
        'wpp.application': 'test',
    })

    try:
        redirect('/redirect', 302)
    except HTTP as http_redirect:
        assert current.response.status == 302
        assert http_redirect.status_code == 302
        assert http_redirect.headers == [('Location', '/redirect')]
Ejemplo n.º 12
0
def test_meta(app):
    current.initialize({
        'PATH_INFO': '/',
        'wpp.appnow': '',
        'wpp.now.utc': '',
        'wpp.now.local': '',
        'wpp.application': ''
    })
    current.response.meta.foo = "bar"
    current.response.meta_prop.foo = "bar"
    templater = Templater(app)
    r = templater.render(source="{{include_meta}}",
                         filename='mtest',
                         context={'current': current})
    assert r == '<meta name="foo" content="bar" />\n' + \
        '<meta property="foo" content="bar" />\n'
Ejemplo n.º 13
0
def test_meta(app):
    current.initialize({
        'PATH_INFO': '/',
        'REQUEST_METHOD': 'GET',
        'HTTP_HOST': 'localhost',
        'wsgi.url_scheme': 'http',
        'wpp.now': datetime.utcnow(),
        'wpp.application': 'test'
    })
    current.response.meta.foo = "bar"
    current.response.meta_prop.foo = "bar"
    templater = app.templater
    r = templater._render(
        source="{{include_meta}}", filename='mtest',
        context={'current': current})
    assert r == '<meta name="foo" content="bar" />\n' + \
        '<meta property="foo" content="bar" />\n'
Ejemplo n.º 14
0
def test_redirect():
    from weppy.globals import current
    current.initialize({
        'PATH_INFO': '/',
        'REQUEST_METHOD': 'GET',
        'HTTP_HOST': 'localhost',
        'wsgi.url_scheme': 'http',
        'wpp.now': datetime.utcnow(),
        'wpp.application': 'test'
    })

    try:
        redirect('/redirect', 302)
    except HTTP as http_redirect:
        assert current.response.status == 302
        assert http_redirect.status_code == 302
        assert http_redirect.headers == [('Location', '/redirect')]
Ejemplo n.º 15
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'
Ejemplo n.º 16
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']
Ejemplo n.º 17
0
def current():
    from weppy.globals import current
    builder = EnvironBuilder()
    current.initialize(builder.get_environ())
    return current
Ejemplo n.º 18
0
def init_current(url):
    builder = EnvironBuilder(url)
    current.initialize(builder.get_environ())
    current._pipeline_storage = []
    return builder
Ejemplo n.º 19
0
def init_current(url):
    builder = EnvironBuilder(url)
    current.initialize(builder.get_environ())
    current._pipeline_storage = []
    return builder