当前位置: 首页>>代码示例>>Python>>正文


Python Sanic.remove_route方法代码示例

本文整理汇总了Python中sanic.Sanic.remove_route方法的典型用法代码示例。如果您正苦于以下问题:Python Sanic.remove_route方法的具体用法?Python Sanic.remove_route怎么用?Python Sanic.remove_route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sanic.Sanic的用法示例。


在下文中一共展示了Sanic.remove_route方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_route_without_clean_cache

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_route_without_clean_cache():
    app = Sanic('test_remove_static_route')

    async def handler(request):
        return text('OK')

    app.add_route(handler, '/test')

    request, response = app.test_client.get('/test')
    assert response.status == 200

    app.remove_route('/test', clean_cache=True)

    request, response = app.test_client.get('/test')
    assert response.status == 404

    app.add_route(handler, '/test')

    request, response = app.test_client.get('/test')
    assert response.status == 200

    app.remove_route('/test', clean_cache=False)

    request, response = app.test_client.get('/test')
    assert response.status == 200
开发者ID:penelopeia,项目名称:sanic,代码行数:27,代码来源:test_routes.py

示例2: test_remove_unhashable_route

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_unhashable_route():
    app = Sanic('test_remove_unhashable_route')

    async def handler(request, unhashable):
        return text('OK')

    app.add_route(handler, '/folder/<unhashable:[A-Za-z0-9/]+>/end/')

    request, response = app.test_client.get('/folder/test/asdf/end/')
    assert response.status == 200

    request, response = app.test_client.get('/folder/test///////end/')
    assert response.status == 200

    request, response = app.test_client.get('/folder/test/end/')
    assert response.status == 200

    app.remove_route('/folder/<unhashable:[A-Za-z0-9/]+>/end/')

    request, response = app.test_client.get('/folder/test/asdf/end/')
    assert response.status == 404

    request, response = app.test_client.get('/folder/test///////end/')
    assert response.status == 404

    request, response = app.test_client.get('/folder/test/end/')
    assert response.status == 404
开发者ID:penelopeia,项目名称:sanic,代码行数:29,代码来源:test_routes.py

示例3: test_remove_static_route

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_static_route():
    app = Sanic('test_remove_static_route')

    async def handler1(request):
        return text('OK1')

    async def handler2(request):
        return text('OK2')

    app.add_route(handler1, '/test')
    app.add_route(handler2, '/test2')

    request, response = app.test_client.get('/test')
    assert response.status == 200

    request, response = app.test_client.get('/test2')
    assert response.status == 200

    app.remove_route('/test')
    app.remove_route('/test2')

    request, response = app.test_client.get('/test')
    assert response.status == 404

    request, response = app.test_client.get('/test2')
    assert response.status == 404
开发者ID:penelopeia,项目名称:sanic,代码行数:28,代码来源:test_routes.py

示例4: test_remove_static_route

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_static_route():
    app = Sanic('test_remove_static_route')

    async def handler1(request):
        return text('OK1')

    async def handler2(request):
        return text('OK2')

    app.add_route(handler1, '/test')
    app.add_route(handler2, '/test2')

    request, response = sanic_endpoint_test(app, uri='/test')
    assert response.status == 200

    request, response = sanic_endpoint_test(app, uri='/test2')
    assert response.status == 200

    app.remove_route('/test')
    app.remove_route('/test2')

    request, response = sanic_endpoint_test(app, uri='/test')
    assert response.status == 404

    request, response = sanic_endpoint_test(app, uri='/test2')
    assert response.status == 404
开发者ID:blurrcat,项目名称:sanic,代码行数:28,代码来源:test_routes.py

示例5: test_remove_dynamic_route

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_dynamic_route():
    app = Sanic('test_remove_dynamic_route')

    async def handler(request, name):
        return text('OK')

    app.add_route(handler, '/folder/<name>')

    request, response = app.test_client.get('/folder/test123')
    assert response.status == 200

    app.remove_route('/folder/<name>')
    request, response = app.test_client.get('/folder/test123')
    assert response.status == 404
开发者ID:penelopeia,项目名称:sanic,代码行数:16,代码来源:test_routes.py

示例6: test_remove_inexistent_route

# 需要导入模块: from sanic import Sanic [as 别名]
# 或者: from sanic.Sanic import remove_route [as 别名]
def test_remove_inexistent_route():
    app = Sanic('test_remove_inexistent_route')

    with pytest.raises(RouteDoesNotExist):
        app.remove_route('/test')
开发者ID:penelopeia,项目名称:sanic,代码行数:7,代码来源:test_routes.py


注:本文中的sanic.Sanic.remove_route方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。