This is how I usually do redirect tests:
self.assertEqual(response.status_code, 302)
self.assertRedirects(
response,
'http://testserver' + reverse('pizza:deleted')
)
I recommend using named URLs, that way your message_id would be similar to
this:
reverse('pizza:delete', args=[pizza.id])
Here is the complete app's tests if you want to take a look
https://github.com/kelvinwong-ca/django-select-multiple-field/blob/master/test_projects/django14/pizzagigi/tests.py
K
On Tuesday, June 17, 2014 7:26:27 PM UTC-7, Antonio Alaniz wrote:
>
> I'm testing a redirect that would include the primary key. Can anyone tell
> me how I can test the redirect URL if it involves the primary key? Will the
> following work?:
>
> self.assertRedirects(response, 'message/(?P<message_id>\d+)/', 200)
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/f0ddc82c-67f8-4b2d-aef1-6fcde2eb3c72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.