views:

28

answers:

1

In the Django testing documentation they promise that you can "Test that the correct view is executed for a given URL."

However I didn't find any possibility how to test which view was executed. I would expect that in the Response class but there's nothing about the executed view.

Thanks in advance.

+1  A: 

You can extract the view function name thusly

from django.test.client import Client
c = Client()
response = c.get('/')
from django.core.urlresolvers import resolve
resolve(response.request["PATH_INFO"])[0].func_name
Dave Aaron Smith
wow, this looks a little bit hackish, but yeah, it works. It uses the resolve function to get the matched url pattern. But there's no problem about that, because it's just the opposite way django works when resolving the URL. Thanks!
pcv