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

[profile gen] Avoid duplicated format ids / mime types in enum

There may be cases where several concepts use the same label, mostly in the case
of format identifier but do the same thing for mime types as a safety belt.
parent a94fa8b3611a
......@@ -891,14 +891,14 @@ class SEDA1XSDExport(SEDA2ExportAdapter):
format_id = data_object.format_id
if format_id is not None:
format_ids = [_concept_value(concept, self.concepts_language)
for concept in format_id.concepts]
format_ids = sorted(set(_concept_value(concept, self.concepts_language)
for concept in format_id.concepts))
else:
format_ids = []
mime_type = data_object.mime_type
if mime_type is not None:
mime_types = [_concept_value(concept, self.concepts_language)
for concept in mime_type.concepts]
mime_types = sorted(set(_concept_value(concept, self.concepts_language)
for concept in mime_type.concepts))
else:
mime_types = []
encoding = data_object.encoding
......
......@@ -1018,6 +1018,24 @@ class OldSEDAExportTC(RelaxNGTestMixin, CubicWebTC):
self.assertEqual([node.attrib['name'] for node in root],
['ArchiveObject', 'Document'])
def test_duplicated_format_id(self):
with self.admin_access.cnx() as cnx:
scheme = testutils.scheme_for_type(cnx, 'file_category', None,
u'fmt/123', u'fmt/123')
concepts = scheme.reverse_in_scheme
transfer = cnx.create_entity('SEDAArchiveTransfer', title=u'my profile',
simplified_profile=True)
bdo = testutils.create_data_object(transfer)
bdo.format_id.cw_set(seda_format_id_to=concepts)
adapter = transfer.cw_adapt_to('SEDA-1.0.rng')
root = etree.Element('test-root')
adapter.xsd_attachment(root, bdo)
self.assertEqual([node.text for node in self.xpath(root, '//rng:value')],
['fmt/123'])
class SEDAExportUnitTest(unittest.TestCase):
......
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