def test_replacement_digiprovmd(self): """ It should have no special behaviour replacing digiprovMDs. """ digiprovmd_old = metsrw.SubSection('digiprovMD', self.STUB_MDWRAP) digiprovmd_new = metsrw.SubSection('digiprovMD', self.STUB_MDWRAP) digiprovmd_old.replace_with(digiprovmd_new) assert digiprovmd_old.get_status() is None assert digiprovmd_new.get_status() is None
def test_replacement_techmd(self): """ It should have no special behaviour replacing techMDs. """ techmd_old = metsrw.SubSection('techMD', self.STUB_MDWRAP) techmd_new = metsrw.SubSection('techMD', self.STUB_MDWRAP) techmd_old.replace_with(techmd_new) assert techmd_old.get_status() is 'superseded' assert techmd_new.get_status() is 'current'
def test_replacement_sourcemd(self): """ It should have no special behaviour replacing sourceMDs. """ sourcemd_old = metsrw.SubSection('sourceMD', self.STUB_MDWRAP) sourcemd_new = metsrw.SubSection('sourceMD', self.STUB_MDWRAP) sourcemd_old.replace_with(sourcemd_new) assert sourcemd_old.get_status() is None assert sourcemd_new.get_status() is None
def test_subsection_ordering(self): l = [] l.append(metsrw.SubSection('digiprovMD', self.STUB_MDWRAP)) l.append(metsrw.SubSection('sourceMD', self.STUB_MDWRAP)) l.append(metsrw.SubSection('rightsMD', self.STUB_MDWRAP)) l.append(metsrw.SubSection('techMD', self.STUB_MDWRAP)) l.sort() assert l[0].subsection == 'techMD' assert l[1].subsection == 'rightsMD' assert l[2].subsection == 'sourceMD' assert l[3].subsection == 'digiprovMD'
def test_replacement_dmdsec(self): """ It should mark the first dmdSec 'original'. It should mark all other dmdSecs 'updated'. """ dmdsec_old = metsrw.SubSection('dmdSec', self.STUB_MDWRAP) assert dmdsec_old.get_status() == 'original' dmdsec_new = metsrw.SubSection('dmdSec', self.STUB_MDWRAP) dmdsec_old.replace_with(dmdsec_new) assert dmdsec_old.get_status() == 'original' assert dmdsec_new.get_status() == 'updated' dmdsec_newer = metsrw.SubSection('dmdSec', self.STUB_MDWRAP) dmdsec_new.replace_with(dmdsec_newer) assert dmdsec_old.get_status() == 'original' assert dmdsec_new.get_status() == 'updated' assert dmdsec_newer.get_status() == 'updated'
def test_replacement_rightsmd(self): """ It should mark the most recent rightsMD 'current'. It should mark all other rightsMDs 'superseded'. """ rightsmd_old = metsrw.SubSection('rightsMD', self.STUB_MDWRAP) assert rightsmd_old.get_status() == 'current' rightsmd_new = metsrw.SubSection('rightsMD', self.STUB_MDWRAP) rightsmd_old.replace_with(rightsmd_new) assert rightsmd_old.get_status() == 'superseded' assert rightsmd_new.get_status() == 'current' rightsmd_newer = metsrw.SubSection('rightsMD', self.STUB_MDWRAP) rightsmd_new.replace_with(rightsmd_newer) assert rightsmd_old.get_status() == 'superseded' assert rightsmd_new.get_status() == 'superseded' assert rightsmd_newer.get_status() == 'current'
def test_collect_mdsec_elements(self): f1 = metsrw.FSEntry('file1.txt', file_uuid=str(uuid.uuid4())) f1.amdsecs.append(metsrw.AMDSec()) f1.dmdsecs.append(metsrw.SubSection('dmdSec', None)) f2 = metsrw.FSEntry('file2.txt', file_uuid=str(uuid.uuid4())) f2.dmdsecs.append(metsrw.SubSection('dmdSec', None)) mw = metsrw.METSDocument() elements = mw._collect_mdsec_elements([f1, f2]) # Check ordering - dmdSec before amdSec assert isinstance(elements, list) assert len(elements) == 3 assert isinstance(elements[0], metsrw.SubSection) assert elements[0].subsection == 'dmdSec' assert isinstance(elements[1], metsrw.SubSection) assert elements[1].subsection == 'dmdSec' assert isinstance(elements[2], metsrw.AMDSec)
def test_subsection_serialize_no_date(self): content = metsrw.MDWrap('<foo/>', None) content.serialize = lambda: etree.Element('dummy_data') subsection = metsrw.SubSection('techMD', content) subsection._id = 'techMD_1' root = subsection.serialize() assert root.tag == '{http://www.loc.gov/METS/}techMD' assert root.attrib['ID'] == 'techMD_1' assert root.attrib['STATUS'] == 'current' assert len(root.attrib) == 2 assert len(root) == 1 assert root[0].tag == 'dummy_data'
def test_allowed_tags(self): """ It should only allow certain subsection tags. """ with pytest.raises(ValueError): metsrw.SubSection('fakeMD', None) metsrw.SubSection('dmdSec', None) metsrw.SubSection('techMD', None) metsrw.SubSection('rightsMD', None) metsrw.SubSection('sourceMD', None) metsrw.SubSection('digiprovMD', None)
def test_replace_with_diff_type(self): """ It should assert if replacing with a different subsection type. """ dmdsec = metsrw.SubSection('dmdSec', self.STUB_MDWRAP) rightsmd = metsrw.SubSection('rightsMD', self.STUB_MDWRAP) with pytest.raises(metsrw.MetsError): dmdsec.replace_with(rightsmd)