Update test_routes.py
This commit is contained in:
parent
7303a06f83
commit
5f329f72ee
|
@ -374,8 +374,7 @@ class Router:
|
||||||
:param method: request method
|
:param method: request method
|
||||||
:return: handler, arguments, keyword arguments
|
:return: handler, arguments, keyword arguments
|
||||||
"""
|
"""
|
||||||
url = unquote(url)
|
url = unquote(host + url)
|
||||||
url = host + url
|
|
||||||
# Check against known static routes
|
# Check against known static routes
|
||||||
route = self.routes_static.get(url)
|
route = self.routes_static.get(url)
|
||||||
method_not_supported = MethodNotSupported(
|
method_not_supported = MethodNotSupported(
|
||||||
|
|
|
@ -29,7 +29,8 @@ def test_versioned_routes_get(method):
|
||||||
client_method = getattr(app.test_client, method)
|
client_method = getattr(app.test_client, method)
|
||||||
|
|
||||||
request, response = client_method('/v1/{}'.format(method))
|
request, response = client_method('/v1/{}'.format(method))
|
||||||
assert response.status== 200
|
assert response.status == 200
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_get():
|
def test_shorthand_routes_get():
|
||||||
app = Sanic('test_shorhand_routes_get')
|
app = Sanic('test_shorhand_routes_get')
|
||||||
|
@ -44,6 +45,7 @@ def test_shorthand_routes_get():
|
||||||
request, response = app.test_client.post('/get')
|
request, response = app.test_client.post('/get')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_multiple():
|
def test_shorthand_routes_multiple():
|
||||||
app = Sanic('test_shorthand_routes_multiple')
|
app = Sanic('test_shorthand_routes_multiple')
|
||||||
|
|
||||||
|
@ -62,6 +64,7 @@ def test_shorthand_routes_multiple():
|
||||||
request, response = app.test_client.options('/get/')
|
request, response = app.test_client.options('/get/')
|
||||||
assert response.status == 200
|
assert response.status == 200
|
||||||
|
|
||||||
|
|
||||||
def test_route_strict_slash():
|
def test_route_strict_slash():
|
||||||
app = Sanic('test_route_strict_slash')
|
app = Sanic('test_route_strict_slash')
|
||||||
|
|
||||||
|
@ -89,6 +92,7 @@ def test_route_strict_slash():
|
||||||
request, response = app.test_client.post('/post')
|
request, response = app.test_client.post('/post')
|
||||||
assert response.status == 404
|
assert response.status == 404
|
||||||
|
|
||||||
|
|
||||||
def test_route_invalid_parameter_syntax():
|
def test_route_invalid_parameter_syntax():
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
app = Sanic('test_route_invalid_param_syntax')
|
app = Sanic('test_route_invalid_param_syntax')
|
||||||
|
@ -99,6 +103,7 @@ def test_route_invalid_parameter_syntax():
|
||||||
|
|
||||||
request, response = app.test_client.get('/get')
|
request, response = app.test_client.get('/get')
|
||||||
|
|
||||||
|
|
||||||
def test_route_strict_slash_default_value():
|
def test_route_strict_slash_default_value():
|
||||||
app = Sanic('test_route_strict_slash', strict_slashes=True)
|
app = Sanic('test_route_strict_slash', strict_slashes=True)
|
||||||
|
|
||||||
|
@ -109,6 +114,7 @@ def test_route_strict_slash_default_value():
|
||||||
request, response = app.test_client.get('/get/')
|
request, response = app.test_client.get('/get/')
|
||||||
assert response.status == 404
|
assert response.status == 404
|
||||||
|
|
||||||
|
|
||||||
def test_route_strict_slash_without_passing_default_value():
|
def test_route_strict_slash_without_passing_default_value():
|
||||||
app = Sanic('test_route_strict_slash')
|
app = Sanic('test_route_strict_slash')
|
||||||
|
|
||||||
|
@ -119,6 +125,7 @@ def test_route_strict_slash_without_passing_default_value():
|
||||||
request, response = app.test_client.get('/get/')
|
request, response = app.test_client.get('/get/')
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
|
|
||||||
|
|
||||||
def test_route_strict_slash_default_value_can_be_overwritten():
|
def test_route_strict_slash_default_value_can_be_overwritten():
|
||||||
app = Sanic('test_route_strict_slash', strict_slashes=True)
|
app = Sanic('test_route_strict_slash', strict_slashes=True)
|
||||||
|
|
||||||
|
@ -129,6 +136,7 @@ def test_route_strict_slash_default_value_can_be_overwritten():
|
||||||
request, response = app.test_client.get('/get/')
|
request, response = app.test_client.get('/get/')
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
|
|
||||||
|
|
||||||
def test_route_slashes_overload():
|
def test_route_slashes_overload():
|
||||||
app = Sanic('test_route_slashes_overload')
|
app = Sanic('test_route_slashes_overload')
|
||||||
|
|
||||||
|
@ -140,7 +148,6 @@ def test_route_slashes_overload():
|
||||||
def handler(request):
|
def handler(request):
|
||||||
return text('OK')
|
return text('OK')
|
||||||
|
|
||||||
|
|
||||||
request, response = app.test_client.get('/hello')
|
request, response = app.test_client.get('/hello')
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
|
|
||||||
|
@ -153,6 +160,7 @@ def test_route_slashes_overload():
|
||||||
request, response = app.test_client.post('/hello/')
|
request, response = app.test_client.post('/hello/')
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
|
|
||||||
|
|
||||||
def test_route_optional_slash():
|
def test_route_optional_slash():
|
||||||
app = Sanic('test_route_optional_slash')
|
app = Sanic('test_route_optional_slash')
|
||||||
|
|
||||||
|
@ -166,6 +174,7 @@ def test_route_optional_slash():
|
||||||
request, response = app.test_client.get('/get/')
|
request, response = app.test_client.get('/get/')
|
||||||
assert response.text == 'OK'
|
assert response.text == 'OK'
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_post():
|
def test_shorthand_routes_post():
|
||||||
app = Sanic('test_shorhand_routes_post')
|
app = Sanic('test_shorhand_routes_post')
|
||||||
|
|
||||||
|
@ -179,6 +188,7 @@ def test_shorthand_routes_post():
|
||||||
request, response = app.test_client.get('/post')
|
request, response = app.test_client.get('/post')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_put():
|
def test_shorthand_routes_put():
|
||||||
app = Sanic('test_shorhand_routes_put')
|
app = Sanic('test_shorhand_routes_put')
|
||||||
|
|
||||||
|
@ -195,6 +205,7 @@ def test_shorthand_routes_put():
|
||||||
request, response = app.test_client.get('/put')
|
request, response = app.test_client.get('/put')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_delete():
|
def test_shorthand_routes_delete():
|
||||||
app = Sanic('test_shorhand_routes_delete')
|
app = Sanic('test_shorhand_routes_delete')
|
||||||
|
|
||||||
|
@ -211,6 +222,7 @@ def test_shorthand_routes_delete():
|
||||||
request, response = app.test_client.get('/delete')
|
request, response = app.test_client.get('/delete')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_patch():
|
def test_shorthand_routes_patch():
|
||||||
app = Sanic('test_shorhand_routes_patch')
|
app = Sanic('test_shorhand_routes_patch')
|
||||||
|
|
||||||
|
@ -227,6 +239,7 @@ def test_shorthand_routes_patch():
|
||||||
request, response = app.test_client.get('/patch')
|
request, response = app.test_client.get('/patch')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_head():
|
def test_shorthand_routes_head():
|
||||||
app = Sanic('test_shorhand_routes_head')
|
app = Sanic('test_shorhand_routes_head')
|
||||||
|
|
||||||
|
@ -243,6 +256,7 @@ def test_shorthand_routes_head():
|
||||||
request, response = app.test_client.get('/head')
|
request, response = app.test_client.get('/head')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_shorthand_routes_options():
|
def test_shorthand_routes_options():
|
||||||
app = Sanic('test_shorhand_routes_options')
|
app = Sanic('test_shorhand_routes_options')
|
||||||
|
|
||||||
|
@ -259,6 +273,7 @@ def test_shorthand_routes_options():
|
||||||
request, response = app.test_client.get('/options')
|
request, response = app.test_client.get('/options')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
def test_static_routes():
|
def test_static_routes():
|
||||||
app = Sanic('test_dynamic_route')
|
app = Sanic('test_dynamic_route')
|
||||||
|
|
||||||
|
@ -741,6 +756,7 @@ def test_remove_inexistent_route():
|
||||||
with pytest.raises(RouteDoesNotExist):
|
with pytest.raises(RouteDoesNotExist):
|
||||||
app.remove_route('/test')
|
app.remove_route('/test')
|
||||||
|
|
||||||
|
|
||||||
def test_removing_slash():
|
def test_removing_slash():
|
||||||
app = Sanic(__name__)
|
app = Sanic(__name__)
|
||||||
|
|
||||||
|
@ -859,7 +875,6 @@ def test_unmergeable_overload_routes():
|
||||||
request, response = app.test_client.post('/overload_whole')
|
request, response = app.test_client.post('/overload_whole')
|
||||||
assert response.text == 'OK1'
|
assert response.text == 'OK1'
|
||||||
|
|
||||||
|
|
||||||
@app.route('/overload_part', methods=['GET'])
|
@app.route('/overload_part', methods=['GET'])
|
||||||
async def handler1(request):
|
async def handler1(request):
|
||||||
return text('OK1')
|
return text('OK1')
|
||||||
|
@ -874,3 +889,21 @@ def test_unmergeable_overload_routes():
|
||||||
|
|
||||||
request, response = app.test_client.post('/overload_part')
|
request, response = app.test_client.post('/overload_part')
|
||||||
assert response.status == 405
|
assert response.status == 405
|
||||||
|
|
||||||
|
|
||||||
|
def test_unicode_routes():
|
||||||
|
app = Sanic('test_unicode_routes')
|
||||||
|
|
||||||
|
@app.get('/你好')
|
||||||
|
def handler1(request):
|
||||||
|
return text('OK1')
|
||||||
|
|
||||||
|
request, response = app.test_client.get('/你好')
|
||||||
|
assert response.text == 'OK1'
|
||||||
|
|
||||||
|
@app.route('/overload/<param>', methods=['GET'])
|
||||||
|
async def handler2(request, param):
|
||||||
|
return text('OK2 ' + param)
|
||||||
|
|
||||||
|
request, response = app.test_client.get('/overload/你好')
|
||||||
|
assert response.text == 'OK2 你好'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user