Skip to content

Commit

Permalink
[fc] Repository: plone.dexterity
Browse files Browse the repository at this point in the history
Branch: refs/heads/master
Date: 2019-08-29T10:33:04+02:00
Author: ale-rt (ale-rt) <alessandro.pisa@gmail.com>
Commit: plone/plone.dexterity@e63e55a

Avoid looking up behaviors with an empty name

Fixes #110

Files changed:
A news/110.bugfix
M plone/dexterity/schema.py
Repository: plone.dexterity

Branch: refs/heads/master
Date: 2019-09-03T13:24:21+02:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/plone.dexterity@76bdf0b

Merge pull request #112 from plone/110-do-not-lookup-faux-behaviors

Avoid looking up behaviors with an empty name

Files changed:
A news/110.bugfix
M plone/dexterity/schema.py
  • Loading branch information
jensens committed Sep 3, 2019
1 parent 91604ad commit 2313a79
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions last_commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,35 @@ Repository: plone.dexterity


Branch: refs/heads/master
Date: 2019-08-29T10:13:17+02:00
Date: 2019-08-29T10:33:04+02:00
Author: ale-rt (ale-rt) <alessandro.pisa@gmail.com>
Commit: https://github.com/plone/plone.dexterity/commit/91407dd58997460da1f249536c557439f3b3635a
Commit: https://github.com/plone/plone.dexterity/commit/e63e55abe2530aff7eea522aa46a489272dedece

Improve debugging
Avoid looking up behaviors with an empty name

The debug messages issued when a non existent behavior is recorded in an FTI have been improved

Fixes #109
Fixes #110

Files changed:
A news/109.bugfix
A news/110.bugfix
M plone/dexterity/schema.py
M plone/dexterity/tests/test_schema_cache.py

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

Repository: plone.dexterity


Branch: refs/heads/master
Date: 2019-09-03T13:19:35+02:00
Date: 2019-09-03T13:24:21+02:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: https://github.com/plone/plone.dexterity/commit/04f9f7046455ab004f8f40d45e56c939e0f9511c
Commit: https://github.com/plone/plone.dexterity/commit/76bdf0b12b9a84076b3a7ef3cb2bdd333f9ba4fc

Merge pull request #110 from plone/109-improved-warnings
Merge pull request #112 from plone/110-do-not-lookup-faux-behaviors

Improve debugging
Avoid looking up behaviors with an empty name

Files changed:
A news/109.bugfix
A news/110.bugfix
M plone/dexterity/schema.py
M plone/dexterity/tests/test_schema_cache.py

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

0 comments on commit 2313a79

Please sign in to comment.