def test_main_with_boot_drives(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, mock_os_match, cli_args): sw_match = '4.21.5F' item_match = namedtuple('item_match', ['hw_match', 'data']) hw_match = item_match(hw_match='default', data={ 'image': 'Eos.swi', 'exact_match': '4.21.5F', 'boot_drives': ['drive1', 'usb1', 'flash'], 'finally': 'finally' }) mock_hw_match.return_value = hw_match mock_os_match.return_value = sw_match mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': True, 'image_name': sw_match, 'boot_drives': ['drive1', 'usb1', 'flash'], 'finally': hw_match.data['finally'] })
def test_main(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, mock_os_match, cli_args): sw_match = '1.0.0' mock_os_match.return_value = sw_match mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({'ok': True, 'image': sw_match})
def test_main_hwnomatch_error(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, cli_args): errmsg = 'no matching hw_model value' mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': False, 'error_type': 'hw_match', 'error_message': errmsg })
def test_main_argparse_error(mock_cli_parse, mock_exit_results, cli_args): errmsg = 'test parse error' mock_cli_parse.side_effect = aztp_os_selector.ArgumentParser.ParserError( errmsg) with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': False, 'error_type': 'args', 'error_message': errmsg })
def test_main_hwmultimatch_error(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, cli_args): errmsg = 'matches multiple os-selector groups' mock_hw_match.side_effect = aztp_os_selector.HwMultiMatchError(errmsg) mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': False, 'error_type': 'hw_match', 'error_message': errmsg })
def test_main_cfgerror(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, mock_os_match, cli_args): errmsg = 'Expecting one of' mock_os_match.side_effect = aztp_os_selector.CfgError(errmsg) mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': False, 'error_type': 'cfg_error', 'error_message': errmsg })
def test_main_json_error(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, cli_args): mock_json_load.side_effect = ValueError() mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': False, 'error_type': 'args', 'error_message': 'JSON argument formatted incorrectly.' })
def test_main(mock_cli_parse, mock_load_cfg, mock_json_load, mock_exit_results, mock_hw_match, mock_os_match, cli_args): sw_match = '1.0.0' item_match = namedtuple('item_match', ['hw_match', 'data']) hw_match = item_match(hw_match='default', data={ 'image': '1.0.1b', 'exact_match': '4.16.6M', 'finally': 'finally' }) mock_hw_match.return_value = hw_match mock_os_match.return_value = sw_match mock_cli_parse.return_value = cli_args with pytest.raises(SystemExit): aztp_os_selector.main() mock_exit_results.assert_called_with({ 'ok': True, 'image_name': sw_match, 'finally': hw_match.data['finally'] })