diff options
author | Theo Alexiou <theofilosalexiou@gmail.com> | 2022-02-13 17:27:12 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-16 10:51:15 +0100 |
commit | 97d7990abde3fe4b525ae83958fd0b52d6a1d13f (patch) | |
tree | 56e0ba7eae9e551bcccfbd87995a8020836ab228 /tests/utils_tests | |
parent | 1d071ec1aa8fa414bb96b41f7be8a1bd01079815 (diff) | |
download | django-97d7990abde3fe4b525ae83958fd0b52d6a1d13f.tar.gz |
Fixed #28358 -- Prevented LazyObject from mimicking nonexistent attributes.
Thanks Sergey Fedoseev for the initial patch.
Diffstat (limited to 'tests/utils_tests')
-rw-r--r-- | tests/utils_tests/test_lazyobject.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/utils_tests/test_lazyobject.py b/tests/utils_tests/test_lazyobject.py index 0ff15469d4..161c9dbcec 100644 --- a/tests/utils_tests/test_lazyobject.py +++ b/tests/utils_tests/test_lazyobject.py @@ -32,6 +32,28 @@ class LazyObjectTestCase(TestCase): return AdHocLazyObject() + def test_getattribute(self): + """ + Proxy methods don't exist on wrapped objects unless they're set. + """ + attrs = [ + "__getitem__", + "__setitem__", + "__delitem__", + "__iter__", + "__len__", + "__contains__", + ] + foo = Foo() + obj = self.lazy_wrap(foo) + for attr in attrs: + with self.subTest(attr): + self.assertFalse(hasattr(obj, attr)) + setattr(foo, attr, attr) + obj_with_attr = self.lazy_wrap(foo) + self.assertTrue(hasattr(obj_with_attr, attr)) + self.assertEqual(getattr(obj_with_attr, attr), attr) + def test_getattr(self): obj = self.lazy_wrap(Foo()) self.assertEqual(obj.foo, "bar") |