diff --git a/tests/v2/up.py b/tests/v2/up.py index 221d677..826950b 100644 --- a/tests/v2/up.py +++ b/tests/v2/up.py @@ -6,9 +6,9 @@ from .mocks.github import MockGitHub # noqa try: - from unittest.mock import patch + from unittest.mock import Mock, patch except ImportError: - from mock import patch # noqa + from mock import Mock, patch # noqa class TestCMLUp(BaseCMLTest): @@ -189,6 +189,49 @@ def test_cml_up_after_use(self): "Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output ) + def test_cml_up_after_use_no_start(self): + super().setUp() + with self.get_context() as m: + # Mock the request to return what we expect from the API. + self.setup_mocks(m) + virl = self.get_virl() + runner = CliRunner() + result = runner.invoke(virl, ["up", "--no-start"]) + self.assertEqual(0, result.exit_code) + self.assertIn( + "Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output + ) + self.assertNotIn("Starting lab", result.output) + + @patch("virl.cli.up.commands.start_lab", autospec=False) + @patch("virl.cli.up.commands.safe_join_existing_lab", autospec=False) + @patch("virl.cli.up.commands.get_current_lab", autospec=False) + @patch("virl.cli.up.commands.get_cml_client", autospec=False) + @patch("virl.cli.up.commands.VIRLServer", autospec=False) + def test_cml_up_after_use_starts_inactive_current_lab( + self, + _server_mock, + get_cml_client_mock, + get_current_lab_mock, + safe_join_existing_lab_mock, + start_lab_mock, + ): + get_cml_client_mock.return_value = object() + get_current_lab_mock.return_value = "current-lab-id" + inactive_lab = Mock() + inactive_lab.id = "current-lab-id" + inactive_lab.title = "Current Lab" + inactive_lab.is_active.return_value = False + safe_join_existing_lab_mock.return_value = inactive_lab + + virl = self.get_virl() + runner = CliRunner() + result = runner.invoke(virl, ["up"]) + + self.assertEqual(0, result.exit_code) + self.assertIn("Lab Current Lab (ID: current-lab-id) is already set as the current lab", result.output) + start_lab_mock.assert_called_once_with(inactive_lab, False) + def test_cml_up_running_lab(self): with self.get_context() as m: # Mock the request to return what we expect from the API. diff --git a/virl/cli/up/commands.py b/virl/cli/up/commands.py index 85dbaeb..40afee8 100644 --- a/virl/cli/up/commands.py +++ b/virl/cli/up/commands.py @@ -199,7 +199,7 @@ def up(repo=None, provision=False, start=True, **kwargs): else: click.secho("Could not find a lab to start. Maybe try -f", fg="red") exit(1) - elif clab: + else: click.secho("Lab {} (ID: {}) is already set as the current lab".format(clab.title, current_lab)) if not clab.is_active() and start: start_lab(clab, provision)