Reputation: 87
So basically when i try to test my patch view it doesn't patch at all as i get a 400 error. However, when i call the same patch view outside the APITestCase, while running the test server, it does work.
At APITestCase:
def test_patch_update_data(self):
self.client.force_authenticate(user=self.user)
self.assertEqual(self.user.first_name, 'Robert')
patch_data = {'first_name': 'test999'}
response = self.client.patch('http://testserver/api/patch/{0}/'.format(
self.user.id), patch_data, format='json')
self.assertEqual(response.status_code, 200) # ERROR:GIVES 400!
self.assertEqual(self.user.first_name, 'test999')
At views.py
class UsuariosUpdatePatchAPIView(UpdateAPIView):
queryset = Usuarios.objects.all()
serializer_class = UsuariosUpdateSerializer
permission_classes = [IsAuthenticated, IsSelfUser]
self.assertEqual(response.status_code, 200)
AssertionError: 400 != 200
Thanks in advance! :)
Upvotes: 1
Views: 690
Reputation: 87
As stated in the comments, response.data gives very useful information. It turned out to be that the field fist_name only accepted letters! So the solution was changing test999 to something without numbers!
Upvotes: 2