Make error message grammar more consistent

This commit is contained in:
AlanCoding
2016-05-17 14:02:18 -04:00
parent e32d20b5c4
commit f6b3da0c46
9 changed files with 77 additions and 75 deletions

View File

@@ -329,12 +329,12 @@ class Credential(PasswordFieldsModel, CommonModelNameNotUnique, ResourceMixin):
def clean_ssh_key_unlock(self):
if self.has_encrypted_ssh_key_data and not self.ssh_key_unlock:
raise ValidationError('SSH key unlock must be set when SSH key '
'is encrypted')
'is encrypted.')
return self.ssh_key_unlock
def clean(self):
if self.deprecated_user and self.deprecated_team:
raise ValidationError('Credential cannot be assigned to both a user and team')
raise ValidationError('Credential cannot be assigned to both a user and team.')
def _password_field_allows_ask(self, field):
return bool(self.kind == 'ssh' and field != 'ssh_key_data')
@@ -394,7 +394,7 @@ def validate_ssh_private_key(data):
'cert_bin': '', # Cert data as binary.
}
data = data.strip()
validation_error = ValidationError('Invalid private key')
validation_error = ValidationError('Invalid private key.')
# Sanity check: We may potentially receive a full PEM certificate,
# and we want to accept these.

View File

@@ -994,7 +994,7 @@ class InventorySourceOptions(BaseModel):
# an EC2 instance with an IAM Role assigned, boto will use credentials
# from the instance metadata instead of those explicitly provided.
elif self.source in CLOUD_PROVIDERS and self.source != 'ec2':
raise ValidationError('Credential is required for a cloud source')
raise ValidationError('Credential is required for a cloud source.')
return cred
def clean_source_regions(self):

View File

