Commit 805183d5 authored by Katia Saurfelt's avatar Katia Saurfelt
Browse files

feat: schema validation, add choice + zeroOrMore for DataObjectGroup (closes #35)

--HG--
branch : seda21
parent adfb3d67f7f2
Pipeline #89861 failed with stages
in 1 minute and 18 seconds
...@@ -765,9 +765,12 @@ class SEDA22RelaxNGExport(SEDA2RelaxNGExport): ...@@ -765,9 +765,12 @@ class SEDA22RelaxNGExport(SEDA2RelaxNGExport):
if nodes or opt_nodes: if nodes or opt_nodes:
# insert after definition of dop's id attribute # insert after definition of dop's id attribute
for node in chain(nodes, opt_nodes): for node in chain(nodes, opt_nodes):
zeroormore = self.element("rng:zeroOrMore")
choice = self.element("rng:choice", zeroormore)
dop[0].addnext(zeroormore)
# insert DataObjectGroup with id from [Physical|Binary]DataObject if found # insert DataObjectGroup with id from [Physical|Binary]DataObject if found
group = self.element( group = self.element(
"rng:element", attributes={"name": "DataObjectGroup"} "rng:element", choice, attributes={"name": "DataObjectGroup"}
) )
node_id = node.xpath( node_id = node.xpath(
'rng:attribute[@name="id"]/@xml:id[1]', namespaces=namespaces 'rng:attribute[@name="id"]/@xml:id[1]', namespaces=namespaces
...@@ -778,7 +781,6 @@ class SEDA22RelaxNGExport(SEDA2RelaxNGExport): ...@@ -778,7 +781,6 @@ class SEDA22RelaxNGExport(SEDA2RelaxNGExport):
) )
attr_element.attrib[self.qname("xml:id")] = f"g{node_id[0]}" attr_element.attrib[self.qname("xml:id")] = f"g{node_id[0]}"
self.element("rng:data", attr_element, {"type": "ID"}) self.element("rng:data", attr_element, {"type": "ID"})
dop[0].addnext(group)
group.append(node) group.append(node)
def postprocess_dataobjectsreference(self, root, namespaces): def postprocess_dataobjectsreference(self, root, namespaces):
......
...@@ -537,7 +537,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC): ...@@ -537,7 +537,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC):
len( len(
self.xpath( self.xpath(
dop, dop,
'./rng:element[@name="DataObjectGroup"]/rng:element[@name="BinaryDataObject"]', # noqa './rng:zeroOrMore/rng:choice/rng:element[@name="DataObjectGroup"]/'
'rng:element[@name="BinaryDataObject"]',
) )
), ),
2, 2,
...@@ -546,7 +547,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC): ...@@ -546,7 +547,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC):
len( len(
self.xpath( self.xpath(
dop, dop,
'./rng:element[@name="DataObjectGroup"]/rng:element[@name="PhysicalDataObject"]', # noqa './rng:zeroOrMore/rng:choice/rng:element[@name="DataObjectGroup"]'
'/rng:element[@name="PhysicalDataObject"]',
) )
), ),
1, 1,
...@@ -560,7 +562,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC): ...@@ -560,7 +562,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC):
len( len(
self.xpath( self.xpath(
dop, dop,
'./rng:element[@name="DataObjectGroup"]/rng:element[@name="BinaryDataObject"]', # noqa './rng:zeroOrMore/rng:choice/rng:element[@name="DataObjectGroup"]'
'/rng:element[@name="BinaryDataObject"]',
) )
), ),
2, 2,
...@@ -569,7 +572,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC): ...@@ -569,7 +572,8 @@ class SEDA2RNGExportTC(RelaxNGTestMixin, CubicWebTC):
len( len(
self.xpath( self.xpath(
dop, dop,
'./rng:element[@name="DataObjectGroup"]/rng:element[@name="PhysicalDataObject"]', # noqa './rng:zeroOrMore/rng:choice/rng:element[@name="DataObjectGroup"]'
'/rng:element[@name="PhysicalDataObject"]',
) )
), ),
1, 1,
......
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