I'm very new to Django and testing....
I'm testing my app and every time I do threads_page = self.client.get('/threads/1/') it returns a 404 status instead of 200 (that url works, the 1 is the subject id).
I found a thread with the same problem and there was a response with the issue (Django test client get returns 404 however works in shell) but I still don't know how to solve it. The problem is that in my views I have a get_object_or_404 with an argument but I don't know how to pass the argument in the test:
views.py
def threads(request, subject_id):
subject = get_object_or_404(Subject, pk=subject_id)
return render(request, 'forum/threads.html', {'subject': subject})
This is my test right now
def test_check_threads_content_is_correct(self):
threads_page = self.client.get('/threads/1/')
self.assertEqual(threads_page.status_code, 200)
Thank you!
Aucun commentaire:
Enregistrer un commentaire