mirror of https://github.com/snachodog/mybuddy.git
Add Temperature data to API.
This commit is contained in:
parent
88dfe809d3
commit
243b9ef1c1
|
@ -58,6 +58,12 @@ class SleepSerializer(CoreModelSerializer):
|
|||
fields = ('id', 'child', 'start', 'end', 'duration')
|
||||
|
||||
|
||||
class TemperatureSerializer(CoreModelSerializer):
|
||||
class Meta:
|
||||
model = models.Temperature
|
||||
fields = ('id', 'child', 'temperature', 'time')
|
||||
|
||||
|
||||
class TimerSerializer(CoreModelSerializer):
|
||||
user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
|
||||
|
||||
|
|
35
api/tests.py
35
api/tests.py
|
@ -195,6 +195,41 @@ class SleepAPITestCase(APITestCase):
|
|||
self.assertEqual(str(obj.duration), '3:30:00')
|
||||
|
||||
|
||||
@override_settings(TIME_ZONE='US/Eastern')
|
||||
class TemperatureAPITestCase(APITestCase):
|
||||
fixtures = ['tests.json']
|
||||
endpoint = reverse('api:temperature-list')
|
||||
|
||||
def setUp(self):
|
||||
self.client.login(username='admin', password='admin')
|
||||
|
||||
def test_get(self):
|
||||
response = self.client.get(self.endpoint)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['results'][0], {
|
||||
'id': 1,
|
||||
'child': 1,
|
||||
'temperature': 98.6,
|
||||
'time': '2017-11-17T12:52:00-05:00'
|
||||
})
|
||||
|
||||
def test_options(self):
|
||||
response = self.client.options(self.endpoint)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['name'], 'Temperature List')
|
||||
|
||||
def test_post(self):
|
||||
data = {
|
||||
'child': 1,
|
||||
'temperature': '100.1',
|
||||
'time': '2017-11-20T22:52:00-05:00'
|
||||
}
|
||||
response = self.client.post(self.endpoint, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
obj = models.Temperature.objects.get(pk=response.data['id'])
|
||||
self.assertEqual(str(obj.temperature), data['temperature'])
|
||||
|
||||
|
||||
@override_settings(TIME_ZONE='US/Eastern')
|
||||
class TimerAPITestCase(APITestCase):
|
||||
fixtures = ['tests.json']
|
||||
|
|
|
@ -10,6 +10,7 @@ router.register(r'changes', views.DiaperChangeViewSet)
|
|||
router.register(r'feedings', views.FeedingViewSet)
|
||||
router.register(r'notes', views.NoteViewSet)
|
||||
router.register(r'sleep', views.SleepViewSet)
|
||||
router.register(r'temperature', views.TemperatureViewSet)
|
||||
router.register(r'timers', views.TimerViewSet)
|
||||
router.register(r'tummy-times', views.TummyTimeViewSet)
|
||||
router.register(r'weight', views.WeightViewSet)
|
||||
|
|
|
@ -37,6 +37,12 @@ class SleepViewSet(viewsets.ModelViewSet):
|
|||
filterset_fields = ('child',)
|
||||
|
||||
|
||||
class TemperatureViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Temperature.objects.all()
|
||||
serializer_class = serializers.TemperatureSerializer
|
||||
filterset_fields = ('child',)
|
||||
|
||||
|
||||
class TimerViewSet(viewsets.ModelViewSet):
|
||||
queryset = models.Timer.objects.all()
|
||||
serializer_class = serializers.TimerSerializer
|
||||
|
|
|
@ -286,6 +286,16 @@
|
|||
"end": "2017-11-19T04:00:00Z",
|
||||
"duration": "04:00:00"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "core.temperature",
|
||||
"pk": 1,
|
||||
"fields":
|
||||
{
|
||||
"child": 1,
|
||||
"temperature": 98.6,
|
||||
"time": "2017-11-17T17:52:00Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "core.timer",
|
||||
|
|
Loading…
Reference in New Issue