Monday, June 10, 2019

Testing - get_object_or_404 returns 200 status code

Hi Django super heroes

I'm making of test cases for my simple Django application. When I test a view with get_object_or_404 shortcut it returns 200 status code.

def my_view(self, request):
  obj_id
= request.POST.get('id')
  obj
= get_object_or_404(MyModel, pk=id)
 
....


# Test case
...data = {'id': 999}
 response
= self.client.post(reverse('view.name'), data=data)
 
self.assertEqual(response.status_code, 404)


I'm getting AssertionError: 200 != 404

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/488aa077-1b11-4404-8d4e-0dad1885707b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment