From 79d417f13b38fbaaed8be03e9bbe4ebb7e0e2680 Mon Sep 17 00:00:00 2001 From: Alexey Bezhan Date: Thu, 9 Nov 2017 14:48:27 +0000 Subject: [PATCH] Add TemplateHistory.get_link method Notifications.serialize calls `Notifications.template.get_link`, so we need TemplateHistory objects to generate their API URLs. This generates a link to the `/v2/` version of the endpoint. --- app/models.py | 8 ++++++++ tests/app/v2/notifications/test_get_notifications.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index 9d16c4968..f209dbb13 100644 --- a/app/models.py +++ b/app/models.py @@ -645,6 +645,14 @@ class TemplateHistory(db.Model): nullable=False, default=NORMAL) + def get_link(self): + return url_for( + "v2_template.get_template_by_id", + template_id=self.id, + version=self.version, + _external=True + ) + def _as_utils_template(self): return Template._as_utils_template(self) diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index d4306ba93..fc6b091c9 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -335,7 +335,7 @@ def test_get_all_notifications_filter_by_template_type(client): assert json_response['notifications'][0]['status'] == "created" assert json_response['notifications'][0]['template'] == { 'id': str(email_template.id), - 'uri': email_template.get_link(), + 'uri': notification.template.get_link(), 'version': 1 } assert json_response['notifications'][0]['email_address'] == "don.draper@scdp.biz"