mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #28358 -- Prevented LazyObject from mimicking nonexistent attributes.
Thanks Sergey Fedoseev for the initial patch.
This commit is contained in:
committed by
Mariusz Felisiak
parent
1d071ec1aa
commit
97d7990abd
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user