[profile gen] Fix path_target_values wrt skipped attributes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 05 Jan 2017 14:37:47 +0100
changeset 2261 6a2991d3a896
parent 2260 88b2dff556c3
child 2262 63e336cdbc8c
[profile gen] Fix path_target_values wrt skipped attributes for instance in case of restrictionEndDate, it was returning [(content entity, restriction end date entity)] instead of [(restriction end date entity, None)] This was only causing cardinality error (eg you get the content entity's cardinality instead of the restriction end date's one) which have been unnoticed until a cardinality uncompatible with attribute was used on a content node. Closes #16688086
entities/profile_generation.py
test/test_profile_generation.py
--- a/entities/profile_generation.py	Wed Jan 11 09:41:15 2017 +0100
+++ b/entities/profile_generation.py	Thu Jan 05 14:37:47 2017 +0100
@@ -1531,7 +1531,7 @@
             rdefschema = next(iter(rschema(rtype).rdefs.values()))
         except KeyError:
             if rtype in SKIP_ATTRS:
-                return rtype_targets
+                return [(e, None) for e in entities]
             # element is still in the intermediary representation but not in the schema
             return [(None, None)]
         rtype_targets = []
--- a/test/test_profile_generation.py	Wed Jan 11 09:41:15 2017 +0100
+++ b/test/test_profile_generation.py	Thu Jan 05 14:37:47 2017 +0100
@@ -1,4 +1,4 @@
-# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -220,7 +220,7 @@
 
 class PathTargetValuesTC(CubicWebTC):
 
-    def test_path(self):
+    def test_keyword_path(self):
         element_defs = iter(XSDMMapping('Keyword'))
         with self.admin_access.client_cnx() as cnx:
             create = cnx.create_entity
@@ -289,6 +289,52 @@
             self.assertEqual(target_value[0], None)
             self.assertEqual(target_value[1], None)
 
+    def test_restriction_path(self):
+        element_defs = iter(XSDMMapping('Content'))
+        with self.admin_access.client_cnx() as cnx:
+            create = cnx.create_entity
+            content = create('SEDAContent')
+            restr_value = create('SEDArestrictionValue', seda_restriction_value=content)
+            restr_end_date = create('SEDArestrictionEndDate', seda_restriction_end_date=content)
+
+            edef = next(element_defs)
+            # readable_edef(edef)
+            # ('Content',
+            #  'SEDAContent',
+            #  [('id', [('seda_id', 'object', 'SEDAid'), ('id', 'subject', 'String')]),
+            #   ('href',
+            #    [('seda_href', 'object', 'SEDAhref'), ('href', 'subject', 'String')]),
+            #   ('restrictionRuleIdRef',
+            #    [('seda_restriction_rule_id_ref', 'object', 'SEDArestrictionRuleIdRef'),
+            #     ('restriction_rule_id_ref', 'subject', 'String')]),
+            #   ('restrictionValue',
+            #    [('seda_restriction_value', 'object', 'SEDArestrictionValue'),
+            #     ('restriction_value', 'subject', 'String')]),
+            #   ('restrictionEndDate',
+            #    [('seda_restriction_end_date', 'object', 'SEDArestrictionEndDate'),
+            #     ('restriction_end_date', 'subject', 'Date')]),
+            #   ...
+
+            def path_for(schema_name, paths):
+                for path_schema, path in paths:
+                    if path_schema.target.local_name == schema_name:
+                        return path
+                raise Exception('%s not found in %s' % (schema_name, paths))
+
+            path = path_for('restrictionValue', edef[-1])
+            target_values = _path_target_values(content, path)
+            self.assertEqual(len(target_values), 1)
+            target_value = target_values[0]
+            self.assertEqual(target_value[0].eid, restr_value.eid)
+            self.assertEqual(target_value[1], None)
+
+            path = path_for('restrictionEndDate', edef[-1])
+            target_values = _path_target_values(content, path)
+            self.assertEqual(len(target_values), 1)
+            target_value = target_values[0]
+            self.assertEqual(target_value[0].eid, restr_end_date.eid)
+            self.assertEqual(target_value[1], None)
+
 
 class SEDA2ExportTCMixIn(object):