Add expected PATCH and DELETE test cases (#126)

Some of these tests are failing. Additional changes may be needed to models or
the API serializers.
This commit is contained in:
Christopher C. Wells 2020-03-13 07:54:10 -07:00 committed by Christopher Charbonneau Wells
parent 0082f0d838
commit 0fbb4d92fc
1 changed files with 154 additions and 0 deletions

View File

@ -107,6 +107,26 @@ class DiaperChangeAPITestCase(APITestCase):
self.assertEqual(obj.color, data['color'])
self.assertEqual(obj.amount, data['amount'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
entry = response.data
entry['wet'] = False
entry['solid'] = True
response = self.client.patch(endpoint, {
'wet': entry['wet'],
'solid': entry['solid'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class FeedingAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -147,6 +167,28 @@ class FeedingAPITestCase(APITestCase):
obj = models.Feeding.objects.get(pk=response.data['id'])
self.assertEqual(obj.type, data['type'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
entry = response.data
entry['type'] = 'breast milk'
entry['method'] = 'left breast'
entry['amount'] = 0
response = self.client.patch(endpoint, {
'type': entry['type'],
'method': entry['method'],
'amount': entry['amount'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class NoteAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -181,6 +223,26 @@ class NoteAPITestCase(APITestCase):
obj = models.Note.objects.get(pk=response.data['id'])
self.assertEqual(obj.note, data['note'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
entry = response.data
entry['note'] = 'Updated note text.'
response = self.client.patch(endpoint, {
'note': entry['note'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
# The time of entry will always update automatically, so only check the
# new value.
self.assertEqual(response.data['note'], entry['note'])
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class SleepAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -217,6 +279,26 @@ class SleepAPITestCase(APITestCase):
obj = models.Sleep.objects.get(pk=response.data['id'])
self.assertEqual(str(obj.duration), '3:30:00')
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 4)
response = self.client.get(endpoint)
entry = response.data
entry['end'] = '2017-11-18T23:30:00-05:00'
response = self.client.patch(endpoint, {
'end': entry['end'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
# The duration of entry will always update automatically, so only check
# the new value.
self.assertEqual(response.data['end'], entry['end'])
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 4)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class TemperatureAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -251,6 +333,24 @@ class TemperatureAPITestCase(APITestCase):
obj = models.Temperature.objects.get(pk=response.data['id'])
self.assertEqual(str(obj.temperature), data['temperature'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
entry = response.data
entry['temperature'] = 99
response = self.client.patch(endpoint, {
'temperature': entry['temperature'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class TimerAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -288,6 +388,24 @@ class TimerAPITestCase(APITestCase):
obj = models.Timer.objects.get(pk=response.data['id'])
self.assertEqual(obj.name, data['name'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
entry = response.data
entry['name'] = 'New Timer Name'
response = self.client.patch(endpoint, {
'name': entry['name'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 1)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class TummyTimeAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -325,6 +443,24 @@ class TummyTimeAPITestCase(APITestCase):
obj = models.TummyTime.objects.get(pk=response.data['id'])
self.assertEqual(str(obj.duration), '0:05:30')
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
entry = response.data
entry['milestone'] = 'Switched sides!'
response = self.client.patch(endpoint, {
'milestone': entry['milestone'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 3)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
class WeightAPITestCase(APITestCase):
fixtures = ['tests.json']
@ -358,3 +494,21 @@ class WeightAPITestCase(APITestCase):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
obj = models.Weight.objects.get(pk=response.data['id'])
self.assertEqual(str(obj.weight), data['weight'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 2)
response = self.client.get(endpoint)
entry = response.data
entry['weight'] = 8.25
response = self.client.patch(endpoint, {
'weight': entry['weight'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 2)
response = self.client.get(endpoint)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.client.delete(endpoint)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)