Rename app name and fix test

This commit is contained in:
Ivan Salamakha 2017-11-10 15:30:47 +02:00
parent 4d16805d29
commit 6ce559d13d

View File

@ -30,7 +30,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')
@ -45,6 +46,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')
@ -63,6 +65,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')
@ -90,6 +93,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')
@ -100,6 +104,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)
@ -110,6 +115,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')
@ -120,6 +126,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)
@ -130,6 +137,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_optional_slash(): def test_route_optional_slash():
app = Sanic('test_route_optional_slash') app = Sanic('test_route_optional_slash')
@ -143,6 +151,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')
@ -156,6 +165,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')
@ -172,6 +182,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')
@ -188,6 +199,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')
@ -204,6 +216,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')
@ -220,6 +233,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')
@ -236,6 +250,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')
@ -718,6 +733,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__)
@ -836,7 +852,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')
@ -859,15 +874,15 @@ def test_custom_route_converters():
custom_router = Router(converters={ custom_router = Router(converters={
"uuid": (uuid.UUID, regex) "uuid": (uuid.UUID, regex)
}) })
app = Sanic('test_dynamic_route', router=custom_router) app = Sanic('test_custom_route_converters', router=custom_router)
results = [] results = []
@app.route('/<id:uuid>', methods=None) @app.route('/<id:uuid>')
async def handler(request, id): async def handler(request, id):
results.append(id) results.append(id)
return text('OK') return text('OK')
request, response = app.test_client.get('/folder/e010dcb8-6b40-11e7-8e04-0242ac120022') request, response = app.test_client.get('/e010dcb8-6b40-11e7-8e04-0242ac120022')
assert response.text == 'OK' assert response.text == 'OK'
assert isinstance(results[0], uuid.UUID) assert isinstance(results[0], uuid.UUID)