def test_xlsx_print_info(tmp_path):
    """Test print_info call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.print_info()
    assert retval is None
def test_xlsx_simulate(tmp_path):
    """Test simulate call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.simulate()
    assert retval == TaskOutcome.SIM_SUCCESS
    assert len(os.listdir(str(tmp_path))) == 0
def test_xlsx_execute_missing_column_heading(tmp_path):
    """Test execute call missing column heading."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    section['spread-sheet-file'] = 'tests/data/spread-sheet/missing_column_heading.xlsx'
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_xlsx_execute_embedded_blank_in_goal_name_id(tmp_path):
    """Test execute with embedded blank in goal_name_id."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    section['spread-sheet-file'] = 'tests/data/spread-sheet/embedded_blank_in_goal_name_id.xlsx'
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
def test_xlsx_execute_work_sheet_name_missing(tmp_path):
    """Test execute call work sheet name missing."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section.pop('work-sheet-name')
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_xlsx_execute_spread_sheet_not_found(tmp_path):
    """Test execute call spread sheet not found."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['spread-sheet-file'] = '/foobar'
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_xlsx_execute_missing_profile_title(tmp_path):
    """Test execute call missing profile title."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    del section['profile-title']
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_xlsx_execute_no_overwrite(tmp_path):
    """Test execute call output already exists."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
    section['output-overwrite'] = 'false'
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE
def test_xlsx_execute(tmp_path):
    """Test execute call."""
    config = configparser.ConfigParser()
    config_path = pathlib.Path(CONFIG_PATH)
    config.read(config_path)
    section = config['task.xlsx-to-oscal-profile']
    d_expected = pathlib.Path(section['output-dir'])
    d_produced = tmp_path
    section['output-dir'] = str(tmp_path)
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    tgt.set_timestamp('2021-07-19T14:03:03.000+00:00')
    retval = tgt.execute()
    assert retval == TaskOutcome.SUCCESS
    list_dir = os.listdir(d_produced)
    assert len(list_dir) == 1
    assert d_expected != d_produced
    for fn in list_dir:
        f_expected = d_expected / fn
        f_produced = d_produced / fn
        result = text_files_equal(f_expected, f_produced)
        assert (result)
def test_xlsx_execute_bogus_config(tmp_path):
    """Test execute call bogus config."""
    section = None
    tgt = xlsx_to_oscal_profile.XlsxToOscalProfile(section)
    retval = tgt.execute()
    assert retval == TaskOutcome.FAILURE