forked from orbit-oss/flask
Added tests, fixed some minor alignment problems.
This commit is contained in:
parent
1647179511
commit
b8e826c16b
3 changed files with 59 additions and 1 deletions
|
|
@ -476,8 +476,11 @@ def routes_command(order_by):
|
|||
sorted_rules = sorted(app.url_map.iter_rules(), key=order_key)
|
||||
|
||||
max_rule = max(len(rule.rule) for rule in sorted_rules)
|
||||
max_rule = max(max_rule, len('Route'))
|
||||
max_ep = max(len(rule.endpoint) for rule in sorted_rules)
|
||||
max_ep = max(max_ep, len('Endpoint'))
|
||||
max_meth = max(len(', '.join(rule.methods)) for rule in sorted_rules)
|
||||
max_meth = max(max_meth, len('Methods'))
|
||||
|
||||
columnformat = '{:<%s} {:<%s} {:<%s}' % (max_rule, max_ep, max_meth)
|
||||
click.echo(columnformat.format('Route', 'Endpoint', 'Methods'))
|
||||
|
|
|
|||
18
tests/test_apps/cliapp/routesapp.py
Normal file
18
tests/test_apps/cliapp/routesapp.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from __future__ import absolute_import, print_function
|
||||
|
||||
from flask import Flask
|
||||
|
||||
|
||||
noroute_app = Flask('noroute app')
|
||||
simpleroute_app = Flask('simpleroute app')
|
||||
only_POST_route_app = Flask('GET route app')
|
||||
|
||||
|
||||
@simpleroute_app.route('/simpleroute')
|
||||
def simple():
|
||||
pass
|
||||
|
||||
|
||||
@only_POST_route_app.route('/only-post', methods=['POST'])
|
||||
def only_post():
|
||||
pass
|
||||
|
|
@ -20,7 +20,7 @@ import pytest
|
|||
from click.testing import CliRunner
|
||||
from flask import Flask, current_app
|
||||
|
||||
from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \
|
||||
from flask.cli import cli, AppGroup, FlaskGroup, NoAppException, ScriptInfo, \
|
||||
find_best_app, locate_app, with_appcontext, prepare_exec_for_file, \
|
||||
find_default_import_path
|
||||
|
||||
|
|
@ -170,3 +170,40 @@ def test_flaskgroup():
|
|||
result = runner.invoke(cli, ['test'])
|
||||
assert result.exit_code == 0
|
||||
assert result.output == 'flaskgroup\n'
|
||||
|
||||
|
||||
class TestRoutes:
|
||||
def test_no_route(self, monkeypatch):
|
||||
monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:noroute_app')
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ['routes'], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
assert result.output == """\
|
||||
Route Endpoint Methods
|
||||
-----------------------------------------------------
|
||||
/static/<path:filename> static HEAD, OPTIONS, GET
|
||||
"""
|
||||
|
||||
def test_simple_route(self, monkeypatch):
|
||||
monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:simpleroute_app')
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ['routes'], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
assert result.output == """\
|
||||
Route Endpoint Methods
|
||||
-----------------------------------------------------
|
||||
/simpleroute simple HEAD, OPTIONS, GET
|
||||
/static/<path:filename> static HEAD, OPTIONS, GET
|
||||
"""
|
||||
|
||||
def test_only_POST_route(self, monkeypatch):
|
||||
monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:only_POST_route_app')
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(cli, ['routes'], catch_exceptions=False)
|
||||
assert result.exit_code == 0
|
||||
assert result.output == """\
|
||||
Route Endpoint Methods
|
||||
------------------------------------------------------
|
||||
/only-post only_post POST, OPTIONS
|
||||
/static/<path:filename> static HEAD, OPTIONS, GET
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue