|
6 | 6 | from .mocks.github import MockGitHub # noqa |
7 | 7 |
|
8 | 8 | try: |
9 | | - from unittest.mock import patch |
| 9 | + from unittest.mock import Mock, patch |
10 | 10 | except ImportError: |
11 | | - from mock import patch # noqa |
| 11 | + from mock import Mock, patch # noqa |
12 | 12 |
|
13 | 13 |
|
14 | 14 | class TestCMLUp(BaseCMLTest): |
@@ -189,6 +189,49 @@ def test_cml_up_after_use(self): |
189 | 189 | "Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output |
190 | 190 | ) |
191 | 191 |
|
| 192 | + def test_cml_up_after_use_no_start(self): |
| 193 | + super().setUp() |
| 194 | + with self.get_context() as m: |
| 195 | + # Mock the request to return what we expect from the API. |
| 196 | + self.setup_mocks(m) |
| 197 | + virl = self.get_virl() |
| 198 | + runner = CliRunner() |
| 199 | + result = runner.invoke(virl, ["up", "--no-start"]) |
| 200 | + self.assertEqual(0, result.exit_code) |
| 201 | + self.assertIn( |
| 202 | + "Lab {} (ID: {}) is already set as the current lab".format(self.get_test_title(), self.get_test_id()), result.output |
| 203 | + ) |
| 204 | + self.assertNotIn("Starting lab", result.output) |
| 205 | + |
| 206 | + @patch("virl.cli.up.commands.start_lab", autospec=False) |
| 207 | + @patch("virl.cli.up.commands.safe_join_existing_lab", autospec=False) |
| 208 | + @patch("virl.cli.up.commands.get_current_lab", autospec=False) |
| 209 | + @patch("virl.cli.up.commands.get_cml_client", autospec=False) |
| 210 | + @patch("virl.cli.up.commands.VIRLServer", autospec=False) |
| 211 | + def test_cml_up_after_use_starts_inactive_current_lab( |
| 212 | + self, |
| 213 | + _server_mock, |
| 214 | + get_cml_client_mock, |
| 215 | + get_current_lab_mock, |
| 216 | + safe_join_existing_lab_mock, |
| 217 | + start_lab_mock, |
| 218 | + ): |
| 219 | + get_cml_client_mock.return_value = object() |
| 220 | + get_current_lab_mock.return_value = "current-lab-id" |
| 221 | + inactive_lab = Mock() |
| 222 | + inactive_lab.id = "current-lab-id" |
| 223 | + inactive_lab.title = "Current Lab" |
| 224 | + inactive_lab.is_active.return_value = False |
| 225 | + safe_join_existing_lab_mock.return_value = inactive_lab |
| 226 | + |
| 227 | + virl = self.get_virl() |
| 228 | + runner = CliRunner() |
| 229 | + result = runner.invoke(virl, ["up"]) |
| 230 | + |
| 231 | + self.assertEqual(0, result.exit_code) |
| 232 | + self.assertIn("Lab Current Lab (ID: current-lab-id) is already set as the current lab", result.output) |
| 233 | + start_lab_mock.assert_called_once_with(inactive_lab, False) |
| 234 | + |
192 | 235 | def test_cml_up_running_lab(self): |
193 | 236 | with self.get_context() as m: |
194 | 237 | # Mock the request to return what we expect from the API. |
|
0 commit comments