mockity mock mock

This commit is contained in:
Chris Meyers
2016-03-28 15:30:38 -04:00
parent 141f5e807e
commit a01b2913bb
5 changed files with 307 additions and 12 deletions
+12 -7
View File
@@ -1551,6 +1551,14 @@ class JobOptionsSerializer(BaseSerializer):
args=(obj.cloud_credential.pk,))
return res
def _summary_field_labels(self, obj):
return [{'id': x.id, 'name': x.name} for x in obj.labels.all().order_by('-name')[:10]]
def get_summary_fields(self, obj):
res = super(JobOptionsSerializer, self).get_summary_fields(obj)
res['labels'] = self._summary_field_labels(obj)
return res
def to_representation(self, obj):
ret = super(JobOptionsSerializer, self).to_representation(obj)
if obj is None:
@@ -1607,6 +1615,9 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer):
res['callback'] = reverse('api:job_template_callback', args=(obj.pk,))
return res
def _recent_jobs(self, obj):
return [{'id': x.id, 'status': x.status, 'finished': x.finished} for x in obj.jobs.filter(active=True).order_by('-created')[:10]]
def get_summary_fields(self, obj):
d = super(JobTemplateSerializer, self).get_summary_fields(obj)
if obj.survey_spec is not None and ('name' in obj.survey_spec and 'description' in obj.survey_spec):
@@ -1625,8 +1636,7 @@ class JobTemplateSerializer(UnifiedJobTemplateSerializer, JobOptionsSerializer):
else:
d['can_copy'] = False
d['can_edit'] = False
d['recent_jobs'] = [{'id': x.id, 'status': x.status, 'finished': x.finished} for x in obj.jobs.filter(active=True).order_by('-created')[:10]]
d['labels'] = [{'id': x.id, 'name': x.name} for x in obj.labels.all().order_by('-name')[:10]]
d['recent_jobs'] = self._recent_jobs(obj)
return d
def validate(self, attrs):
@@ -1668,11 +1678,6 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
res['relaunch'] = reverse('api:job_relaunch', args=(obj.pk,))
return res
def get_summary_fields(self, obj):
d = super(JobSerializer, self).get_summary_fields(obj)
d['labels'] = [{'id': x.id, 'name': x.name} for x in obj.labels.all().order_by('-name')[:10]]
return d
def to_internal_value(self, data):
# When creating a new job and a job template is specified, populate any
# fields not provided in data from the job template.