Added tests, fixed some minor alignment problems.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kiss György · committed by Kiss György · parent 1647179 · Browse files · 3 files·+59 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+59 added−1 removed
- tests:+56 added−1 removed
- other:+3 added−0 removed
Provenance
- Commit
b8e826c- Tree
34a0e1d- Author
Kiss György <kissgyorgy@me.com>- Committer
Kiss György <kissgyorgy@me.com>- Parent
1647179
3 files changed+59 added−1 removed
modified:flask/cli.py+3 added
474 unmodified lines475 order_key = lambda rule: getattr(rule, order_by)476 sorted_rules = sorted(app.url_map.iter_rules(), key=order_key)477 478 max_rule = max(len(rule.rule) for rule in sorted_rules)479+ max_rule = max(max_rule, len('Route'))480 max_ep = max(len(rule.endpoint) for rule in sorted_rules)481+ max_ep = max(max_ep, len('Endpoint'))482 max_meth = max(len(', '.join(rule.methods)) for rule in sorted_rules)483+ max_meth = max(max_meth, len('Methods'))484 485 columnformat = '{:<%s} {:<%s} {:<%s}' % (max_rule, max_ep, max_meth)486 click.echo(columnformat.format('Route', 'Endpoint', 'Methods'))487 under_count = max_rule + max_ep + max_meth + 450 unmodified linesadded:tests/test_apps/cliapp/routesapp.py+18 added
1+from __future__ import absolute_import, print_function2+3+from flask import Flask4+5+6+noroute_app = Flask('noroute app')7+simpleroute_app = Flask('simpleroute app')8+only_POST_route_app = Flask('GET route app')9+10+11+@simpleroute_app.route('/simpleroute')12+def simple():13+ pass14+15+16+@only_POST_route_app.route('/only-post', methods=['POST'])17+def only_post():18+ passmodified:tests/test_cli.py+38 added-1 removed
18 unmodified lines19 import pytest20 from click.testing import CliRunner21 from flask import Flask, current_app22 23-from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \23+from flask.cli import cli, AppGroup, FlaskGroup, NoAppException, ScriptInfo, \24 find_best_app, locate_app, with_appcontext, prepare_exec_for_file, \25 find_default_import_path26 27 141 unmodified lines169 runner = CliRunner()170 result = runner.invoke(cli, ['test'])171 assert result.exit_code == 0172 assert result.output == 'flaskgroup\n'173+174+175+class TestRoutes:176+ def test_no_route(self, monkeypatch):177+ monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:noroute_app')178+ runner = CliRunner()179+ result = runner.invoke(cli, ['routes'], catch_exceptions=False)180+ assert result.exit_code == 0181+ assert result.output == """\182+Route Endpoint Methods 183+-----------------------------------------------------184+/static/<path:filename> static HEAD, OPTIONS, GET185+"""186+187+ def test_simple_route(self, monkeypatch):188+ monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:simpleroute_app')189+ runner = CliRunner()190+ result = runner.invoke(cli, ['routes'], catch_exceptions=False)191+ assert result.exit_code == 0192+ assert result.output == """\193+Route Endpoint Methods 194+-----------------------------------------------------195+/simpleroute simple HEAD, OPTIONS, GET196+/static/<path:filename> static HEAD, OPTIONS, GET197+"""198+199+ def test_only_POST_route(self, monkeypatch):200+ monkeypatch.setitem(os.environ, 'FLASK_APP', 'cliapp.routesapp:only_POST_route_app')201+ runner = CliRunner()202+ result = runner.invoke(cli, ['routes'], catch_exceptions=False)203+ assert result.exit_code == 0204+ assert result.output == """\205+Route Endpoint Methods 206+------------------------------------------------------207+/only-post only_post POST, OPTIONS 208+/static/<path:filename> static HEAD, OPTIONS, GET209+"""