Ticket #25187: 25187-positional-arg-test.diff

File 25187-positional-arg-test.diff, 1.7 KB (added by Tim Graham, 8 years ago)
  • tests/auth_tests/test_auth_backends_deprecation.py

    diff --git a/tests/auth_tests/test_auth_backends_deprecation.py b/tests/auth_tests/test_auth_backends_deprecation.py
    index 765d87b..398d34c 100644
    a b class NoRequestBackend:  
    1010        pass
    1111
    1212
     13class RequestNotPositionArgBackend:
     14    def authenticate(self, username, password, request):
     15        pass
     16
     17
    1318class AcceptsRequestBackendTest(SimpleTestCase):
    1419    """
    1520    A deprecation warning is shown for backends that have an authenticate()
    1621    method without a request parameter.
    1722    """
    1823    no_request_backend = '%s.NoRequestBackend' % __name__
     24    request_not_positional_backend = '%s.RequestNotPositionArgBackend' % __name__
    1925
    2026    @override_settings(AUTHENTICATION_BACKENDS=[no_request_backend])
    2127    def test_no_request_deprecation_warning(self):
    class AcceptsRequestBackendTest(SimpleTestCase):  
    2834            "Update %s.authenticate() to accept a positional `request` "
    2935            "argument." % self.no_request_backend
    3036        )
     37
     38    @override_settings(AUTHENTICATION_BACKENDS=[request_not_positional_backend])
     39    def test_request_keyword_arg_deprecation_warning(self):
     40        with warnings.catch_warnings(record=True) as warns:
     41            warnings.simplefilter('always')
     42            authenticate(username='test', password='test', request=object())
     43        self.assertEqual(len(warns), 1)
     44        self.assertEqual(
     45            str(warns[0].message),
     46            "In %s.authenticate(), move the `request` keyword arugment to the "
     47            "first positional argument." % self.request_not_positional_backend
     48        )
Back to Top