#16087: Add ResolverMatch object to test client responses.
-------------------------------------------------+-------------------------
Reporter: mrmachine | Owner: nobody
Type: Bug | Status: new
Milestone: 1.4 | Component: Testing
Version: 1.3 | framework
Keywords: test client view url resolve | Severity: Normal
reverse | Triage Stage:
Has patch: 0 | Unreviewed
| Easy pickings: 0
-------------------------------------------------+-------------------------
The docs say that you can use the test client to "Test that the correct
view is executed for a given URL." but this doesn't seem to be possible
without requiring users to perform their own `resolve()`, when Django has
already done it and discarded the resulting ResolverMatch object.
{{{
response = client.post(some_url, some_data, follow=True)
self.assertEqual(resolve(response.request["PATH_INFO"]).url_name,
'some_url')
}}}
In my case, `some_url` is a view that processes some form data and
redirects according to the data, and I'm testing that with `some_data` as
input, the request is redirected to `some_url`. With different data, it
might redirect to a different URL.
Initially I tried to use `assertRedirects` and `response.redirect_chain`
to test this, but ran into trouble because I had to try and construct a
URL string that would match the redirect_chain from the view function or
URL name, without knowing the exact URL arguments that were used to
generate the redirect URL (auto field and a hash that is unique to the
newly created object).
I'd like to see Django add the ResolverMatch object directly to all test
client responses, so that users can easily test that a specific view
function or named URL was executed.
I guess this would be implemented similarly to the way the context and
templates are added.
I think this is either a feature bug or a documentation bug. If this is
not a valid feature of the test client, the docs should be clarified. I
read "correct view is executed" to mean "correct view function (or class
based view) is executed".
--
Ticket URL: <https://code.djangoproject.com/ticket/16087>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.