Allow for the disabling of the schema cache (for testing purposes), and fix some expectations (we now expect more schema lookups in the test since the schema cache is disabled).
This commit is contained in:
parent
79f4255b41
commit
4ee6216de6
|
@ -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):
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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, ))
|
||||
|
|
Reference in New Issue