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

@@ -849,7 +849,7 @@ class ProjectOptionsSerializer(BaseSerializer):
if scm_type:
attrs.pop('local_path', None)
if 'local_path' in attrs and attrs['local_path'] not in valid_local_paths:
errors['local_path'] = 'Invalid path choice'
errors['local_path'] = 'Invalid path choice.'
if errors:
raise serializers.ValidationError(errors)
@@ -1305,14 +1305,14 @@ class InventorySourceOptionsSerializer(BaseSerializer):
source_script = attrs.get('source_script', self.instance and self.instance.source_script or '')
if source == 'custom':
if source_script is None or source_script == '':
errors['source_script'] = 'source_script must be provided'
errors['source_script'] = "If 'source' is 'custom', 'source_script' must be provided."
else:
try:
if source_script.organization != self.instance.inventory.organization:
errors['source_script'] = 'source_script does not belong to the same organization as the inventory.'
errors['source_script'] = "The 'source_script' does not belong to the same organization as the inventory."
except Exception:
# TODO: Log
errors['source_script'] = 'source_script doesn\'t exist.'
errors['source_script'] = "'source_script' doesn't exist."
if errors:
raise serializers.ValidationError(errors)
@@ -1813,7 +1813,7 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer):
return value
except yaml.YAMLError:
pass
raise serializers.ValidationError('Must be valid JSON or YAML')
raise serializers.ValidationError('Must be valid JSON or YAML.')
class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
@@ -1860,7 +1860,7 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
try:
job_template = JobTemplate.objects.get(pk=data['job_template'])
except JobTemplate.DoesNotExist:
self._errors = {'job_template': 'Invalid job template'}
self._errors = {'job_template': 'Invalid job template.'}
return
data.setdefault('name', job_template.name)
data.setdefault('description', job_template.description)
@@ -2278,7 +2278,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 a valid JSON or YAML dictionary.'
if not isinstance(extra_vars, dict):
extra_vars = {}
@@ -2385,11 +2385,11 @@ class NotificationTemplateSerializer(BaseSerializer):
attrs['notification_configuration'][field] = object_actual.notification_configuration[field]
error_list = []
if missing_fields:
error_list.append("Missing required fields for Notification Configuration: {}".format(missing_fields))
error_list.append("Missing required fields for Notification Configuration: {}.".format(missing_fields))
if incorrect_type_fields:
for type_field_error in incorrect_type_fields:
error_list.append("Configuration field '{}' incorrect type, expected {}".format(type_field_error[0],
type_field_error[1]))
error_list.append("Configuration field '{}' incorrect type, expected {}.".format(type_field_error[0],
type_field_error[1]))
if error_list:
raise serializers.ValidationError(error_list)
return attrs
@@ -2509,9 +2509,11 @@ class ActivityStreamSerializer(BaseSerializer):
if key == 'changes':
field.help_text = 'A summary of the new and changed values when an object is created, updated, or deleted'
if key == 'object1':
field.help_text = 'For create, update, and delete events this is the object type that was affected. For associate and disassociate events this is the object type associated or disassociated with object2'
field.help_text = ('For create, update, and delete events this is the object type that was affected. '
'For associate and disassociate events this is the object type associated or disassociated with object2.')
if key == 'object2':
field.help_text = 'Unpopulated for create, update, and delete events. For associate and disassociate events this is the object type that object1 is being associated with'
field.help_text = ('Unpopulated for create, update, and delete events. For associate and disassociate '
'events this is the object type that object1 is being associated with.')
if key == 'operation':
field.help_text = 'The action taken with respect to the given object(s).'
return ret
@@ -2617,7 +2619,7 @@ class TowerSettingsSerializer(BaseSerializer):
def to_internal_value(self, data):
if data['key'] not in settings.TOWER_SETTINGS_MANIFEST:
self._errors = {'key': 'Key {0} is not a valid settings key'.format(data['key'])}
self._errors = {'key': 'Key {0} is not a valid settings key.'.format(data['key'])}
return
ret = super(TowerSettingsSerializer, self).to_internal_value(data)
manifest_val = settings.TOWER_SETTINGS_MANIFEST[data['key']]

View File

