diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-05-15 17:28:00 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-06-24 10:45:13 +0200 |
| commit | 78963495d0caadb77eb97ccf319ef0ba3b204fb5 (patch) | |
| tree | 52162432f13b92b85b6188a6415887cfc06c5701 /tests | |
| parent | 742ea51413b3aab07c6afbfd1d52c1908ffcb510 (diff) | |
Refs #17209 -- Added LoginView and LogoutView class-based views
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_views.py | 10 | ||||
| -rw-r--r-- | tests/auth_tests/urls.py | 17 | ||||
| -rw-r--r-- | tests/generic_views/urls.py | 2 | ||||
| -rw-r--r-- | tests/resolve_url/tests.py | 14 | ||||
| -rw-r--r-- | tests/resolve_url/urls.py | 8 | ||||
| -rw-r--r-- | tests/test_client/urls.py | 4 | ||||
| -rw-r--r-- | tests/view_tests/generic_urls.py | 4 |
7 files changed, 31 insertions, 28 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index 5b4b877c47..bd01c67d70 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -15,7 +15,7 @@ from django.contrib.auth.forms import ( AuthenticationForm, PasswordChangeForm, SetPasswordForm, ) from django.contrib.auth.models import User -from django.contrib.auth.views import login as login_view, redirect_to_login +from django.contrib.auth.views import LoginView, redirect_to_login from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sites.requests import RequestSite from django.core import mail @@ -553,10 +553,10 @@ class LoginTest(AuthViewsTestCase): # Do a GET to establish a CSRF token # TestClient isn't used here as we're testing middleware, essentially. req = HttpRequest() - CsrfViewMiddleware().process_view(req, login_view, (), {}) + CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {}) # get_token() triggers CSRF token inclusion in the response get_token(req) - resp = login_view(req) + resp = LoginView.as_view()(req) resp2 = CsrfViewMiddleware().process_response(req, resp) csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None) token1 = csrf_cookie.coded_value @@ -569,10 +569,10 @@ class LoginTest(AuthViewsTestCase): # Use POST request to log in SessionMiddleware().process_request(req) - CsrfViewMiddleware().process_view(req, login_view, (), {}) + CsrfViewMiddleware().process_view(req, LoginView.as_view(), (), {}) req.META["SERVER_NAME"] = "testserver" # Required to have redirect work in login view req.META["SERVER_PORT"] = 80 - resp = login_view(req) + resp = LoginView.as_view()(req) resp2 = CsrfViewMiddleware().process_response(req, resp) csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, None) token2 = csrf_cookie.coded_value diff --git a/tests/auth_tests/urls.py b/tests/auth_tests/urls.py index 2b70c59a51..c6dd632e0a 100644 --- a/tests/auth_tests/urls.py +++ b/tests/auth_tests/urls.py @@ -61,14 +61,11 @@ def userpage(request): pass -def custom_request_auth_login(request): - return views.login(request, authentication_form=CustomRequestAuthenticationForm) - # special urls for auth test cases urlpatterns = auth_urlpatterns + [ - url(r'^logout/custom_query/$', views.logout, dict(redirect_field_name='follow')), - url(r'^logout/next_page/$', views.logout, dict(next_page='/somewhere/')), - url(r'^logout/next_page/named/$', views.logout, dict(next_page='password_reset')), + url(r'^logout/custom_query/$', views.LogoutView.as_view(redirect_field_name='follow')), + url(r'^logout/next_page/$', views.LogoutView.as_view(next_page='/somewhere/')), + url(r'^logout/next_page/named/$', views.LogoutView.as_view(next_page='password_reset')), url(r'^remote_user/$', remote_user_auth_view), url(r'^password_reset_from_email/$', views.password_reset, dict(from_email='staffmember@example.com')), url(r'^password_reset_extra_email_context/$', views.password_reset, @@ -94,10 +91,12 @@ urlpatterns = auth_urlpatterns + [ url(r'^auth_processor_perms/$', auth_processor_perms), url(r'^auth_processor_perm_in_perms/$', auth_processor_perm_in_perms), url(r'^auth_processor_messages/$', auth_processor_messages), - url(r'^custom_request_auth_login/$', custom_request_auth_login), + url(r'^custom_request_auth_login/$', + views.LoginView.as_view(authentication_form=CustomRequestAuthenticationForm)), url(r'^userpage/(.+)/$', userpage, name="userpage"), - url(r'^login/redirect_authenticated_user_default/$', views.login), - url(r'^login/redirect_authenticated_user/$', views.login, dict(redirect_authenticated_user=True)), + url(r'^login/redirect_authenticated_user_default/$', views.LoginView.as_view()), + url(r'^login/redirect_authenticated_user/$', + views.LoginView.as_view(redirect_authenticated_user=True)), # This line is only required to render the password reset with is_admin=True url(r'^admin/', admin.site.urls), diff --git a/tests/generic_views/urls.py b/tests/generic_views/urls.py index e95f9c01c7..288383e032 100644 --- a/tests/generic_views/urls.py +++ b/tests/generic_views/urls.py @@ -292,5 +292,5 @@ urlpatterns = [ views.BookSigningDetail.as_view()), # Useful for testing redirects - url(r'^accounts/login/$', auth_views.login) + url(r'^accounts/login/$', auth_views.LoginView.as_view()) ] diff --git a/tests/resolve_url/tests.py b/tests/resolve_url/tests.py index b909f68abe..ecccfa6c9e 100644 --- a/tests/resolve_url/tests.py +++ b/tests/resolve_url/tests.py @@ -1,12 +1,12 @@ from __future__ import unicode_literals -from django.contrib.auth.views import logout from django.shortcuts import resolve_url from django.test import SimpleTestCase, override_settings from django.urls import NoReverseMatch, reverse_lazy from django.utils import six from .models import UnimportantThing +from .urls import some_view @override_settings(ROOT_URLCONF='resolve_url.urls') @@ -53,25 +53,25 @@ class ResolveUrlTests(SimpleTestCase): Tests that passing a view function to ``resolve_url`` will result in the URL path mapping to that view name. """ - resolved_url = resolve_url(logout) - self.assertEqual('/accounts/logout/', resolved_url) + resolved_url = resolve_url(some_view) + self.assertEqual('/some-url/', resolved_url) def test_lazy_reverse(self): """ Tests that passing the result of reverse_lazy is resolved to a real URL string. """ - resolved_url = resolve_url(reverse_lazy('logout')) + resolved_url = resolve_url(reverse_lazy('some-view')) self.assertIsInstance(resolved_url, six.text_type) - self.assertEqual('/accounts/logout/', resolved_url) + self.assertEqual('/some-url/', resolved_url) def test_valid_view_name(self): """ Tests that passing a view name to ``resolve_url`` will result in the URL path mapping to that view. """ - resolved_url = resolve_url('logout') - self.assertEqual('/accounts/logout/', resolved_url) + resolved_url = resolve_url('some-view') + self.assertEqual('/some-url/', resolved_url) def test_domain(self): """ diff --git a/tests/resolve_url/urls.py b/tests/resolve_url/urls.py index e78b833927..43429d6f2a 100644 --- a/tests/resolve_url/urls.py +++ b/tests/resolve_url/urls.py @@ -1,6 +1,10 @@ from django.conf.urls import url -from django.contrib.auth import views + + +def some_view(request): + pass + urlpatterns = [ - url(r'^accounts/logout/$', views.logout, name='logout'), + url(r'^some-url/$', some_view, name='some-view'), ] diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py index a7b0ed310d..ca8d5a8fc2 100644 --- a/tests/test_client/urls.py +++ b/tests/test_client/urls.py @@ -36,6 +36,6 @@ urlpatterns = [ url(r'^accounts/$', RedirectView.as_view(url='login/')), url(r'^accounts/no_trailing_slash$', RedirectView.as_view(url='login/')), - url(r'^accounts/login/$', auth_views.login, {'template_name': 'login.html'}), - url(r'^accounts/logout/$', auth_views.logout), + url(r'^accounts/login/$', auth_views.LoginView.as_view(template_name='login.html')), + url(r'^accounts/logout/$', auth_views.LogoutView.as_view()), ] diff --git a/tests/view_tests/generic_urls.py b/tests/view_tests/generic_urls.py index ee1c7d123b..4ca2c8927a 100644 --- a/tests/view_tests/generic_urls.py +++ b/tests/view_tests/generic_urls.py @@ -28,8 +28,8 @@ numeric_days_info_dict = dict(date_based_info_dict, day_format='%d') date_based_datefield_info_dict = dict(date_based_info_dict, queryset=DateArticle.objects.all()) urlpatterns = [ - url(r'^accounts/login/$', auth_views.login, {'template_name': 'login.html'}), - url(r'^accounts/logout/$', auth_views.logout), + url(r'^accounts/login/$', auth_views.LoginView.as_view(template_name='login.html')), + url(r'^accounts/logout/$', auth_views.LogoutView.as_view()), # Special URLs for particular regression cases. url('^中文/target/$', views.index_page), |
