diff --git a/awx/main/tests/functional/api/test_notifications.py b/awx/main/tests/functional/api/test_notifications.py new file mode 100644 index 0000000000..d3cd3ca637 --- /dev/null +++ b/awx/main/tests/functional/api/test_notifications.py @@ -0,0 +1,24 @@ +import pytest + +from awx.api.versioning import reverse + + +@pytest.mark.django_db +def test_get_jt_running_notification(get, admin, job_template): + url = reverse('api:job_template_notification_templates_started_list', kwargs={'pk': job_template.pk}) + response = get(url, admin) + assert response.status_code == 200 + assert len(response.data['results']) == 0 + + +@pytest.mark.django_db +def test_post_jt_running_notification(get, post, admin, notification_template, job_template): + url = reverse('api:job_template_notification_templates_started_list', kwargs={'pk': job_template.pk}) + response = post(url, + dict(id=notification_template.id, + associate=True), + admin) + assert response.status_code == 204 + response = get(url, admin) + assert response.status_code == 200 + assert len(response.data['results']) == 1 diff --git a/docs/notification_system.md b/docs/notification_system.md index 1415f30c96..6b751beca3 100644 --- a/docs/notification_system.md +++ b/docs/notification_system.md @@ -22,9 +22,11 @@ Notification templates assigned at certain levels will inherit notifications def ## Workflow -When a job succeeds or fails, the error or success handler will pull a list of relevant notifications using the procedure defined above. It will then create a Notification object for each one containing relevant details about the job and then **sends** it to the destination (email addresses, slack channel(s), SMS numbers, etc.). These Notification objects are available as related resources on job types (Jobs, Inventory Updates, Project Updates), and also at `/api/v2/notifications`. You may also see what notifications have been sent from a notifications by examining its related resources. +When a job starts, succeeds or fails, the running, error or success handler will pull a list of relevant notifications using the procedure defined above. It will then create a Notification object for each one containing relevant details about the job and then **sends** it to the destination (email addresses, slack channel(s), SMS numbers, etc.). These Notification objects are available as related resources on job types (Jobs, Inventory Updates, Project Updates), and also at `/api/v2/notifications`. You may also see what notifications have been sent from a notifications by examining its related resources. -Notifications can succeed or fail but that will not cause its associated job to succeed or fail. The status of the notification can be viewed at its detail endpoint: `/api/v2/notifications/` +When a notification is associated to a job via the `/api/v2/.../notification_templates_any/` endpoint, it will send upon success OR fail, but _not_ on start. + +Notifications can succeed or fail but that will _not_ cause its associated job to succeed or fail. The status of the notification can be viewed at its detail endpoint: `/api/v2/notifications/` ## Testing Notifications Before Using Them