Skip to content

Commit

Permalink
Merge pull request #758 from 18F/include-grade-in-timecards-json
Browse files Browse the repository at this point in the history
Include 'grade' in timecards.json response.
  • Loading branch information
rogeruiz authored Mar 15, 2018
2 parents 5685b90 + 4015bf6 commit bafc00b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api-docs/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ To fetch a list of projects information.
"billable": true,
"start_date": null,
"end_date": null,
"grade": 16,
"active": true
},...
Expand All @@ -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`.
14 changes: 14 additions & 0 deletions tock/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
3 changes: 3 additions & 0 deletions tock/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class TimecardSerializer(serializers.Serializer):
project_organization = serializers.CharField(
source='project.organization_name'
)
grade = serializers.IntegerField(
source='grade.grade')

# API Views

Expand Down Expand Up @@ -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'
)
Expand Down
10 changes: 10 additions & 0 deletions tock/hours/fixtures/timecards.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"model": "employees.EmployeeGrade",
"fields": {
"employee": 1,
"grade": 4,
"g_start_date": "2015-05-28"
},
"pk": 1
},
{
"model": "hours.reportingperiod",
"fields": {
Expand All @@ -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"
},
Expand Down

0 comments on commit bafc00b

Please sign in to comment.