Merge pull request #7087 from AlanCoding/message_tweaking

tweaks to SCM inventory related validation errors
This commit is contained in:
Alan Rominger
2017-07-14 16:02:53 -04:00
committed by GitHub

View File

@@ -1638,7 +1638,7 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
return ret
def validate_source_project(self, value):
if value.scm_type == '':
if value and value.scm_type == '':
raise serializers.ValidationError(_("Can not use manual project for SCM-based inventory."))
return value
@@ -1648,6 +1648,11 @@ class InventorySourceSerializer(UnifiedJobTemplateSerializer, InventorySourceOpt
"Manual inventory sources are created automatically when a group is created in the v1 API."))
return value
def validate_update_on_project_update(self, value):
if value and self.instance and self.instance.schedules.exists():
raise serializers.ValidationError(_("Setting not compatible with existing schedules."))
return value
def validate(self, attrs):
def get_field_from_model_or_attrs(fd):
return attrs.get(fd, self.instance and getattr(self.instance, fd) or None)
@@ -3418,7 +3423,7 @@ class ScheduleSerializer(BaseSerializer):
raise serializers.ValidationError(_('Manual Project can not have a schedule set.'))
elif type(value) == InventorySource and value.source == 'scm' and value.update_on_project_update:
raise serializers.ValidationError(_(
'Inventory sources with `update_on_project_update` can not be shceduled. '
'Inventory sources with `update_on_project_update` cannot be scheduled. '
'Schedule its source project `{}` instead.'.format(value.source_project.name)))
return value