mirror of https://github.com/snachodog/mybuddy.git
Add PATCH and DELETE support (#126)
This commit is contained in:
parent
a17ae0754e
commit
0082f0d838
|
@ -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'],
|
||||
}
|
||||
|
|
22
api/tests.py
22
api/tests.py
|
@ -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']
|
||||
|
|
Loading…
Reference in New Issue