Skip to content

Commit

Permalink
relax routes cli match order
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Jul 3, 2022
1 parent 12d3f4f commit ab6a8b0
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,22 +422,23 @@ def create_app():

class TestRoutes:
@pytest.fixture
def invoke(self, runner):
def create_app():
app = Flask(__name__)
app.testing = True
def app(self):
app = Flask(__name__)
app.testing = True

@app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])
def yyy_get_post(x, y):
pass
@app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])
def yyy_get_post(x, y):
pass

@app.route("/zzz_post", methods=["POST"])
def aaa_post():
pass
@app.route("/zzz_post", methods=["POST"])
def aaa_post():
pass

return app
return app

cli = FlaskGroup(create_app=create_app)
@pytest.fixture
def invoke(self, app, runner):
cli = FlaskGroup(create_app=lambda: app)
return partial(runner.invoke, cli)

@pytest.fixture
Expand All @@ -462,7 +463,7 @@ def test_simple(self, invoke):
assert result.exit_code == 0
self.expect_order(["aaa_post", "static", "yyy_get_post"], result.output)

def test_sort(self, invoke):
def test_sort(self, app, invoke):
default_output = invoke(["routes"]).output
endpoint_output = invoke(["routes", "-s", "endpoint"]).output
assert default_output == endpoint_output
Expand All @@ -474,10 +475,8 @@ def test_sort(self, invoke):
["yyy_get_post", "static", "aaa_post"],
invoke(["routes", "-s", "rule"]).output,
)
self.expect_order(
["aaa_post", "yyy_get_post", "static"],
invoke(["routes", "-s", "match"]).output,
)
match_order = [r.endpoint for r in app.url_map.iter_rules()]
self.expect_order(match_order, invoke(["routes", "-s", "match"]).output)

def test_all_methods(self, invoke):
output = invoke(["routes"]).output
Expand Down

0 comments on commit ab6a8b0

Please sign in to comment.