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) 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)