1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Adjusted CBV resolver_match example in testing tools docs.

The view_class is available on the view callback, allowing that to be
checked, rather than the __name__.
This commit is contained in:
Carlton Gibson
2022-01-26 20:58:22 +01:00
committed by GitHub
parent f38c3cbadc
commit d15a10afb5
2 changed files with 13 additions and 4 deletions

View File

@@ -32,6 +32,7 @@ from django.test import (
)
from django.urls import reverse_lazy
from django.utils.decorators import async_only_middleware
from django.views.generic import RedirectView
from .views import TwoArgException, get_view, post_view, trace_view
@@ -213,6 +214,14 @@ class ClientTest(TestCase):
response = self.client.get('/get_view/')
self.assertEqual(response.resolver_match.url_name, 'get_view')
def test_response_resolver_match_class_based_view(self):
"""
The response ResolverMatch instance can be used to access the CBV view
class.
"""
response = self.client.get('/accounts/')
self.assertIs(response.resolver_match.func.view_class, RedirectView)
@modify_settings(MIDDLEWARE={'prepend': 'test_client.tests.middleware_urlconf'})
def test_response_resolver_match_middleware_urlconf(self):
response = self.client.get('/middleware_urlconf_view/')