From c51e755c0fcd6ed94b207de08fe04df03df84ade Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sun, 26 Jan 2020 14:30:00 -0800 Subject: [PATCH] Add Diaper Change "amount" field data to API --- api/serializers.py | 2 +- api/tests.py | 9 +++++-- api/views.py | 2 +- babybuddy/fixtures/tests.json | 45 +++++++++++++++++++++++------------ 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index 7af26346..b09f1f9a 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -36,7 +36,7 @@ class ChildSerializer(serializers.HyperlinkedModelSerializer): class DiaperChangeSerializer(CoreModelSerializer): class Meta: model = models.DiaperChange - fields = ('id', 'child', 'time', 'wet', 'solid', 'color') + fields = ('id', 'child', 'time', 'wet', 'solid', 'color', 'amount') class FeedingSerializer(CoreModelSerializer): diff --git a/api/tests.py b/api/tests.py index 63a944d0..05f78fef 100644 --- a/api/tests.py +++ b/api/tests.py @@ -61,7 +61,8 @@ class DiaperChangeAPITestCase(APITestCase): 'time': '2017-11-18T14:00:00-05:00', 'wet': True, 'solid': False, - 'color': '' + 'color': '', + 'amount': 2.25 }) def test_options(self): @@ -75,12 +76,16 @@ class DiaperChangeAPITestCase(APITestCase): 'time': '2017-11-18T12:00:00-05:00', 'wet': True, 'solid': True, - 'color': 'brown' + 'color': 'brown', + 'amount': 1.25 } response = self.client.post(self.endpoint, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) obj = models.DiaperChange.objects.get(pk=response.data['id']) + self.assertTrue(obj.wet) + self.assertTrue(obj.solid) self.assertEqual(obj.color, data['color']) + self.assertEqual(obj.amount, data['amount']) @override_settings(TIME_ZONE='US/Eastern') diff --git a/api/views.py b/api/views.py index 05d18f81..c91f11e6 100644 --- a/api/views.py +++ b/api/views.py @@ -16,7 +16,7 @@ class ChildViewSet(viewsets.ModelViewSet): class DiaperChangeViewSet(viewsets.ModelViewSet): queryset = models.DiaperChange.objects.all() serializer_class = serializers.DiaperChangeSerializer - filterset_fields = ('child', 'wet', 'solid', 'color') + filterset_fields = ('child', 'wet', 'solid', 'color', 'amount') class FeedingViewSet(viewsets.ModelViewSet): diff --git a/babybuddy/fixtures/tests.json b/babybuddy/fixtures/tests.json index 7be74906..ebe4978f 100644 --- a/babybuddy/fixtures/tests.json +++ b/babybuddy/fixtures/tests.json @@ -20,7 +20,8 @@ "time": "2017-11-18T16:00:00Z", "wet": false, "solid": true, - "color": "green" + "color": "green", + "amount": null } }, { @@ -32,7 +33,8 @@ "time": "2017-11-18T19:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 2.25 } }, { @@ -44,7 +46,8 @@ "time": "2017-11-17T13:00:00Z", "wet": false, "solid": true, - "color": "green" + "color": "green", + "amount": 1.3 } }, { @@ -56,7 +59,8 @@ "time": "2017-11-17T16:00:00Z", "wet": false, "solid": true, - "color": "green" + "color": "green", + "amount": null } }, { @@ -68,7 +72,8 @@ "time": "2017-11-16T15:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": null } }, { @@ -80,7 +85,8 @@ "time": "2017-11-16T18:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 5.4 } }, { @@ -92,7 +98,8 @@ "time": "2017-11-15T15:00:00Z", "wet": false, "solid": true, - "color": "brown" + "color": "brown", + "amount": 0.25 } }, { @@ -104,7 +111,8 @@ "time": "2017-11-15T13:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 1.67 } }, { @@ -116,7 +124,8 @@ "time": "2017-11-15T16:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 1.0 } }, { @@ -128,7 +137,8 @@ "time": "2017-11-15T21:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": null } }, { @@ -140,7 +150,8 @@ "time": "2017-11-14T15:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": null } }, { @@ -152,7 +163,8 @@ "time": "2017-11-13T14:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 2.6 } }, { @@ -164,7 +176,8 @@ "time": "2017-11-13T18:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": null } }, { @@ -176,7 +189,8 @@ "time": "2017-11-12T15:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": null } }, { @@ -188,7 +202,8 @@ "time": "2017-11-11T15:00:00Z", "wet": true, "solid": false, - "color": "" + "color": "", + "amount": 0.75 } }, {