Add PATCH and DELETE support (#126)

This commit is contained in:
Christopher C. Wells 2020-03-13 06:29:14 -07:00 committed by Christopher Charbonneau Wells
parent a17ae0754e
commit 0082f0d838
2 changed files with 24 additions and 2 deletions

View File

@ -9,6 +9,6 @@ class BabyBuddyDjangoModelPermissions(DjangoModelPermissions):
'HEAD': [],
'POST': ['%(app_label)s.add_%(model_name)s'],
# 'PUT': ['%(app_label)s.change_%(model_name)s'],
# 'PATCH': ['%(app_label)s.change_%(model_name)s'],
# 'DELETE': ['%(app_label)s.delete_%(model_name)s'],
'PATCH': ['%(app_label)s.change_%(model_name)s'],
'DELETE': ['%(app_label)s.delete_%(model_name)s'],
}

View File

@ -42,6 +42,28 @@ class ChildAPITestCase(APITestCase):
obj = models.Child.objects.get(pk=response.data['id'])
self.assertEqual(obj.first_name, data['first_name'])
def test_patch(self):
endpoint = '{}{}/'.format(self.endpoint, 'fake-child')
response = self.client.get(endpoint)
entry = response.data
entry['first_name'] = 'New'
entry['last_name'] = 'Name'
response = self.client.patch(endpoint, {
'first_name': entry['first_name'],
'last_name': entry['last_name'],
})
self.assertEqual(response.status_code, status.HTTP_200_OK)
# The slug we be updated by the name change.
entry['slug'] = 'new-name'
self.assertEqual(response.data, entry)
def test_delete(self):
endpoint = '{}{}/'.format(self.endpoint, 'fake-child')
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 DiaperChangeAPITestCase(APITestCase):
fixtures = ['tests.json']