Commit e1ba39be authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Test that unicity of CompoundMapper's name applies within a given entity type

And make the error message a bit more explicit.

Closes #17103219.
parent fd81943ceab3
......@@ -104,7 +104,8 @@ class CompoundMapper(JSONSchemaMapper):
# Make sure 'name' is unique amongst objects with
# 'jsonschema.object' regid.
raise ValueError('a class with name "{}" is already '
'registered for {} entity type'.format(, cls.etype))
# Prevent duplicate mapping of the same etype/rtype.
common_rtypes = set(obj._relations) & set(cls._relations)
if common_rtypes:
......@@ -922,6 +922,40 @@ class CompoundMapperTC(CubicWebTC):
except ValueError as e:"unexpected {}".format(e))
def test_name_unicity_constraints_per_entity_type(self):
"""Several CompoundMapper with the same name may be registered if they
concern distinct entity types.
class c1(CompoundMapper):
etype = 'Book'
relations = (
class c2(CompoundMapper):
name = 'c1'
etype = 'CWUser'
relations = (
class c3(CompoundMapper):
name = 'c1'
etype = 'Book'
relations = (
('author', 'object')
registry = self.vreg['mappers']
with patch.dict(registry, clear=True):
self.assertIn(c1, self.vreg['mappers']['jsonschema.object'])
self.assertIn(c2, self.vreg['mappers']['jsonschema.object'])
expected_regexp = 'a class with name "c1" is already registered for Book entity type' # noqa: E501
with self.assertRaisesRegex(ValueError, expected_regexp):
def test_mapped_attributes_hidden(self):
"""Make sure attributes mapped to CompoundMapper are in "hidden" uicfg
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment