summaryrefslogtreecommitdiff
path: root/tests/utils_tests
diff options
context:
space:
mode:
authorTheo Alexiou <theofilosalexiou@gmail.com>2022-02-13 17:27:12 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-16 10:51:15 +0100
commit97d7990abde3fe4b525ae83958fd0b52d6a1d13f (patch)
tree56e0ba7eae9e551bcccfbd87995a8020836ab228 /tests/utils_tests
parent1d071ec1aa8fa414bb96b41f7be8a1bd01079815 (diff)
downloaddjango-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.py22
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")