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

[xsd gen] Proper XSD generation for KeywordReference

when only a scheme is specified, don't fix the type but the schemeURI.
parent 3d906c0fbc90
......@@ -219,8 +219,9 @@ class SEDA2XSDExport(EntityAdapter):
else:
extension_element = target_element[0][0][0]
if getattr(target_value, 'cw_etype', None) == 'Concept':
self.concept_scheme_attribute(xselement, extension_element, target_value)
self.concept_scheme_attribute(xselement, extension_element, target_value.scheme)
elif (xselement.local_name == 'KeywordReference' and card_entity.scheme):
self.concept_scheme_attribute(xselement, extension_element, card_entity.scheme)
fixed_value = xsd_serialize(target_value)
if fixed_value is not None:
attr = 'default' if hasattr(target_value, 'id') else 'fixed'
......@@ -241,16 +242,15 @@ class SEDA2XSDExport(EntityAdapter):
if getattr(target_value, 'eid', None): # value is an entity
to_process[xselement].append((target_value, target_element))
def concept_scheme_attribute(self, xselement, type_element, target_value):
def concept_scheme_attribute(self, xselement, type_element, scheme):
try:
xsattr = _xselement_scheme_attribute(xselement)
except KeyError:
print 'no scheme to be specified for', xselement
else:
scheme_attr = self.element(
'xsd:attribute',
attributes={'name': xsattr.local_name,
'fixed': target_value.scheme.absolute_url()})
scheme_attr = self.element('xsd:attribute',
attributes={'name': xsattr.local_name,
'fixed': scheme.absolute_url()})
type_element.append(scheme_attr)
def fill_concept_element(self, xselement, type_element, target_element, target_value):
......
......@@ -213,6 +213,60 @@ class SEDAXSDExportTC(XmlTestMixin, CubicWebTC):
open_types = xpath('//xs:complexType[@name="OpenType"]')
self.assertEqual(len(open_types), 1)
def test_keyword(self):
with self.admin_access.client_cnx() as cnx:
create = cnx.create_entity
scheme = scheme_for_rtype(cnx, 'seda_keyword_type_to', u'theme')
kw_type = scheme.reverse_in_scheme[0]
transfer = create('SEDAArchiveTransfer', title=u'test profile')
unit, unit_alt = create_archive_unit(transfer, user_cardinality=u'0..n')
unit_alt_seq = create(
'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement',
reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management=unit_alt)
content = create('SEDAContent', seda_content=unit_alt_seq)
kw = create('SEDAKeyword', seda_keyword=content)
create('SEDAKeywordContent', reverse_seda_keyword_content=kw,
keyword_content=u'kwick')
kwr_e = create('SEDAKeywordReference', seda_keyword_reference_from=kw,
seda_keyword_reference_to_scheme=scheme)
create('SEDAKeywordType', seda_keyword_type_from=kw,
seda_keyword_type_to=kw_type)
profile = self.profile_etree(transfer)
xpath = lambda x: profile.xpath(x, namespaces=NAMESPACES)
kwc = xpath('//xs:element[@name="KeywordContent"]')
self.assertEqual(len(kwc), 1)
self.assertEqual(kwc[0].attrib, {'name': 'KeywordContent', 'fixed': 'kwick'})
kwt = xpath('//xs:element[@name="KeywordType"]')
self.assertEqual(len(kwt), 1)
self.assertEqual(kwt[0].attrib, {'name': 'KeywordType', 'fixed': 'theme',
'minOccurs': '0'})
self.assertXSDAttributes(kwt[0],
[{'name': 'listVersionID',
'fixed': scheme.absolute_url()}])
kwr = xpath('//xs:element[@name="KeywordReference"]')
self.assertEqual(len(kwr), 1)
self.assertEqual(kwr[0].attrib, {'name': 'KeywordReference',
'minOccurs': '0'})
self.assertXSDAttributes(kwr[0],
[{'name': 'schemeURI',
'fixed': scheme.absolute_url()}])
kwr_e.cw_set(seda_keyword_reference_to=kw_type)
profile = self.profile_etree(transfer)
xpath = lambda x: profile.xpath(x, namespaces=NAMESPACES)
kwr = xpath('//xs:element[@name="KeywordReference"]')
self.assertEqual(len(kwr), 1)
self.assertEqual(kwr[0].attrib, {'name': 'KeywordReference', 'fixed': 'theme',
'minOccurs': '0'})
self.assertXSDAttributes(kwr[0],
[{'name': 'schemeURI',
'fixed': scheme.absolute_url()}])
def profile_etree(self, transfer_entity):
"""Return etree representation of profile's XSD for the given transfer entity"""
xsd = transfer_entity.cw_adapt_to('SEDA-2.0.xsd').dump()
......
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