mirror of
https://github.com/ansible/awx.git
synced 2026-01-17 12:41:19 -03:30
Merge pull request #10094 from jladdjr/awx_8853_add_notification_error_to_nt_listview
add notification error to notification template list view In support of #8853 Updates /api/v2/notification_templates to include the error field for summary_fields -> recent_notifications Reviewed-by: Bianca Henderson <beeankha@gmail.com>
This commit is contained in:
commit
e08590290c
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user