From 9f3621b75eb307f4243605a5175df22ff16dc5bd Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 14 Jan 2016 14:03:27 +0000 Subject: [PATCH] Use url_for to generate URLs > it is about consistency and updates, if that endpoint changes in the future > we don't have to update hundreds of tests for a specific string. The actual > url should be ambiguous we are testing a view endpoint. --- tests/app/main/views/test_templates.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index 924f3d311..1b63d573c 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -1,3 +1,4 @@ +from flask import url_for from tests.app.main import create_test_user @@ -6,7 +7,7 @@ def test_should_return_list_of_all_templates(notifications_admin, notifications_ with notifications_admin.test_client() as client: user = create_test_user('active') client.login(user) - response = client.get('/services/123/templates') + response = client.get(url_for('.manage_templates', service_id=123)) assert response.status_code == 200 @@ -16,7 +17,7 @@ def test_should_show_page_for_one_template(notifications_admin, notifications_ad with notifications_admin.test_client() as client: user = create_test_user('active') client.login(user) - response = client.get('/services/123/templates/1') + response = client.get(url_for('.edit_template', service_id=123, template_id=1)) assert response.status_code == 200 @@ -26,10 +27,10 @@ def test_should_redirect_when_saving_a_template(notifications_admin, notificatio with notifications_admin.test_client() as client: user = create_test_user('active') client.login(user) - response = client.post('/services/123/templates/1') + response = client.post(url_for('.edit_template', service_id=123, template_id=1)) - assert response.status_code == 302 - assert response.location == 'http://localhost/services/123/templates' + assert response.status_code == 302 + assert response.location == url_for('.manage_templates', service_id=123, _external=True) def test_should_show_delete_template_page(notifications_admin, notifications_admin_db, notify_db_session): @@ -37,7 +38,7 @@ def test_should_show_delete_template_page(notifications_admin, notifications_adm with notifications_admin.test_client() as client: user = create_test_user('active') client.login(user) - response = client.get('/services/123/templates/1/delete') + response = client.get(url_for('.delete_template', service_id=123, template_id=1)) assert response.status_code == 200 assert 'Are you sure' in response.get_data(as_text=True) @@ -48,7 +49,7 @@ def test_should_redirect_when_deleting_a_template(notifications_admin, notificat with notifications_admin.test_client() as client: user = create_test_user('active') client.login(user) - response = client.post('/services/123/templates/1/delete') + response = client.post(url_for('.delete_template', service_id=123, template_id=1)) - assert response.status_code == 302 - assert response.location == 'http://localhost/services/123/templates' + assert response.status_code == 302 + assert response.location == url_for('.manage_templates', service_id=123, _external=True)