def test_file_and_dir(testpath): import_object.main(['--workspace', testpath, 'tests/data/file_and_dir']) return_code = compile_structmap.main(['--workspace', testpath]) output_structmap = os.path.join(testpath, 'structmap.xml') sm_tree = ET.parse(output_structmap) sm_root = sm_tree.getroot() elementlist = sm_root.xpath( '/mets:mets/mets:structMap/mets:div/mets:div/mets:div/mets:div/*', namespaces=NAMESPACES) assert elementlist[0].tag == '{%s}fptr' % NAMESPACES['mets'] assert elementlist[1].tag == '{%s}div' % NAMESPACES['mets'] assert return_code == 0
def create_test_data(workspace): # create descriptive metadata dmdsec_location = 'tests/data/import_description/metadata/dc_description.xml' dmdsec_target = 'tests/data/structured/Software files' main([dmdsec_location, '--dmdsec_target', dmdsec_target, '--workspace', workspace, '--desc_root', 'remove']) # create provenance metadata premis_event.main(['creation', '2016-10-13T12:30:55', '--event_target', 'tests/data/structured', '--event_detail', 'Testing', '--event_outcome', 'success', '--event_outcome_detail', 'Outcome detail', '--workspace', workspace, '--agent_name', 'Demo Application', '--agent_type', 'software']) #create technical metadata import_object.main(['--workspace', workspace, 'tests/data/structured/Software files/koodi.java']) #create structural metadata compile_structmap.main(['--workspace', workspace])
def test_import_object_ok(input_file, testpath): arguments = ['--workspace', testpath, input_file] return_code = import_object.main(arguments) output = os.path.join(testpath, encode_path(input_file, suffix='-techmd.xml')) tree = ET.parse(output) root = tree.getroot() assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD', namespaces=NAMESPACES)) == 1 assert return_code == 0
def test_import_object_skip_inspection_nodate_ok(input_file, testpath): arguments = ['--workspace', testpath, input_file, '--skip_inspection', '--format_name', 'image/dpx', '--format_version', '1.0', '--digest_algorithm', 'MD5', '--message_digest', '1qw87geiewgwe9'] return_code = import_object.main(arguments) output = os.path.join(testpath, encode_path(input_file, suffix='-techmd.xml')) tree = ET.parse(output) root = tree.getroot() assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD', namespaces=NAMESPACES)) == 1 assert return_code == 0
def test_import_object_validate_pdf_ok(input_file, testpath): arguments = ['--workspace', testpath, 'tests/data/test_import.pdf'] return_code = import_object.main(arguments) output = os.path.join(testpath, encode_path(input_file, suffix='-techmd.xml')) tree = ET.parse(output) root = tree.getroot() assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD', namespaces=NAMESPACES)) == 1 assert root.xpath('//premis:formatName/text()', namespaces=NAMESPACES)[0] == 'application/pdf' assert root.xpath('//premis:formatVersion/text()', namespaces=NAMESPACES)[0] == '1.4' assert return_code == 0
def test_import_object_structured_ok(testpath): workspace = os.path.abspath(testpath) do = os.path.abspath(os.path.join(os.curdir, 'tests/data/structured')) test_file = "" for element in iterate_files(do): arguments = ['--workspace', workspace, os.path.relpath(element, os.curdir)] return_code = import_object.main(arguments) test_file = os.path.relpath(element, os.curdir) output = os.path.join(testpath, encode_path(test_file, suffix='-techmd.xml')) tree = ET.parse(output) root = tree.getroot() assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD', namespaces=NAMESPACES)) == 1 assert return_code == 0
def test_import_object_fail(input_file): with pytest.raises(IOError): arguments = [input_file] import_object.main(arguments)
def create_test_data(workspace): # create technical metadata import_object.main([ '--workspace', workspace, 'tests/data/structured/Software files/koodi.java' ])