diff --git a/app/models.py b/app/models.py index 9f3a583a9..e5785582f 100644 --- a/app/models.py +++ b/app/models.py @@ -284,7 +284,12 @@ class Template(db.Model): def get_link(self): # TODO: use "/v2/" route once available - return url_for("template.get_template_by_id_and_service_id", service_id=self.service_id, template_id=self.id) + return url_for( + "template.get_template_by_id_and_service_id", + service_id=self.service_id, + template_id=self.id, + _external=True + ) class TemplateHistory(db.Model): diff --git a/app/v2/notifications/get_notifications.py b/app/v2/notifications/get_notifications.py index 77ba0379c..274df52d7 100644 --- a/app/v2/notifications/get_notifications.py +++ b/app/v2/notifications/get_notifications.py @@ -29,12 +29,12 @@ def get_notifications(): def _build_links(notifications): _links = { - 'current': url_for(".get_notifications", **request.args.to_dict(flat=False)), + 'current': url_for(".get_notifications", _external=True, **request.args.to_dict(flat=False)), } if len(notifications): next_query_params = dict(request.args.to_dict(flat=False), older_than=notifications[-1].id) - _links['next'] = url_for(".get_notifications", **next_query_params) + _links['next'] = url_for(".get_notifications", _external=True, **next_query_params) return _links diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 423243e6c..3c1b93134 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -73,7 +73,7 @@ def test_get_all_notifications_returns_200(client, notify_db, notify_db_session) assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications" + assert json_response['links']['current'].endswith("/v2/notifications") assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 2 @@ -98,7 +98,7 @@ def test_get_all_notifications_no_notifications_if_no_notificatons(client, sampl assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications" + assert json_response['links']['current'].endswith("/v2/notifications") assert 'next' not in json_response['links'].keys() assert len(json_response['notifications']) == 0 @@ -120,7 +120,7 @@ def test_get_all_notifications_filter_by_template_type(client, notify_db, notify assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?template_type=email" + assert json_response['links']['current'].endswith("/v2/notifications?template_type=email") assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 1 @@ -148,7 +148,7 @@ def test_get_all_notifications_filter_by_single_status(client, notify_db, notify assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?status=pending" + assert json_response['links']['current'].endswith("/v2/notifications?status=pending") assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 1 @@ -172,7 +172,7 @@ def test_get_all_notifications_filter_by_multiple_statuses(client, notify_db, no assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?status=created&status=pending&status=sending" + assert json_response['links']['current'].endswith("/v2/notifications?status=created&status=pending&status=sending") assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 3 @@ -199,7 +199,7 @@ def test_get_all_notifications_filter_by_failed_status(client, notify_db, notify assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?status=failed" + assert json_response['links']['current'].endswith("/v2/notifications?status=failed") assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 3 @@ -223,7 +223,7 @@ def test_get_all_notifications_filter_by_id(client, notify_db, notify_db_session assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?older_than={}".format(newer_notification.id) + assert json_response['links']['current'].endswith("/v2/notifications?older_than={}".format(newer_notification.id)) assert 'next' in json_response['links'].keys() assert len(json_response['notifications']) == 1 @@ -242,7 +242,8 @@ def test_get_all_notifications_filter_by_id_no_notifications_if_nonexistent_id(c assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?older_than=dd4b8b9d-d414-4a83-9256-580046bf18f9" + assert json_response['links']['current'].endswith( + "/v2/notifications?older_than=dd4b8b9d-d414-4a83-9256-580046bf18f9") assert 'next' not in json_response['links'].keys() assert len(json_response['notifications']) == 0 @@ -259,7 +260,7 @@ def test_get_all_notifications_filter_by_id_no_notifications_if_last_notificatio assert response.status_code == 200 assert response.headers['Content-type'] == "application/json" - assert json_response['links']['current'] == "/v2/notifications?older_than={}".format(notification.id) + assert json_response['links']['current'].endswith("/v2/notifications?older_than={}".format(notification.id)) assert 'next' not in json_response['links'].keys() assert len(json_response['notifications']) == 0