I am trying to create a unit test for a view that will show a random object on a detail page.
views.py
def random_stuf(request):
rand_stuf = Mod.objects.order_by('?').first().pk
return HttpResponseRedirect(reverse('app:detail', args=(rand_stuf,)))
urls.py
path('detail/random/', views.random_stuf, name='random'),
tests.py
def test_random(self):
response = self.client.get(reverse('app:random'))
self.assertRedirects(response, '/detail/1/', status_code=302, target_status_code=200)
the argument of the expected url will be different every time. Is there a way i can test this?
Aucun commentaire:
Enregistrer un commentaire