mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 03:30:02 -03:30
Better handle missing notification_type in patches to notification template
Addresses #2628
This commit is contained in:
@@ -2435,6 +2435,8 @@ class NotificationTemplateSerializer(BaseSerializer):
|
|||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
from awx.api.views import NotificationTemplateDetail
|
from awx.api.views import NotificationTemplateDetail
|
||||||
|
if 'notification_type' not in attrs:
|
||||||
|
raise serializers.ValidationError('Missing required fields for Notification Configuration: notification_type')
|
||||||
notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[attrs['notification_type']]
|
notification_class = NotificationTemplate.CLASS_FOR_NOTIFICATION_TYPE[attrs['notification_type']]
|
||||||
missing_fields = []
|
missing_fields = []
|
||||||
incorrect_type_fields = []
|
incorrect_type_fields = []
|
||||||
|
|||||||
@@ -104,3 +104,7 @@ def test_notification_template_merging(get, post, user, organization, project, n
|
|||||||
organization.notification_templates_any.add(notification_template)
|
organization.notification_templates_any.add(notification_template)
|
||||||
project.notification_templates_any.add(notification_template)
|
project.notification_templates_any.add(notification_template)
|
||||||
assert len(project.notification_templates['any']) == 1
|
assert len(project.notification_templates['any']) == 1
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_notification_template_invalid_patch(patch, notification_template, organization, admin):
|
||||||
|
patch(reverse('api:notification_template_detail', args=(notification_template.id,)), { 'organization': organization.id}, admin, expect=400)
|
||||||
|
|||||||
Reference in New Issue
Block a user