From e4eb03259b3e10e59b9abfa0daeb1a885101cfa6 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Mon, 3 May 2021 12:11:36 -0700 Subject: [PATCH 1/2] include error field in notification template's list of recent notifs --- awx/api/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index c705a99dfd..48a6eebdfc 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4374,7 +4374,7 @@ class NotificationTemplateSerializer(BaseSerializer): return res def _recent_notifications(self, obj): - return [{'id': x.id, 'status': x.status, 'created': x.created} for x in obj.notifications.all().order_by('-created')[:5]] + return [{'id': x.id, 'status': x.status, 'created': x.created, 'error': x.error} for x in obj.notifications.all().order_by('-created')[:5]] def get_summary_fields(self, obj): d = super(NotificationTemplateSerializer, self).get_summary_fields(obj) From a6f381748852df0b9015e25ff3d4e0256d7d1c19 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Mon, 3 May 2021 13:12:31 -0700 Subject: [PATCH 2/2] verify notification errors included in NT list view --- .../tests/functional/test_notifications.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/awx/main/tests/functional/test_notifications.py b/awx/main/tests/functional/test_notifications.py index f6ae506248..881241ffb2 100644 --- a/awx/main/tests/functional/test_notifications.py +++ b/awx/main/tests/functional/test_notifications.py @@ -123,6 +123,29 @@ def test_disallow_delete_when_notifications_pending(delete, user, notification_t assert response.status_code == 405 +@pytest.mark.django_db +def test_notification_template_list_includes_notification_errors(get, user, notification_template): + Notification.objects.create(notification_template=notification_template, status='failed', error='failed to send') + Notification.objects.create(notification_template=notification_template, status='pending') + Notification.objects.create(notification_template=notification_template, status='successful') + url = reverse('api:notification_template_list') + u = user('superuser', True) + response = get(url, user=u) + + assert response.status_code == 200 + notifications = response.data['results'][0]['summary_fields']['recent_notifications'] + assert len(notifications) == 3 + statuses = [n['status'] for n in notifications] + assert set(statuses) == set(['failed', 'pending', 'successful']) + for n in notifications: + if n['status'] == 'successful': + assert n['error'] == '' + elif n['status'] == 'pending': + assert n['error'] == '' + elif n['status'] == 'failed': + assert n['error'] == 'failed to send' + + @pytest.mark.django_db def test_custom_environment_injection(post, user, organization): u = user('admin-poster', True)