def test_execute_single_instance(mocker, molecule_instance): molecule_instance.state.change_state('hosts', {'foo': None}) patched_get_login = mocker.patch('molecule.command.login.Login._get_login') l = login.Login({}, {}, molecule_instance) l.execute() patched_get_login.assert_called_once_with('foo')
def test_execute_raises_when_no_running_hosts(patched_print_error, molecule_instance): l = login.Login({}, {}, molecule_instance) with pytest.raises(SystemExit): l.execute() msg = 'There are no running hosts.' patched_print_error.assert_called_once_with(msg)
def test_execute_more_specific_hostname_match(mocker, molecule_instance): molecule_instance.state.change_state('hosts', {'foo': None, 'fooo': None}) command_args = {'host': 'foo'} patched_get_login = mocker.patch('molecule.command.login.Login._get_login') l = login.Login({}, command_args, molecule_instance) l.execute() patched_get_login.assert_called_once_with('foo')
def test_execute_raises_when_host_unknown(patched_print_error, molecule_instance): molecule_instance.state.change_state('hosts', {'foo': None}) command_args = {'host': 'unknown'} l = login.Login({}, command_args, molecule_instance) with pytest.raises(SystemExit): l.execute() msg = "Unknown host 'unknown'.\n\nAvailable hosts:\nfoo" patched_print_error.assert_called_once_with(msg)
def test_execute_raises_when_no_host_privided_but_multiple_instances_exist( patched_print_error, molecule_instance): molecule_instance.state.change_state('hosts', {'foo': None, 'baz': None}) l = login.Login({}, {}, molecule_instance) with pytest.raises(SystemExit): l.execute() msg = ('There are 2 running hosts. Please specify which with --host.\n' '\nAvailable hosts:\nbaz\nfoo') patched_print_error.assert_called_once_with(msg)
def test_execute_partial_hostname_raises_when_many_match( mocker, patched_print_error, molecule_instance): molecule_instance.state.change_state('hosts', {'foo': None, 'fooo': None}) command_args = {'host': 'fo'} l = login.Login({}, command_args, molecule_instance) with pytest.raises(SystemExit): l.execute() msg = ("There are 2 hosts that match 'fo'. You can only login to one at a " "time.\n\nAvailable hosts:\nfoo\nfooo") patched_print_error.assert_called_once_with(msg)
def _instance(config_instance): config_instance.state.change_state('created', True) return login.Login(config_instance)
def login_instance(molecule_driver_delegated_section_data, config_instance): config_instance.state.change_state('created', True) config_instance.merge_dicts(config_instance.config, molecule_driver_delegated_section_data) return login.Login(config_instance)