diff options
| author | Mateo Radman <48420316+mateoradman@users.noreply.github.com> | 2021-06-20 20:16:33 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-06-25 06:55:47 +0200 |
| commit | 8a7ac78b706797a03d26b88eddb9d1067ed35b66 (patch) | |
| tree | dbba445b3fe90377ffae9e4c605beb0ecb3ae93a /tests | |
| parent | 64839512a6ed04a29e49e246acf8337b1be2cb8e (diff) | |
Refs #32508 -- Raised ImproperlyConfigured/TypeError instead of using "assert" in various code.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_views.py | 6 | ||||
| -rw-r--r-- | tests/auth_tests/urls.py | 1 | ||||
| -rw-r--r-- | tests/dispatch/tests.py | 2 | ||||
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 16 |
4 files changed, 23 insertions, 2 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index 0ec3a134c2..9ae7dab252 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -23,6 +23,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sites.requests import RequestSite from django.core import mail +from django.core.exceptions import ImproperlyConfigured from django.db import connection from django.http import HttpRequest, HttpResponse from django.middleware.csrf import CsrfViewMiddleware, get_token @@ -386,6 +387,11 @@ class PasswordResetTest(AuthViewsTestCase): response = Client().get('/reset/%s/set-password/' % uuidb64) self.assertContains(response, 'The password reset link was invalid') + def test_missing_kwargs(self): + msg = "The URL path must contain 'uidb64' and 'token' parameters." + with self.assertRaisesMessage(ImproperlyConfigured, msg): + self.client.get('/reset/missing_parameters/') + @override_settings(AUTH_USER_MODEL='auth_tests.CustomUser') class CustomUserPasswordResetTest(AuthViewsTestCase): diff --git a/tests/auth_tests/urls.py b/tests/auth_tests/urls.py index 044f0da037..70857e866a 100644 --- a/tests/auth_tests/urls.py +++ b/tests/auth_tests/urls.py @@ -133,6 +133,7 @@ urlpatterns = auth_urlpatterns + [ post_reset_login_backend='django.contrib.auth.backends.AllowAllUsersModelBackend', ), ), + path('reset/missing_parameters/', views.PasswordResetConfirmView.as_view()), path('password_change/custom/', views.PasswordChangeView.as_view(success_url='/custom/')), path('password_change/custom/named/', diff --git a/tests/dispatch/tests.py b/tests/dispatch/tests.py index 30a9354bba..05b7bdb02f 100644 --- a/tests/dispatch/tests.py +++ b/tests/dispatch/tests.py @@ -58,7 +58,7 @@ class DispatcherTests(SimpleTestCase): @override_settings(DEBUG=True) def test_cannot_connect_non_callable(self): msg = 'Signal receivers must be callable.' - with self.assertRaisesMessage(AssertionError, msg): + with self.assertRaisesMessage(TypeError, msg): a_signal.connect(object()) self.assertTestIsClean(a_signal) diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index c8cc4aeb1e..aa3cf4b839 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -12,7 +12,7 @@ from unittest import mock from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile from django.db import DatabaseError, connection -from django.http import Http404 +from django.http import Http404, HttpRequest, HttpResponse from django.shortcuts import render from django.template import TemplateDoesNotExist from django.test import RequestFactory, SimpleTestCase, override_settings @@ -1635,3 +1635,17 @@ class DecoratorsTests(SimpleTestCase): @sensitive_post_parameters def test_func(request): return index_page(request) + + def test_sensitive_post_parameters_http_request(self): + class MyClass: + @sensitive_post_parameters() + def a_view(self, request): + return HttpResponse() + + msg = ( + "sensitive_post_parameters didn't receive an HttpRequest object. " + "If you are decorating a classmethod, make sure to use " + "@method_decorator." + ) + with self.assertRaisesMessage(TypeError, msg): + MyClass().a_view(HttpRequest()) |
