diff --git a/news/109.bugfix b/news/109.bugfix new file mode 100644 index 00000000..ae935a23 --- /dev/null +++ b/news/109.bugfix @@ -0,0 +1 @@ +The debug messages issued when a non existent behavior is recorded in an FTI have been improved [ale-rt] diff --git a/plone/dexterity/schema.py b/plone/dexterity/schema.py index 93565ea4..9d0afa86 100644 --- a/plone/dexterity/schema.py +++ b/plone/dexterity/schema.py @@ -136,10 +136,11 @@ def behavior_registrations(self, fti): if registration is None: # BBB - this case should be deprecated in v 3.0 warnings.warn( - 'No behavior registration found for behavior named: "{0}"' + 'No behavior registration found for behavior named "{0}"' + ' for factory "{1}"' ' - trying deprecated fallback lookup (will be removed ' 'in 3.0)..."'.format( - behavior_name + behavior_name, fti.getId() ), DeprecationWarning, ) @@ -147,8 +148,8 @@ def behavior_registrations(self, fti): schema_interface = resolve(behavior_name) except (ValueError, ImportError): log.error( - "Error resolving behavior {0}".format( - behavior_name + "Error resolving behavior {0} for factory {1}".format( + behavior_name, fti.getId() ) ) continue diff --git a/plone/dexterity/tests/test_schema_cache.py b/plone/dexterity/tests/test_schema_cache.py index 5429b310..9d901e3b 100644 --- a/plone/dexterity/tests/test_schema_cache.py +++ b/plone/dexterity/tests/test_schema_cache.py @@ -1,12 +1,14 @@ # -*- coding: utf-8 -*- from .case import MockTestCase from mock import Mock +from mock import patch from plone.dexterity.fti import DexterityFTI from plone.dexterity.interfaces import IDexterityFTI from plone.dexterity.schema import SCHEMA_CACHE from zope.interface import Interface import unittest +import warnings class TestSchemaCache(MockTestCase): @@ -57,6 +59,25 @@ class ITestBehavior(Interface): self.assertTrue(r1[0] is r2[0] is registration) + def test_unexistent_behaviors_lookup(self): + fti = DexterityFTI(u"testtype") + self.mock_utility(fti, IDexterityFTI, name=u"testtype") + # Set an unregistered behavior + fti.behaviors = ["foo.bar"] + + with patch("warnings.warn") as mock_warnings: + warning_list = [call[1][0] for call in mock_warnings.mock_calls] + SCHEMA_CACHE.behavior_registrations(u'testtype') + # Verify the warning has been issued + self.assertEqual( + mock_warnings.mock_calls[-1].args[0], + ( + 'No behavior registration found for behavior named ' + '"foo.bar" for factory "testtype" - trying deprecated ' + 'fallback lookup (will be removed in 3.0)..."' + ) + ) + def test_repeated_subtypes_lookup(self): fti = DexterityFTI(u"testtype")