diff --git a/plone/dexterity/schema.py b/plone/dexterity/schema.py index cd56ab7..38ea083 100644 --- a/plone/dexterity/schema.py +++ b/plone/dexterity/schema.py @@ -39,7 +39,7 @@ def volatile(func): @functools.wraps(func) def decorator(self, portal_type): fti = queryUtility(IDexterityFTI, name=portal_type) - if fti is not None: + if fti is not None and self.cache_enabled: key = '_v_schema_%s' % func.__name__ cache = getattr(fti, key, None) if cache is not None: @@ -49,7 +49,7 @@ def volatile(func): value = func(self, fti) - if fti is not None and value is not None: + if fti is not None and value is not None and self.cache_enabled: setattr(fti, key, (fti._p_mtime, value)) return value @@ -81,6 +81,9 @@ class SchemaCache(object): lock = RLock() + def __init__(self, cache_enabled=True): + self.cache_enabled = cache_enabled + @synchronized(lock) @volatile def get(self, fti): diff --git a/plone/dexterity/tests/test_security.py b/plone/dexterity/tests/test_security.py index 0854090..14a8c54 100644 --- a/plone/dexterity/tests/test_security.py +++ b/plone/dexterity/tests/test_security.py @@ -16,11 +16,15 @@ from plone.dexterity.fti import DexterityFTI from plone.autoform.interfaces import READ_PERMISSIONS_KEY -class TestAttributeProtection(MockTestCase): +class TestAttributeProtection(MockTestCase): def setUp(self): SCHEMA_CACHE.clear() - + SCHEMA_CACHE.cache_enabled = False + + def tearDown(self): + SCHEMA_CACHE.cache_enabled = True + def test_item(self): # Mock schema model @@ -31,6 +35,8 @@ class TestAttributeProtection(MockTestCase): # Mock FTI fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) self.mock_utility(fti_mock, IDexterityFTI, u'testtype') @@ -70,6 +76,8 @@ class TestAttributeProtection(MockTestCase): # Mock FTI fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) self.mock_utility(fti_mock, IDexterityFTI, u'testtype') @@ -111,6 +119,8 @@ class TestAttributeProtection(MockTestCase): # Mock FTI fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) self.mock_utility(fti_mock, IDexterityFTI, u'testtype') @@ -148,6 +158,8 @@ class TestAttributeProtection(MockTestCase): # Mock FTI fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) self.mock_utility(fti_mock, IDexterityFTI, u'testtype') @@ -176,6 +188,8 @@ class TestAttributeProtection(MockTestCase): # Mock FTI fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) + self.expect(fti_mock.lookupSchema()).result(ITestSchema) self.mock_utility(fti_mock, IDexterityFTI, u'testtype') diff --git a/plone/dexterity/tests/test_webdav.py b/plone/dexterity/tests/test_webdav.py index 80a302b..c601575 100644 --- a/plone/dexterity/tests/test_webdav.py +++ b/plone/dexterity/tests/test_webdav.py @@ -920,8 +920,6 @@ class TestFileRepresentation(MockTestCase): fti_mock = self.mocker.mock(DexterityFTI) SCHEMA_CACHE.clear() self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.behaviors).result([]) self.expect(fti_mock.behaviors).result([]) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") @@ -943,8 +941,6 @@ class TestFileRepresentation(MockTestCase): SCHEMA_CACHE.clear() fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.behaviors).result([]) self.expect(fti_mock.behaviors).result([]) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") @@ -968,8 +964,6 @@ class TestFileRepresentation(MockTestCase): SCHEMA_CACHE.clear() fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.behaviors).result([]) self.expect(fti_mock.behaviors).result([]) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") @@ -1030,7 +1024,6 @@ class TestFileRepresentation(MockTestCase): SCHEMA_CACHE.clear() fti_mock = self.mocker.mock(DexterityFTI) self.expect(fti_mock.lookupSchema()).result(ITest) - self.expect(fti_mock.lookupSchema()).result(ITest) self.mock_adapter(MockBehaviorAssignable, IBehaviorAssignable, (Item, ))