diff options
| author | Claude Paroz <claude@2xlibre.net> | 2020-03-11 09:47:43 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-03-11 13:16:44 +0100 |
| commit | e663f695fb282053b31f69ee2dcbc67ddacb9104 (patch) | |
| tree | 059aefa465734a3d0a781cab682d80511cb6ae92 /tests/utils_tests | |
| parent | 5cc2c63f902412cdd9a8ebbabbd953aa8e2180c0 (diff) | |
Fixed #31359 -- Deprecated get_random_string() calls without an explicit length.
Diffstat (limited to 'tests/utils_tests')
| -rw-r--r-- | tests/utils_tests/test_crypto.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/utils_tests/test_crypto.py b/tests/utils_tests/test_crypto.py index 9dbfd9fe57..4469d6e985 100644 --- a/tests/utils_tests/test_crypto.py +++ b/tests/utils_tests/test_crypto.py @@ -1,10 +1,12 @@ import hashlib import unittest -from django.test import SimpleTestCase +from django.test import SimpleTestCase, ignore_warnings from django.utils.crypto import ( - InvalidAlgorithm, constant_time_compare, pbkdf2, salted_hmac, + InvalidAlgorithm, constant_time_compare, get_random_string, pbkdf2, + salted_hmac, ) +from django.utils.deprecation import RemovedInDjango40Warning class TestUtilsCryptoMisc(SimpleTestCase): @@ -183,3 +185,14 @@ class TestUtilsCryptoPBKDF2(unittest.TestCase): def test_default_hmac_alg(self): kwargs = {'password': b'password', 'salt': b'salt', 'iterations': 1, 'dklen': 20} self.assertEqual(pbkdf2(**kwargs), hashlib.pbkdf2_hmac(hash_name=hashlib.sha256().name, **kwargs)) + + +class DeprecationTests(SimpleTestCase): + @ignore_warnings(category=RemovedInDjango40Warning) + def test_get_random_string(self): + self.assertEqual(len(get_random_string()), 12) + + def test_get_random_string_warning(self): + msg = 'Not providing a length argument is deprecated.' + with self.assertRaisesMessage(RemovedInDjango40Warning, msg): + get_random_string() |
