From 37f0c4459b5c1fc72b9c6a2a1e4ffffd8e933254 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 13 Nov 2019 15:10:16 +0000 Subject: [PATCH] Prefer shorter URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flask will pick the first route that matches. Decorators get applied from innermost to outermost. So if the same endpoint is served at `/abc` and `/123` the one used when `url_for` is generating a URL is whichever decorator is lowest (in terms of line number). It doesn’t functionally make a difference, but it’s causing the functional tests to fail at the moment. And shorter URLs are nicer, so I think it makes sense to change here, rather than change the tests. --- app/main/views/templates.py | 2 +- tests/app/test_navigation.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 16e6192cc..381117f9d 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -105,8 +105,8 @@ def start_tour(service_id, template_id): ) -@main.route("/services//templates", methods=['GET', 'POST']) @main.route("/services//templates/all", methods=['GET', 'POST']) +@main.route("/services//templates", methods=['GET', 'POST']) @main.route("/services//templates/folders/", methods=['GET', 'POST']) @main.route("/services//templates/", methods=['GET', 'POST']) @main.route("/services//templates/all/folders/", methods=['GET', 'POST']) diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 94bf7ec3b..96b1cb8ce 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -148,6 +148,24 @@ def test_a_page_should_nave_selected_org_navigation_item( assert selected_nav_items[0].text.strip() == selected_nav_item +def test_navigation_urls( + client_request, + mock_get_service_templates, + mock_get_template_folders, +): + page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID) + assert [ + a['href'] for a in page.select('.navigation a') + ] == [ + '/services/{}'.format(SERVICE_ONE_ID), + '/services/{}/templates'.format(SERVICE_ONE_ID), + '/services/{}/users'.format(SERVICE_ONE_ID), + '/services/{}/usage'.format(SERVICE_ONE_ID), + '/services/{}/service-settings'.format(SERVICE_ONE_ID), + '/services/{}/api'.format(SERVICE_ONE_ID), + ] + + def test_caseworkers_get_caseworking_navigation( client_request, mocker,