def test_import_description_invalid_namespace(testpath):
    """ test case for invalid namespace in XML file """
    dmdsec_location = 'tests/data/import_description/dc_invalid_ns.xml'
    dmdsec_target = 'tests/data/structured/'

    with pytest.raises(TypeError):
        main([dmdsec_location,  '--workspace', dmdsec_target, '--workspace', testpath])
def test_import_description_file_not_found(testpath):
    """ Test case for not existing xml-file."""
    dmdsec_location = 'tests/data/import_description/metadata/dc_description_not_found.xml'
    dmdsec_target = 'tests/data/structured/'

    with pytest.raises(IOError):
        main([dmdsec_location,  '--workspace', dmdsec_target, '--workspace', testpath])
def test_import_description_no_xml(testpath):
    """ test case for invalid XML file """
    dmdsec_location = 'tests/data/import_description/plain_text.xml'
    dmdsec_target = 'tests/data/structured/'

    with pytest.raises(ET.XMLSyntaxError):
        main([dmdsec_location,  '--workspace', dmdsec_target, '--workspace', testpath])
def test_import_description_valid_file(testpath):
    """ Test case for single valid xml-file"""
    dmdsec_location = 'tests/data/import_description/metadata/dc_description.xml'
    dmdsec_target = 'tests/data/structured/'

    url_location = quote_plus(dmdsec_target, safe='') + '-dmdsec.xml'

    main([dmdsec_location, '--dmdsec_target', dmdsec_target, '--workspace',
        testpath, '--desc_root', 'remove'])

    output_file = os.path.join(testpath, url_location)
    tree = ET.parse(output_file)
    root = tree.getroot()
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])