diff options
| author | Ran Benita <ran234@gmail.com> | 2019-05-03 13:46:21 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-05-22 20:41:52 +0200 |
| commit | a2c31e12da272acc76f3a3a0157fae9a7f6477ac (patch) | |
| tree | c3a3ad2f35b0b0a37429f9953b3c8df9a5fb70ca /tests/utils_tests | |
| parent | b711eafd2aabdf22e1d529bfb76dd8d3356d7000 (diff) | |
Fixed #30498 -- Fixed proxy class caching in lazy().
lazy() should prepare the proxy class only once (the first time it's
used) not on every call.
Regression in b4e76f30d12bfa8a53cc297c60055c6f4629cc4c.
Diffstat (limited to 'tests/utils_tests')
| -rw-r--r-- | tests/utils_tests/test_functional.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/utils_tests/test_functional.py b/tests/utils_tests/test_functional.py index ab649b7983..af4bd197a6 100644 --- a/tests/utils_tests/test_functional.py +++ b/tests/utils_tests/test_functional.py @@ -1,3 +1,5 @@ +from unittest import mock + from django.test import SimpleTestCase from django.utils.functional import cached_property, lazy @@ -207,3 +209,12 @@ class FunctionalTests(SimpleTestCase): original_object = b'J\xc3\xbcst a str\xc3\xadng' lazy_obj = lazy(lambda: original_object, bytes) self.assertEqual(repr(original_object), repr(lazy_obj())) + + def test_lazy_class_preparation_caching(self): + # lazy() should prepare the proxy class only once i.e. the first time + # it's used. + lazified = lazy(lambda: 0, int) + __proxy__ = lazified().__class__ + with mock.patch.object(__proxy__, '__prepare_class__') as mocked: + lazified() + mocked.assert_not_called() |
