mirror of
https://github.com/ansible/awx.git
synced 2026-01-18 21:21:21 -03:30
Use consistent error message when vars are not parsed correctly
This commit is contained in:
parent
b5ae83845e
commit
99fc0e8264
@ -1216,7 +1216,7 @@ class HostSerializer(BaseSerializerWithVariables):
|
||||
vars_dict['ansible_ssh_port'] = port
|
||||
attrs['variables'] = yaml.dump(vars_dict)
|
||||
except (yaml.YAMLError, TypeError):
|
||||
raise serializers.ValidationError(_('Must be valid JSON or YAML.'))
|
||||
raise serializers.ValidationError({'variables': _('Must be valid JSON or YAML.')})
|
||||
|
||||
return super(HostSerializer, self).validate(attrs)
|
||||
|
||||
@ -2693,7 +2693,7 @@ class JobLaunchSerializer(BaseSerializer):
|
||||
extra_vars = yaml.safe_load(extra_vars)
|
||||
assert isinstance(extra_vars, dict)
|
||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
||||
errors['extra_vars'] = _('Must be a valid JSON or YAML dictionary.')
|
||||
errors['extra_vars'] = _('Must be valid JSON or YAML.')
|
||||
|
||||
if not isinstance(extra_vars, dict):
|
||||
extra_vars = {}
|
||||
@ -2764,7 +2764,7 @@ class WorkflowJobLaunchSerializer(BaseSerializer):
|
||||
extra_vars = yaml.safe_load(extra_vars)
|
||||
assert isinstance(extra_vars, dict)
|
||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
||||
errors['extra_vars'] = 'Must be a valid JSON or YAML dictionary.'
|
||||
errors['extra_vars'] = _('Must be valid JSON or YAML.')
|
||||
|
||||
if not isinstance(extra_vars, dict):
|
||||
extra_vars = {}
|
||||
|
||||
@ -196,7 +196,8 @@ def test_job_reject_invalid_prompted_extra_vars(runtime_data, job_template_promp
|
||||
reverse('api:job_template_launch', args=[job_template.pk]),
|
||||
dict(extra_vars='{"unbalanced brackets":'), admin_user, expect=400)
|
||||
|
||||
assert response.data['extra_vars'] == ['Must be a valid JSON or YAML dictionary.']
|
||||
assert 'extra_vars' in response.data
|
||||
assert 'valid JSON or YAML' in str(response.data['extra_vars'][0])
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user