fail gracefully when a schema lookup fails do to import error in lookupSchema
This commit is contained in:
parent
8f6fed05e5
commit
12f24e4ea2
|
@ -1,14 +1,24 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
2.1.2 (unreleased)
|
||||
2.1.3 (unreleased)
|
||||
------------------
|
||||
- Fail gracefully when a schema lookup fails due to schema that doesn't
|
||||
exist or no longer exists for some reason or another.
|
||||
[eleddy]
|
||||
|
||||
- Add convenience functions (aka sanity) for getting
|
||||
dexterity fields and behavior fields in a consistent way
|
||||
[eleddy]
|
||||
|
||||
|
||||
2.1.2 (2013-03-05)
|
||||
------------------
|
||||
|
||||
- Merged Rafael Oliveira's (@rafaelbco) @content-core views from
|
||||
collective.cmfeditionsdexteritycompat.
|
||||
[rpatterson]
|
||||
|
||||
|
||||
2.1.1 (2013-01-17)
|
||||
------------------
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os.path
|
||||
import logging
|
||||
|
||||
from zope.interface import implements
|
||||
|
||||
|
@ -204,12 +205,18 @@ class DexterityFTI(base.DynamicViewTypeInformation):
|
|||
return not(self.schema)
|
||||
|
||||
def lookupSchema(self):
|
||||
schema = None
|
||||
|
||||
# If a specific schema is given, use it
|
||||
if self.schema:
|
||||
schema = utils.resolveDottedName(self.schema)
|
||||
if schema is None:
|
||||
raise ValueError(u"Schema %s set for type %s cannot be resolved" % (self.schema, self.getId()))
|
||||
try:
|
||||
schema = utils.resolveDottedName(self.schema)
|
||||
except ImportError:
|
||||
logging.warning(u"Schema %s set for type %s cannot be resolved" % (self.schema, self.getId()))
|
||||
# fall through to return a fake class with no
|
||||
# fields so that end user code doesn't break
|
||||
|
||||
if schema:
|
||||
return schema
|
||||
|
||||
# Otherwise, look up a dynamic schema. This will query the model for
|
||||
|
|
|
@ -87,6 +87,20 @@ class TestFTI(MockTestCase):
|
|||
# cleanup
|
||||
delattr(plone.dexterity.schema.generated, schemaName)
|
||||
|
||||
def test_lookupSchema_with_nonexistant_schema(self):
|
||||
""" Tests the case where a dexterity type is not removed cleanly
|
||||
from the fti, but the code has been removed.
|
||||
"""
|
||||
fti = DexterityFTI(u"testtype")
|
||||
fti.schema = 'model.wont.be.imported'
|
||||
portal = self.create_dummy(getPhysicalPath=lambda:('', 'site'))
|
||||
self.mock_utility(portal, ISiteRoot)
|
||||
schemaName = utils.portalTypeToSchemaName(fti.getId())
|
||||
setattr(plone.dexterity.schema.generated, schemaName, ITestSchema)
|
||||
self.assertEquals(ITestSchema, fti.lookupSchema())
|
||||
delattr(plone.dexterity.schema.generated, schemaName)
|
||||
|
||||
|
||||
def test_lookupModel_from_string(self):
|
||||
fti = DexterityFTI(u"testtype")
|
||||
fti.schema = None
|
||||
|
|
Reference in New Issue