diff --git a/awx/api/serializers.py b/awx/api/serializers.py index d7d38c3b4f..eb0d5141e7 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -2435,7 +2435,16 @@ class NotificationTemplateSerializer(BaseSerializer): def validate(self, attrs): from awx.api.views import NotificationTemplateDetail - notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[attrs['notification_type']] + + notification_type = None + if 'notification_type' in attrs: + notification_type = attrs['notification_type'] + elif self.instance: + notification_type = self.instance.notification_type + if not notification_type: + raise serializers.ValidationError('Missing required fields for Notification Configuration: notification_type') + + notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[notification_type] missing_fields = [] incorrect_type_fields = [] error_list = [] diff --git a/awx/main/tests/functional/test_notifications.py b/awx/main/tests/functional/test_notifications.py index d6db3e608c..c54e9fb3f2 100644 --- a/awx/main/tests/functional/test_notifications.py +++ b/awx/main/tests/functional/test_notifications.py @@ -104,3 +104,11 @@ def test_notification_template_merging(get, post, user, organization, project, n organization.notification_templates_any.add(notification_template) project.notification_templates_any.add(notification_template) assert len(project.notification_templates['any']) == 1 + +@pytest.mark.django_db +def test_notification_template_simple_patch(patch, notification_template, admin): + patch(reverse('api:notification_template_detail', args=(notification_template.id,)), { 'name': 'foo'}, admin, expect=200) + +@pytest.mark.django_db +def test_notification_template_invalid_notification_type(patch, notification_template, admin): + patch(reverse('api:notification_template_detail', args=(notification_template.id,)), { 'notification_type': 'invalid'}, admin, expect=400)