Testing - get_object_or_404 returns 200 status code

11 views
Skip to first unread message

Cristhiam Gabriel FernƔndez

unread,
Jun 10, 2019, 4:16:45ā€ÆPM6/10/19
to Django users
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

Chetan Ganji

unread,
Jun 10, 2019, 4:29:24ā€ÆPM6/10/19
to django...@googlegroups.com
Whats your question?
I failed to understand that šŸ˜…

--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Cristhiam Gabriel FernƔndez

unread,
Jun 10, 2019, 4:32:16ā€ÆPM6/10/19
to Django users
Hi RyuCoder

Should not get_object_or_404 shortcut retry 404 status code?


El lunes, 10 de junio de 2019, 15:29:24 (UTC-5), RyuCoder escribiĆ³:
Whats your question?
I failed to understand that šŸ˜…

On Tue, Jun 11, 2019, 1:45 AM Cristhiam Gabriel FernƔndez <cristh...@gmail.com> wrote:
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages