mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #16087 -- Added ResolverMatch instance to test client response.
Thanks mrmachine for the suggestion.
This commit is contained in:
parent
2d425116e2
commit
bf743a4d57
5 changed files with 54 additions and 4 deletions
|
@ -432,6 +432,25 @@ Specifically, a ``Response`` object has the following attributes:
|
|||
loaded from a file. (The name is a string such as
|
||||
``'admin/index.html'``.)
|
||||
|
||||
.. attribute:: resolver_match
|
||||
|
||||
.. versionadded:: 1.8
|
||||
|
||||
An instance of :class:`~django.core.urlresolvers.ResolverMatch` for the
|
||||
response. You can use the
|
||||
:attr:`~django.core.urlresolvers.ResolverMatch.func` attribute, for
|
||||
example, to verify the view that served the response::
|
||||
|
||||
# my_view here is a function based view
|
||||
self.assertEqual(response.resolver_match.func, my_view)
|
||||
|
||||
# class based views need to be compared by name, as the functions
|
||||
# generated by as_view() won't be equal
|
||||
self.assertEqual(response.resolver_match.func.__name__, MyView.as_view().__name__)
|
||||
|
||||
If the given URL is not found, accessing this attribute will raise a
|
||||
:exc:`~django.core.urlresolvers.Resolver404` exception.
|
||||
|
||||
You can also use dictionary syntax on the response object to query the value
|
||||
of any settings in the HTTP headers. For example, you could determine the
|
||||
content type of a response using ``response['Content-Type']``.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue