mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #16087 -- Added ResolverMatch instance to test client response.
Thanks mrmachine for the suggestion.
This commit is contained in:
@@ -214,8 +214,11 @@ Tests
|
||||
* The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
|
||||
allows you to test that two JSON fragments are not equal.
|
||||
|
||||
* Added the ability to preserve the test database by adding the :djadminopt:`--keepdb`
|
||||
flag.
|
||||
* Added the ability to preserve the test database by adding the
|
||||
:djadminopt:`--keepdb` flag.
|
||||
|
||||
* Added the :attr:`~django.test.Response.resolver_match` attribute to test
|
||||
client responses.
|
||||
|
||||
Validators
|
||||
^^^^^^^^^^
|
||||
|
||||
@@ -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']``.
|
||||
|
||||
Reference in New Issue
Block a user