Skip to content
Myr

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

3 files+59 added−1 removed

modified:flask/cli.py+3 added
474 unmodified lines
475 order_key = lambda rule: getattr(rule, order_by)476 sorted_rules = sorted(app.url_map.iter_rules(), key=order_key)477478 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'))484485 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 + 4
50 unmodified lines
added:tests/test_apps/cliapp/routesapp.py+18 added
1from __future__ import absolute_import, print_function23from flask import Flask456noroute_app = Flask('noroute app')7simpleroute_app = Flask('simpleroute app')8only_POST_route_app = Flask('GET route app')91011@simpleroute_app.route('/simpleroute')12def simple():13 pass141516@only_POST_route_app.route('/only-post', methods=['POST'])17def only_post():18 pass
modified:tests/test_cli.py+38 added-1 removed
18 unmodified lines
19import pytest20from click.testing import CliRunner21from flask import Flask, current_app2223from flask.cli import AppGroup, FlaskGroup, NoAppException, ScriptInfo, \23from flask.cli import cli, AppGroup, FlaskGroup, NoAppException, ScriptInfo, \24 find_best_app, locate_app, with_appcontext, prepare_exec_for_file, \25 find_default_import_path2627
141 unmodified lines
169 runner = CliRunner()170 result = runner.invoke(cli, ['test'])171 assert result.exit_code == 0172 assert result.output == 'flaskgroup\n'173174175class 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 == """\182Route Endpoint Methods 183-----------------------------------------------------184/static/<path:filename> static HEAD, OPTIONS, GET185"""186187 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 == """\193Route Endpoint Methods 194-----------------------------------------------------195/simpleroute simple HEAD, OPTIONS, GET196/static/<path:filename> static HEAD, OPTIONS, GET197"""198199 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 == """\205Route Endpoint Methods 206------------------------------------------------------207/only-post only_post POST, OPTIONS 208/static/<path:filename> static HEAD, OPTIONS, GET209"""