@@ -244,11 +244,11 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
def clean(self):
if self.job_type == 'scan' and (self.inventory is None or self.ask_inventory_on_launch):
raise ValidationError('Scan jobs must be assigned a fixed inventory')
raise ValidationError({"inventory": ["Scan jobs must be assigned a fixed inventory.",]})
if (not self.ask_inventory_on_launch) and self.inventory is None:
raise ValidationError('Job Template must either have an inventory or allow prompting for inventory')
raise ValidationError({"inventory": ["Job Template must provide 'inventory' or allow prompting for it.",]})
if (not self.ask_credential_on_launch) and self.credential is None:
raise ValidationError('Job Template must either have a credential or allow prompting for credential')
raise ValidationError({"credential": ["Job Template must provide 'credential' or allow prompting for it.",]})
return super(JobTemplate, self).clean()
def create_job(self, **kwargs):
@@ -292,9 +292,9 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
if not self.survey_enabled:
return errors
if 'name' not in self.survey_spec:
errors.append("'name' missing from survey spec")
errors.append("'name' missing from survey spec.")
if 'description' not in self.survey_spec:
errors.append("'description' missing from survey spec")
errors.append("'description' missing from survey spec.")
for survey_element in self.survey_spec.get("spec", []):
if survey_element['variable'] not in data and \
survey_element['required']:
@@ -302,50 +302,50 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, ResourceMixin):
elif survey_element['type'] in ["textarea", "text", "password"]:
if survey_element['variable'] in data:
if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < survey_element['min']:
errors.append("'%s' value %s is too small (must be at least %s)" %
errors.append("'%s' value %s is too small (must be at least %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > survey_element['max']:
errors.append("'%s' value %s is too large (must be no more than %s)" %
errors.append("'%s' value %s is too large (must be no more than %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
elif survey_element['type'] == 'integer':
if survey_element['variable'] in data:
if 'min' in survey_element and survey_element['min'] not in ["", None] and survey_element['variable'] in data and \
data[survey_element['variable']] < survey_element['min']:
errors.append("'%s' value %s is too small (must be at least %s)" %
errors.append("'%s' value %s is too small (must be at least %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
if 'max' in survey_element and survey_element['max'] not in ["", None] and survey_element['variable'] in data and \
data[survey_element['variable']] > survey_element['max']:
errors.append("'%s' value %s is too large (must be no more than %s)" %
errors.append("'%s' value %s is too large (must be no more than %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
if type(data[survey_element['variable']]) != int:
errors.append("Value %s for %s expected to be an integer" % (data[survey_element['variable']],
survey_element['variable']))
errors.append("Value %s for '%s' expected to be an integer." % (data[survey_element['variable']],
survey_element['variable']))
elif survey_element['type'] == 'float':
if survey_element['variable'] in data:
if 'min' in survey_element and survey_element['min'] not in ["", None] and data[survey_element['variable']] < survey_element['min']:
errors.append("'%s' value %s is too small (must be at least %s)" %
errors.append("'%s' value %s is too small (must be at least %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
if 'max' in survey_element and survey_element['max'] not in ["", None] and data[survey_element['variable']] > survey_element['max']:
errors.append("'%s' value %s is too large (must be no more than %s)" %
errors.append("'%s' value %s is too large (must be no more than %s)." %
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
if type(data[survey_element['variable']]) not in (float, int):
errors.append("Value %s for %s expected to be a numeric type" % (data[survey_element['variable']],
survey_element['variable']))
errors.append("Value %s for '%s' expected to be a numeric type." % (data[survey_element['variable']],
survey_element['variable']))
elif survey_element['type'] == 'multiselect':
if survey_element['variable'] in data:
if type(data[survey_element['variable']]) != list:
errors.append("'%s' value is expected to be a list" % survey_element['variable'])
errors.append("'%s' value is expected to be a list." % survey_element['variable'])
else:
for val in data[survey_element['variable']]:
if val not in survey_element['choices']:
errors.append("Value %s for %s expected to be one of %s" % (val, survey_element['variable'],
survey_element['choices']))
errors.append("Value %s for '%s' expected to be one of %s." % (val, survey_element['variable'],
survey_element['choices']))
elif survey_element['type'] == 'multiplechoice':
if survey_element['variable'] in data:
if data[survey_element['variable']] not in survey_element['choices']:
errors.append("Value %s for %s expected to be one of %s" % (data[survey_element['variable']],
survey_element['variable'],
survey_element['choices']))
errors.append("Value %s for '%s' expected to be one of %s." % (data[survey_element['variable']],
survey_element['variable'],
survey_element['choices']))
return errors
def _update_unified_job_kwargs(self, **kwargs):

View File

@@ -116,10 +116,10 @@ class ProjectOptions(models.Model):
scm_url = update_scm_url(self.scm_type, scm_url,
check_special_cases=False)
except ValueError, e:
raise ValidationError((e.args or ('Invalid SCM URL',))[0])
raise ValidationError((e.args or ('Invalid SCM URL.',))[0])
scm_url_parts = urlparse.urlsplit(scm_url)
if self.scm_type and not any(scm_url_parts):
raise ValidationError('SCM URL is required')
raise ValidationError('SCM URL is required.')
return unicode(self.scm_url or '')
def clean_credential(self):
@@ -128,7 +128,7 @@ class ProjectOptions(models.Model):
cred = self.credential
if cred:
if cred.kind != 'scm':
raise ValidationError('Credential kind must be "scm"')
raise ValidationError("Credential kind must be 'scm'.")
try:
scm_url = update_scm_url(self.scm_type, self.scm_url,
check_special_cases=False)
@@ -143,7 +143,7 @@ class ProjectOptions(models.Model):
update_scm_url(self.scm_type, self.scm_url, scm_username,
scm_password)
except ValueError, e:
raise ValidationError((e.args or ('Invalid credential',))[0])
raise ValidationError((e.args or ('Invalid credential.',))[0])
except ValueError:
pass
return cred

View File

@@ -61,7 +61,7 @@ def test_no_fact_found(hosts, get, user):
response = get(url, user('admin', True))
expected_response = {
"detail": "Fact not found"
"detail": "Fact not found."
}
assert 404 == response.status_code
assert expected_response == response.data

View File

@@ -159,7 +159,7 @@ def test_job_reject_invalid_prompted_extra_vars(runtime_data, job_template_promp
dict(extra_vars='{"unbalanced brackets":'), user('admin', True))
assert response.status_code == 400
assert response.data['extra_vars'] == ['Must be a valid JSON or YAML dictionary']
assert response.data['extra_vars'] == ['Must be a valid JSON or YAML dictionary.']
@pytest.mark.django_db
@pytest.mark.job_runtime_vars

View File

@@ -12,7 +12,7 @@ def mock_feature_disabled(feature, bypass_database=None):
return False
def mock_check_license(self, add_host=False, feature=None, check_expiration=True):
raise LicenseForbids("Feature %s is not enabled in the active license" % feature)
raise LicenseForbids("Feature %s is not enabled in the active license." % feature)
@pytest.fixture
def survey_jobtemplate(project, inventory, credential):
@@ -42,7 +42,7 @@ def test_deny_enabling_survey(deploy_jobtemplate, patch, user):
JT_url = reverse('api:job_template_detail', args=(deploy_jobtemplate.id,))
response = patch(url=JT_url, data=dict(survey_enabled=True), user=user('admin', True))
assert response.status_code == 402
assert response.data['detail'] == 'Feature surveys is not enabled in the active license'
assert response.data['detail'] == 'Feature surveys is not enabled in the active license.'
@mock.patch('awx.main.access.BaseAccess.check_license', mock_check_license)
@pytest.mark.django_db
@@ -61,7 +61,7 @@ def test_deny_creating_with_survey(machine_credential, project, inventory, post,
response = post(url=JT_url, data=JT_data, user=user('admin', True))
assert response.status_code == 402
assert response.data['detail'] == 'Feature surveys is not enabled in the active license'
assert response.data['detail'] == 'Feature surveys is not enabled in the active license.'
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
@pytest.mark.django_db
@@ -105,7 +105,7 @@ def test_survey_spec_non_dict_error(deploy_jobtemplate, post, user):
user=user('admin', True))
assert response.status_code == 400
assert response.data['error'] == "survey element 0 is not a json object"
assert response.data['error'] == "Survey question 0 is not a json object."
@mock.patch('awx.api.views.feature_enabled', new=mock_feature_enabled)
@pytest.mark.django_db
@@ -132,4 +132,4 @@ def test_survey_spec_dual_names_error(deploy_jobtemplate, post, user):
user=user('admin', True))
assert response.status_code == 400
assert response.data['error'] == "'variable' name 'submitter_email' duplicated in survey element 1"
assert response.data['error'] == "'variable' 'submitter_email' duplicated in survey question 1."