def step_impl(context): mets = utils.get_mets_from_scenario(context) dublincore_el = mets.find( './/mets:dmdSec/mets:mdWrap/mets:xmlData/dcterms:dublincore', context.am_user.mets.mets_nsmap) assert dublincore_el for attr in context.am_user.browser.metadata_attrs: dc_el = dublincore_el.find('dc:{}'.format(attr), context.am_user.mets.mets_nsmap) assert dc_el is not None assert dc_el.text == context.am_user.browser.dummy_val
def step_impl(context, count, event_type): mets = utils.get_mets_from_scenario(context) events = [] for premis_evt_el in mets.findall(".//premis:event", context.am_user.mets.mets_nsmap): premis_evt_type_el = premis_evt_el.find( "premis:eventType", context.am_user.mets.mets_nsmap) if premis_evt_type_el.text == event_type: events.append(premis_evt_el) utils.assert_premis_event(event_type, premis_evt_el, context) assert len(events) == int(count)
def step_impl(context, conj_quant): """``conj_quant`` is 'but no' or 'and a', a conjunction followed by a quantifier, of course. """ mets = utils.get_mets_from_scenario(context, api=True) mets_hdr_els = mets.findall(".//mets:metsHdr", context.am_user.mets.mets_nsmap) assert len(mets_hdr_els) == 1 mets_hdr_el = mets_hdr_els[0] assert mets_hdr_el.get("CREATEDATE") if conj_quant == "but no": assert mets_hdr_el.get("LASTMODDATE") is None else: assert mets_hdr_el.get("LASTMODDATE") is not None, ( "<mets:metsHdr>" " element is lacking a LASTMODDATE attribute:" " {}".format(mets_hdr_el.attrib))
def step_impl(context, conj_quant): """``conj_quant`` is 'but no' or 'and a', a conjunction followed by a quantifier, of course. """ mets = utils.get_mets_from_scenario(context) mets_hdr_els = mets.findall('.//mets:metsHdr', context.am_user.mets.mets_nsmap) assert len(mets_hdr_els) == 1 mets_hdr_el = mets_hdr_els[0] assert mets_hdr_el.get('CREATEDATE') if conj_quant == 'but no': assert mets_hdr_el.get('LASTMODDATE') is None else: assert mets_hdr_el.get('LASTMODDATE') is not None, ( '<mets:metsHdr>' ' element is lacking a LASTMODDATE attribute:' ' {}'.format(mets_hdr_el.attrib))
def step_impl(context, count, event_type, properties): mets = utils.get_mets_from_scenario(context) events = [] properties = json.loads(properties) for premis_evt_el in mets.findall('.//premis:event', context.am_user.mets.mets_nsmap): premis_evt_type_el = premis_evt_el.find( 'premis:eventType', context.am_user.mets.mets_nsmap) if premis_evt_type_el.text == event_type: events.append(premis_evt_el) utils.assert_premis_event(event_type, premis_evt_el, context) utils.assert_premis_properties(premis_evt_el, context, properties) assert len(events) == int(count), ( 'We expected to find {count} events of type {event_type} matching' ' properties `{properties}` but in fact we only found' ' {events_count}.'.format(count=count, event_type=event_type, properties=str(properties), events_count=len(events)))
def step_impl(context): """Asserts that the <mets:structMap> element of the AIP METS file correctly encodes the directory structure of the transfer that was recorded in an earlier step under the following attributes:: context.scenario.remote_dir_subfolders context.scenario.remote_dir_files context.scenario.remote_dir_empty_subfolders NOTE: empty directories in the transfer are not indicated in the resulting AIP METS. """ context.scenario.mets = mets = utils.get_mets_from_scenario(context, api=True) ns = context.am_user.mets.mets_nsmap for type_, xpath in ( ("physical", './/mets:structMap[@TYPE="physical"]'), ("logical", './/mets:structMap[@LABEL="Normative Directory Structure"]'), ): struct_map_el = mets.find(xpath, ns) assert ( struct_map_el is not None ), "We expected to find a {}-type structMap but did not".format(type_) subpaths = utils.get_subpaths_from_struct_map(struct_map_el, ns) subpaths = [ p.replace("/objects", "", 1) for p in filter(None, utils.remove_common_prefix(subpaths)) ] for dirpath in context.scenario.remote_dir_subfolders: if (type_ == "physical") and ( dirpath in context.scenario.remote_dir_empty_subfolders): continue assert dirpath in subpaths, ( "Expected directory path\n{}\nis not in METS structmap" " paths\n{}".format(dirpath, pprint.pformat(subpaths))) if type == "physical": for filepath in context.scenario.remote_dir_files: if os.path.basename(filepath) == ".gitignore": continue assert filepath in subpaths, ( "Expected file path\n{}\nis not in METS structmap" " paths\n{}".format(filepath, pprint.pformat(subpaths)))
def step_impl(context, quant): mets = utils.get_mets_from_scenario(context, api=True) mets_dmd_sec_els = mets.findall(".//mets:dmdSec", context.am_user.mets.mets_nsmap) try: quant = { "no": 0, "zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9, }[quant] except KeyError: raise utils.ArchivematicaStepsError( "Unable to recognize the quantifier {} when checking for dmdSec" " elements in the METS file".format(quant)) else: assert len(mets_dmd_sec_els) == quant
def step_impl(context, quant): mets = utils.get_mets_from_scenario(context) mets_dmd_sec_els = mets.findall('.//mets:dmdSec', context.am_user.mets.mets_nsmap) try: quant = { 'no': 0, 'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, }[quant] except KeyError: raise utils.ArchivematicaStepsError( 'Unable to recognize the quantifier {} when checking for dmdSec' ' elements in the METS file'.format(quant)) else: assert len(mets_dmd_sec_els) == quant
def step_impl(context): accession_no = getattr(context.scenario, 'accession_no', None) mets = context.scenario.mets = utils.get_mets_from_scenario(context) context.am_user.mets.validate_mets_for_pids(mets, accession_no=accession_no)