def test_stop(self): stdout = MagicMock() mock_is_docker_present = MagicMock(return_value=True) mock_get_running_haproxy = MagicMock(return_value='sandbox-haproxy') mock_docker_rm = MagicMock() args = MagicMock(**{}) with patch('conductr_cli.docker.is_docker_present', mock_is_docker_present), \ patch('conductr_cli.sandbox_proxy.get_running_haproxy', mock_get_running_haproxy), \ patch('conductr_cli.terminal.docker_rm', mock_docker_rm): logging_setup.configure_logging(args, stdout) self.assertTrue(sandbox_proxy.stop_proxy()) mock_get_running_haproxy.assert_called_once_with() mock_docker_rm.assert_called_once_with(['sandbox-haproxy']) expected_output = strip_margin( """||------------------------------------------------| || Stopping HAProxy | ||------------------------------------------------| |HAProxy has been successfully stopped |""") self.assertEqual(expected_output, self.output(stdout))
def test_already_stopped(self): stdout = MagicMock() mock_get_running_haproxy = MagicMock(return_value=None) mock_docker_rm = MagicMock() args = MagicMock(**{}) with patch('conductr_cli.sandbox_proxy.get_running_haproxy', mock_get_running_haproxy), \ patch('conductr_cli.terminal.docker_rm', mock_docker_rm): logging_setup.configure_logging(args, stdout) self.assertTrue(sandbox_proxy.stop_proxy()) mock_get_running_haproxy.assert_called_once_with() mock_docker_rm.assert_not_called() self.assertEqual('', self.output(stdout))
def test_attribute_error(self): stdout = MagicMock() mock_get_running_haproxy = MagicMock( side_effect=AttributeError('test')) mock_docker_rm = MagicMock() args = MagicMock(**{}) with patch('conductr_cli.sandbox_proxy.get_running_haproxy', mock_get_running_haproxy), \ patch('conductr_cli.terminal.docker_rm', mock_docker_rm): logging_setup.configure_logging(args, stdout) self.assertFalse(sandbox_proxy.stop_proxy()) mock_get_running_haproxy.assert_called_once_with() mock_docker_rm.assert_not_called() self.assertEqual('', self.output(stdout))
def test_called_process_error(self): stdout = MagicMock() mock_is_docker_present = MagicMock(return_value=True) mock_get_running_haproxy = MagicMock( side_effect=CalledProcessError(1, 'test')) mock_docker_rm = MagicMock() args = MagicMock(**{}) with patch('conductr_cli.docker.is_docker_present', mock_is_docker_present), \ patch('conductr_cli.sandbox_proxy.get_running_haproxy', mock_get_running_haproxy), \ patch('conductr_cli.terminal.docker_rm', mock_docker_rm): logging_setup.configure_logging(args, stdout) self.assertFalse(sandbox_proxy.stop_proxy()) mock_get_running_haproxy.assert_called_once_with() mock_docker_rm.assert_not_called() self.assertEqual('', self.output(stdout))
def stop(): return sandbox_proxy.stop_proxy()
def stop(args): """`sandbox stop` command""" is_proxy_success = sandbox_proxy.stop_proxy() is_docker_success = sandbox_stop_docker.stop(args) is_jvm_success = sandbox_stop_jvm.stop(args) return is_proxy_success and is_docker_success and is_jvm_success