@@ -856,7 +856,7 @@ class TeamRolesList(SubListCreateAttachDetachAPIView):
# Forbid implicit role creation here
sub_id = request.data.get('id', None)
if not sub_id:
data = dict(msg='Role "id" field is missing')
data = dict(msg="Role 'id' field is missing.")
return Response(data, status=status.HTTP_400_BAD_REQUEST)
return super(TeamRolesList, self).post(request, *args, **kwargs)
@@ -1138,7 +1138,7 @@ class UserRolesList(SubListCreateAttachDetachAPIView):
# Forbid implicit role creation here
sub_id = request.data.get('id', None)
if not sub_id:
data = dict(msg='Role "id" field is missing')
data = dict(msg="Role 'id' field is missing.")
return Response(data, status=status.HTTP_400_BAD_REQUEST)
if sub_id == self.request.user.admin_role.pk:
@@ -1269,10 +1269,10 @@ class CredentialList(ListCreateAPIView):
kwargs.pop(field, None)
if not any([x in request.data for x in ['user', 'team', 'organization']]):
return Response({'detail': 'Missing user, team, or organization'}, status=status.HTTP_400_BAD_REQUEST)
return Response({"detail": "Missing 'user', 'team', or 'organization'."}, status=status.HTTP_400_BAD_REQUEST)
if sum([1 if x in request.data else 0 for x in ['user', 'team', 'organization']]) != 1:
return Response({'detail': 'Expecting exactly one of user, team, or organization'}, status=status.HTTP_400_BAD_REQUEST)
return Response({"detail": "Expecting exactly one of 'user', 'team', or 'organization'."}, status=status.HTTP_400_BAD_REQUEST)
if 'user' in request.data:
user = User.objects.get(pk=request.data['user'])
@@ -1651,7 +1651,7 @@ class HostFactCompareView(SubDetailAPIView, SystemTrackingEnforcementMixin):
fact_entry = Fact.get_host_fact(host_obj.id, module_spec, datetime_actual)
if not fact_entry:
return Response({'detail': 'Fact not found'}, status=status.HTTP_404_NOT_FOUND)
return Response({'detail': 'Fact not found.'}, status=status.HTTP_404_NOT_FOUND)
return Response(self.serializer_class(instance=fact_entry).data)
class GroupList(ListCreateAPIView):
@@ -1694,7 +1694,7 @@ class GroupChildrenList(SubListCreateAttachDetachAPIView):
'''
sub_id = request.data.get('id', None)
if not sub_id:
data = dict(msg='"id" is required to disassociate')
data = dict(msg="'id' is required to disassociate.")
return Response(data, status=status.HTTP_400_BAD_REQUEST)
parent = self.get_parent_object()
@@ -2070,7 +2070,7 @@ class InventorySourceNotificationTemplatesAnyList(SubListCreateAttachDetachAPIVi
def post(self, request, *args, **kwargs):
parent = self.get_parent_object()
if parent.source not in CLOUD_INVENTORY_SOURCES:
return Response(dict(msg="Notification Templates can only be assigned when source is one of {}"
return Response(dict(msg="Notification Templates can only be assigned when source is one of {}."
.format(CLOUD_INVENTORY_SOURCES, parent.source)),
status=status.HTTP_400_BAD_REQUEST)
return super(InventorySourceNotificationTemplatesAnyList, self).post(request, *args, **kwargs)
@@ -2288,34 +2288,34 @@ class JobTemplateSurveySpec(GenericAPIView):
obj.survey_spec = json.dumps(request.data)
except ValueError:
# TODO: Log
return Response(dict(error="Invalid JSON when parsing survey spec"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="Invalid JSON when parsing survey spec."), status=status.HTTP_400_BAD_REQUEST)
if "name" not in obj.survey_spec:
return Response(dict(error="'name' missing from survey spec"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'name' missing from survey spec."), status=status.HTTP_400_BAD_REQUEST)
if "description" not in obj.survey_spec:
return Response(dict(error="'description' missing from survey spec"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'description' missing from survey spec."), status=status.HTTP_400_BAD_REQUEST)
if "spec" not in obj.survey_spec:
return Response(dict(error="'spec' missing from survey spec"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'spec' missing from survey spec."), status=status.HTTP_400_BAD_REQUEST)
if not isinstance(obj.survey_spec["spec"], list):
return Response(dict(error="'spec' must be a list of items"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'spec' must be a list of items."), status=status.HTTP_400_BAD_REQUEST)
if len(obj.survey_spec["spec"]) < 1:
return Response(dict(error="'spec' doesn't contain any items"), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'spec' doesn't contain any items."), status=status.HTTP_400_BAD_REQUEST)
idx = 0
variable_set = set()
for survey_item in obj.survey_spec["spec"]:
if not isinstance(survey_item, dict):
return Response(dict(error="survey element %s is not a json object" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="Survey question %s is not a json object." % str(idx)), status=status.HTTP_400_BAD_REQUEST)
if "type" not in survey_item:
return Response(dict(error="'type' missing from survey element %s" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'type' missing from survey question %s." % str(idx)), status=status.HTTP_400_BAD_REQUEST)
if "question_name" not in survey_item:
return Response(dict(error="'question_name' missing from survey element %s" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'question_name' missing from survey question %s." % str(idx)), status=status.HTTP_400_BAD_REQUEST)
if "variable" not in survey_item:
return Response(dict(error="'variable' missing from survey element %s" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'variable' missing from survey question %s." % str(idx)), status=status.HTTP_400_BAD_REQUEST)
if survey_item['variable'] in variable_set:
return Response(dict(error="'variable' name '%s' duplicated in survey element %s" % (survey_item['variable'], str(idx))), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'variable' '%s' duplicated in survey question %s." % (survey_item['variable'], str(idx))), status=status.HTTP_400_BAD_REQUEST)
else:
variable_set.add(survey_item['variable'])
if "required" not in survey_item:
return Response(dict(error="'required' missing from survey element %s" % str(idx)), status=status.HTTP_400_BAD_REQUEST)
return Response(dict(error="'required' missing from survey question %s." % str(idx)), status=status.HTTP_400_BAD_REQUEST)
idx += 1
obj.save()
return Response()
@@ -2516,7 +2516,7 @@ class JobTemplateCallback(GenericAPIView):
# NOTE: We limit this to one job waiting per host per callblack to keep them from stacking crazily
if Job.objects.filter(status__in=['pending', 'waiting', 'running'], job_template=job_template,
limit=limit).count() > 0:
data = dict(msg='Host callback job already pending')
data = dict(msg='Host callback job already pending.')
return Response(data, status=status.HTTP_400_BAD_REQUEST)
# Everything is fine; actually create the job.
@@ -2861,7 +2861,7 @@ class JobJobPlaysList(BaseJobEventsList):
all_plays = []
job = Job.objects.filter(pk=self.kwargs['pk'])
if not job.exists():
return ({'detail': 'job not found'}, -1, status.HTTP_404_NOT_FOUND)
return ({'detail': 'Job not found.'}, -1, status.HTTP_404_NOT_FOUND)
job = job[0]
# Put together a queryset for relevant job events.
@@ -2943,15 +2943,15 @@ class JobJobTasksList(BaseJobEventsList):
# If there's no event ID specified, this will return a 404.
job = Job.objects.filter(pk=self.kwargs['pk'])
if not job.exists():
return ({'detail': 'job not found'}, -1, status.HTTP_404_NOT_FOUND)
return ({'detail': 'Job not found.'}, -1, status.HTTP_404_NOT_FOUND)
job = job[0]
if 'event_id' not in request.query_params:
return ({'detail': '"event_id" not provided'}, -1, status.HTTP_400_BAD_REQUEST)
return ({"detail": "'event_id' not provided."}, -1, status.HTTP_400_BAD_REQUEST)
parent_task = job.job_events.filter(pk=int(request.query_params.get('event_id', -1)))
if not parent_task.exists():
return ({'detail': 'parent event not found'}, -1, status.HTTP_404_NOT_FOUND)
return ({'detail': 'Parent event not found.'}, -1, status.HTTP_404_NOT_FOUND)
parent_task = parent_task[0]
# Some events correspond to a playbook or task starting up,
@@ -3624,7 +3624,7 @@ class RoleUsersList(SubListCreateAttachDetachAPIView):
# Forbid implicit role creation here
sub_id = request.data.get('id', None)
if not sub_id:
data = dict(msg='Role "id" field is missing')
data = dict(msg="Role 'id' field is missing.")
return Response(data, status=status.HTTP_400_BAD_REQUEST)
return super(RoleUsersList, self).post(request, *args, **kwargs)
@@ -3647,7 +3647,7 @@ class RoleTeamsList(ListAPIView):
# Forbid implicit role creation here
sub_id = request.data.get('id', None)
if not sub_id:
data = dict(msg='Role "id" field is missing')
data = dict(msg="Role 'id' field is missing.")
return Response(data, status=status.HTTP_400_BAD_REQUEST)
# XXX: Need to pull in can_attach and can_unattach kinda code from SubListCreateAttachDetachAPIView
role = Role.objects.get(pk=self.kwargs['pk'])