diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index 7e46750967fc3f2f86a3f522ee9b7239138fc5c7..cc5861c3504fbcb35174bc0ba3c927e96827710d 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -1807,6 +1807,37 @@ class TestPropertySheet: # ... other cases should be added here + + + # Tests for _aq_dynamic patch. Probably not in the right place. + def test_aq_dynamic(self): + doc = self.portal.person_module.newContent(portal_type='Person') + from Acquisition import Explicit + + class Ok(Explicit): + aq_dynamic_calls = [] + def _aq_dynamic(self, name): + self.aq_dynamic_calls.append(name) + return 'returned_attr' + + ok = Ok().__of__(doc) + self.assertEquals('returned_attr', getattr(ok, 'attr')) + self.assertEquals(ok.aq_dynamic_calls, ['attr']) + + def test_aq_dynamic_exception(self): + # if an exception is raised in _aq_dynamic, it should not be hidden + doc = self.portal.person_module.newContent(portal_type='Person') + from Acquisition import Explicit + + class NotOk(Explicit): + def _aq_dynamic(self, name): + raise ValueError() + + not_ok = NotOk().__of__(doc) + self.assertRaises(ValueError, getattr, not_ok, 'attr') + self.assertFalse(hasattr(not_ok, 'attr')) + + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestERP5Type))