URLs in API responses have full URL

This commit is contained in:
Paul Craig
2016-11-28 11:13:11 +00:00
parent 268e19bb76
commit 9b1375ba84
3 changed files with 18 additions and 12 deletions

View File

@@ -284,7 +284,12 @@ class Template(db.Model):
def get_link(self): def get_link(self):
# TODO: use "/v2/" route once available # 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): class TemplateHistory(db.Model):

View File

@@ -29,12 +29,12 @@ def get_notifications():
def _build_links(notifications): def _build_links(notifications):
_links = { _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): if len(notifications):
next_query_params = dict(request.args.to_dict(flat=False), older_than=notifications[-1].id) 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 return _links

View File

@@ -73,7 +73,7 @@ def test_get_all_notifications_returns_200(client, notify_db, notify_db_session)
assert response.status_code == 200 assert response.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 2 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' not in json_response['links'].keys()
assert len(json_response['notifications']) == 0 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 1 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 1 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 3 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 3 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' in json_response['links'].keys()
assert len(json_response['notifications']) == 1 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' not in json_response['links'].keys()
assert len(json_response['notifications']) == 0 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.status_code == 200
assert response.headers['Content-type'] == "application/json" 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 'next' not in json_response['links'].keys()
assert len(json_response['notifications']) == 0 assert len(json_response['notifications']) == 0