Commit 1fe812b6 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

Extend rule_type_from_etype to support SEDASeqXXXRuleRule etype

we get this kind of entity type when forcing display of some inlined creation
form (job done in later cset).

Add an assertion to make unexpected entity type easier to debug.
parent fff22f766b10
......@@ -99,13 +99,20 @@ def full_seda2_profile(cls, req, rset=None, entity=None, **kwargs):
def rule_type_from_etype(etype):
"""Return the rule type from an etype like SEDAAccessRule or SEDAAltAccessRulePreventInheritance
"""Return the rule type (e.g. 'access') from an etype enclosing the information
(e.g. 'SEDAAltAccessRulePreventInheritance', 'SEDASeqAaccessRuleRule' or 'SEDAAccessRule')
if etype.startswith('SEDAAlt'):
rule_type = etype[len('SEDAAlt'):-len('RulePreventInheritance')]
elif etype.startswith('SEDASeq'):
rule_type = etype[len('SEDASeq'):-len('RuleRule')]
rule_type = etype[len('SEDA'):-len('Rule')]
return rule_type.lower()
rule_type = rule_type.lower()
assert rule_type in ('access', 'appraisal', 'classification',
'reuse', 'dissemination', 'storage'), \
'unhandled etype {}'.format(etype)
return rule_type
class DirectLinkIContained(IContained):
......@@ -25,7 +25,7 @@ from logilab.common import attrdict
from cubicweb.devtools.testlib import CubicWebTC
from cubes.seda.entities import (seda_profile_container_def, simplified_profile, full_seda2_profile,
parent_and_container, rule_type_from_etype)
from testutils import create_archive_unit, create_data_object
......@@ -155,6 +155,19 @@ class ITreeTC(CubicWebTC):
self.assertParent(bdo, au.eid)
class RuleFromETypeTC(unittest.TestCase):
def test_rule_from_etype(self):
for rule_type in ('access', 'appraisal', 'classification',
'reuse', 'dissemination', 'storage'):
for prefix, suffix in [
('SEDAAlt', 'RulePreventInheritance'),
('SEDASeq', 'RuleRule'),
('SEDA', 'Rule'),
self.assertEqual(rule_type_from_etype(prefix + rule_type.capitalize() + suffix),
class ParentAndContainerTC(CubicWebTC):
def test_nodata(self):
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