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

[profile gen / test] Add functional test using file provided by the SAEM project

Ensuring we're able to validate a sample SEDA 0.2 profile.
parent 9e58a45e2742
<?xml version="1.0" encoding="UTF-8"?>
<ArchiveTransfer xmlns="fr:gouv:ae:archive:draft:standard_echange_v0.2">
<Comment>Pewal</Comment>
<Date>2016-12-14T09:10:13Z</Date>
<TransferIdentifier>75241-a000000042</TransferIdentifier>
<TransferringAgency>
<Identification>75241/ou000035346</Identification>
<Name>Direction du pilotage de la modernisation et du dialogue social - BM DGRHAG</Name>
</TransferringAgency>
<ArchivalAgency>
<Identification>75241/ou000035333</Identification>
<Name>Direction des archives Bordeaux métropole</Name>
</ArchivalAgency>
<Contains>
<ArchivalAgreement>AccordBordeaux</ArchivalAgreement>
<!-- <ArchivalProfile>25651/p000035368</ArchivalProfile> -->
<DescriptionLanguage listVersionID="edition 2009">fr</DescriptionLanguage>
<DescriptionLevel listVersionID="edition 2009">series</DescriptionLevel>
<Name>Pewal</Name>
<TransferringAgencyArchiveIdentifier>75241/a000000039</TransferringAgencyArchiveIdentifier>
<ContentDescription>
<Language listVersionID="edition 2009">fr</Language>
<LatestDate>2009-07-14</LatestDate>
<OldestDate>2009-07-14</OldestDate>
</ContentDescription>
<Appraisal>
<Code listVersionID="edition 2009">detruire</Code>
<Duration>P01Y</Duration>
<StartDate>2009-07-14</StartDate>
</Appraisal>
<AccessRestriction>
<Code listVersionID="edition 2009">AR045</Code>
<StartDate>2009-07-14</StartDate>
</AccessRestriction>
<Contains>
<DescriptionLevel listVersionID="edition 2009">item</DescriptionLevel>
<Name>Kesso</Name>
<TransferringAgencyObjectIdentifier>75241/a000000040</TransferringAgencyObjectIdentifier>
<ContentDescription>
<Language listVersionID="edition 2009">fr</Language>
<LatestDate>2009-07-14</LatestDate>
<OldestDate>2009-07-14</OldestDate>
<ContentDescriptive>
<KeywordContent>acte authentique</KeywordContent>
<KeywordReference>workspace://SpacesStore/ff9840fd-797f-4141-ac4c-cb57d5988ef9</KeywordReference>
</ContentDescriptive>
</ContentDescription>
<Document>
<Attachment encodingCode="7" filename="koala.jpg" mimeCode="image/jpeg"/>
<!-- <Creation>2009-07-14T05:32:31Z</Creation> -->
<!-- <Identification>75241/a000000041</Identification> -->
<Type listVersionID="edition 2009">RISEM</Type>
</Document>
</Contains>
</Contains>
</ArchiveTransfer>
......@@ -75,9 +75,9 @@ class XmlTestMixin(object):
"""Return etree attribute definitions for 'name'"""
raise NotImplementedError()
def profile_etree(self, transfer_entity):
def profile_etree(self, transfer_entity, adapter_id=None):
"""Return etree representation of profile's XSD for the given transfer entity."""
adapter = transfer_entity.cw_adapt_to(self.adapter_id)
adapter = transfer_entity.cw_adapt_to(adapter_id or self.adapter_id)
root = adapter.dump_etree()
self.assertXmlValid(root)
return root
......@@ -94,6 +94,13 @@ class XmlTestMixin(object):
message = checker.output_difference(Example("", expected), actual, 0)
self.fail(message)
def check_xsd_profile(self, root, sample_file, **substitutions):
"""Check that the SEDA profile can be used to validate a sample XML document."""
profile = self.schema_class(root)
with open(sample_file) as f:
sample_xml_string = f.read().format(**substitutions)
profile.assert_(etree.fromstring(sample_xml_string))
class XMLSchemaTestMixin(XmlTestMixin):
"""Mixin extending XmlTestMixin with implementation of some assert methods for XMLSchema."""
......@@ -582,13 +589,6 @@ class SEDAExportFuncTCMixIn(object):
cnx.commit()
self.transfer_eid = transfer.eid
def check_xsd_profile(self, root, sample_file, **substitutions):
"""Check that the SEDA profile can be used to validate a sample XML document."""
profile = self.schema_class(root)
with open(sample_file) as f:
sample_xml_string = f.read().format(**substitutions)
profile.assert_(etree.fromstring(sample_xml_string))
def test_profile1(self):
"""Check a minimal SEDA profile validating BV2.0_min.xml."""
with self.admin_access.client_cnx() as cnx:
......@@ -815,6 +815,54 @@ class OldSEDARNGExportTC(RelaxNGTestMixin, OldSEDAExportMixin, CubicWebTC):
def test_seda_0_2_rng(self):
self._test_profile('SEDA-0.2.rng', 'seda_02_export.rng')
def test_seda_0_2_bordereau_ref(self):
"""Check a sample SEDA 0.2 profile validation."""
with self.admin_access.client_cnx() as cnx:
create = cnx.create_entity
transfer = create('SEDAArchiveTransfer', title=u'test profile',
simplified_profile=True)
create('SEDAComment', seda_comment=transfer)
unit, unit_alt, unit_alt_seq = create_archive_unit(transfer)
content = create('SEDAContent', seda_content=unit_alt_seq)
create('SEDATitle', seda_title=content)
create('SEDAArchivalAgreement', seda_archival_agreement=transfer)
create('SEDATransferringAgencyArchiveUnitIdentifier',
seda_transferring_agency_archive_unit_identifier=content)
create('SEDAStartDate', seda_start_date=content)
create('SEDAEndDate', seda_end_date=content)
appraisal_rule = create('SEDAAppraisalRule', seda_appraisal_rule=unit_alt_seq)
appraisal_rule_seq = create('SEDASeqAppraisalRuleRule',
reverse_seda_seq_appraisal_rule_rule=appraisal_rule)
create('SEDAStartDate', seda_start_date=appraisal_rule_seq)
access_rule = create('SEDAAccessRule', seda_access_rule=unit_alt_seq)
access_rule_seq = create('SEDASeqAccessRuleRule',
reverse_seda_seq_access_rule_rule=access_rule)
create('SEDAStartDate', seda_start_date=access_rule_seq)
subunit, subunit_alt, subunit_alt_seq = create_archive_unit(unit_alt_seq, id=u'subunit')
subcontent = create('SEDAContent', seda_content=subunit_alt_seq)
create('SEDATitle', seda_title=subcontent)
create('SEDATransferringAgencyArchiveUnitIdentifier',
seda_transferring_agency_archive_unit_identifier=subcontent)
create('SEDAStartDate', seda_start_date=subcontent)
create('SEDAEndDate', seda_end_date=subcontent)
kw = create('SEDAKeyword', user_cardinality=u'0..n', seda_keyword=subcontent)
create('SEDAKeywordContent', reverse_seda_keyword_content=kw)
bdo = create_data_object(transfer)
create('SEDADataObjectReference',
seda_data_object_reference=subunit_alt_seq,
seda_data_object_reference_id=bdo)
create('SEDAEncoding', seda_encoding_from=bdo)
create('SEDAMimeType', seda_mime_type_from=bdo)
cnx.commit()
root = self.profile_etree(transfer, 'SEDA-0.2.rng')
self.check_xsd_profile(root, self.datapath('seda_02_bordereau_ref.xml'))
if __name__ == '__main__':
import unittest
......
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