diff options
| author | Greg Chapple <gregchapple1@gmail.com> | 2014-06-06 15:49:02 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-06-13 08:50:43 -0400 |
| commit | bf743a4d571bbb7da276bc21c61f6ada5d26942c (patch) | |
| tree | cbd84d33039b6058e5b4ebefbdf1311be8461e93 /docs | |
| parent | 2d425116e2f26ab546c380784df1de79562009a7 (diff) | |
Fixed #16087 -- Added ResolverMatch instance to test client response.
Thanks mrmachine for the suggestion.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.8.txt | 7 | ||||
| -rw-r--r-- | docs/topics/testing/tools.txt | 19 |
2 files changed, 24 insertions, 2 deletions
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 86f9a122c2..b4f385529d 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -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 ^^^^^^^^^^ diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 1d55b2e3dc..e6433b5235 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -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']``. |
