From 76d6b30bc61bac3dee5b28b72c7c8526798b95c7 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 14 Mar 2018 14:42:48 -0400 Subject: [PATCH 1/2] Include 'grade' in timecards.json response. --- tock/api/tests.py | 14 ++++++++++++++ tock/api/views.py | 3 +++ tock/hours/fixtures/timecards.json | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/tock/api/tests.py b/tock/api/tests.py index 84bbfaa02..435bb98af 100644 --- a/tock/api/tests.py +++ b/tock/api/tests.py @@ -70,6 +70,20 @@ def test_timecards_json(self): clean_res = json.loads(res.decode()) self.assertEqual(len(clean_res), 2) + def test_timecards_grade_is_null_when_absent(self): + res = client(self).get( + reverse('TimecardList'), + data={'date': '2016-06-01'}).content + clean_res = json.loads(res.decode()) + self.assertEqual(clean_res[0]['grade'], None) + + def test_timecards_grade_is_populated_when_present(self): + res = client(self).get( + reverse('TimecardList'), + data={'date': '2015-06-01'}).content + clean_res = json.loads(res.decode()) + self.assertEqual(clean_res[0]['grade'], 4) + # TODO: test with more diverse data def test_get_timecards(self): """ Check that get time cards returns the correct queryset """ diff --git a/tock/api/views.py b/tock/api/views.py index e2e853464..bfcda6e12 100644 --- a/tock/api/views.py +++ b/tock/api/views.py @@ -109,6 +109,8 @@ class TimecardSerializer(serializers.Serializer): project_organization = serializers.CharField( source='project.organization_name' ) + grade = serializers.IntegerField( + source='grade.grade') # API Views @@ -167,6 +169,7 @@ class TimecardList(generics.ListAPIView): 'timecard__user', 'project__accounting_code__agency', 'timecard__reporting_period', + 'grade', ).order_by( 'timecard__reporting_period__start_date' ) diff --git a/tock/hours/fixtures/timecards.json b/tock/hours/fixtures/timecards.json index 75dcfefef..593b72f87 100644 --- a/tock/hours/fixtures/timecards.json +++ b/tock/hours/fixtures/timecards.json @@ -1,4 +1,13 @@ [ + { + "model": "employees.EmployeeGrade", + "fields": { + "employee": 1, + "grade": 4, + "g_start_date": "2015-05-28" + }, + "pk": 1 + }, { "model": "hours.reportingperiod", "fields": { @@ -24,6 +33,7 @@ "timecard": 1, "project": 1, "hours_spent": 20, + "grade": 1, "created": "2015-06-08T12:00:00.000Z", "modified": "2015-06-08T12:00:00.000Z" }, From 4015bf606f1b9bad899559c9cc36e6bbead3aeb5 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 14 Mar 2018 16:57:38 -0400 Subject: [PATCH 2/2] Document 'grade' in api docs. --- api-docs/projects.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api-docs/projects.md b/api-docs/projects.md index 041adcc1c..139aca075 100644 --- a/api-docs/projects.md +++ b/api-docs/projects.md @@ -32,6 +32,7 @@ To fetch a list of projects information. "billable": true, "start_date": null, "end_date": null, + "grade": 16, "active": true },... @@ -48,5 +49,8 @@ To fetch a list of projects information. $ curl https://tock.18f.gov/api/projects.json -H 'Authorization: Token randomalphanumericstringed854b18ba024327' ``` -* **Notes:** None. - +* **Notes:** + +Note that `grade` may be `null` if no grade information is +available. If it is non-null, it will be a number corresponding to a grade; +the mapping is defined by `GRADE_CHOICES` in `tock/employees/models.py`.