Skip to content

Commit 2c87176

Browse files
committed
Add tests for the new --id argument.
1 parent b9196d7 commit 2c87176

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

tests/v2/start.py

+33
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ def test_cml_start(self):
1919
self.assertEqual(0, result.exit_code)
2020
self.assertNotIn("Node rtr-2 is already active", result.output)
2121

22+
def test_cml_start_by_id(self):
23+
with self.get_context() as m:
24+
# Mock the request to return what we expect from the API.
25+
self.setup_func("get", m, "labs/{}/nodes/n2/check_if_converged".format(self.get_test_id()), json=True)
26+
self.setup_func("put", m, "labs/{}/nodes/n2/state/start".format(self.get_test_id()), json=None)
27+
self.setup_func("get", m, "labs/{}/nodes/n2/check_if_converged".format(self.get_test_id()), json=True)
28+
self.setup_mocks(m)
29+
virl = self.get_virl()
30+
runner = CliRunner()
31+
result = runner.invoke(virl, ["start", "--id"], "88119b68-9d08-40c4-90f5-6dc533fd0257")
32+
self.assertEqual(0, result.exit_code)
33+
self.assertNotIn("Node rtr-2 is already active", result.output)
34+
2235
def test_cml_start_already_active(self):
2336
with self.get_context() as m:
2437
# Mock the request to return what we expect from the API.
@@ -29,6 +42,26 @@ def test_cml_start_already_active(self):
2942
self.assertEqual(0, result.exit_code)
3043
self.assertIn("Node rtr-1 is already active", result.output)
3144

45+
def test_cml_start_already_active_by_id(self):
46+
with self.get_context() as m:
47+
# Mock the request to return what we expect from the API.
48+
self.setup_mocks(m)
49+
virl = self.get_virl()
50+
runner = CliRunner()
51+
result = runner.invoke(virl, ["start", "--id", "88119b68-9d08-40c4-90f5-6dc533fd0256"])
52+
self.assertEqual(0, result.exit_code)
53+
self.assertIn("Node rtr-1 is already active", result.output)
54+
55+
def test_cml_start_missing_args(self):
56+
with self.get_context() as m:
57+
# Mock the request to return what we expect from the API.
58+
self.setup_mocks(m)
59+
virl = self.get_virl()
60+
runner = CliRunner()
61+
result = runner.invoke(virl, ["start"])
62+
self.assertEqual(1, result.exit_code)
63+
self.assertIn("Usage: cml start", result.output)
64+
3265
def test_cml_start_bogus_node(self):
3366
with self.get_context() as m:
3467
# Mock the request to return what we expect from the API.

tests/v2/stop.py

+31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ def test_cml_stop(self):
1717
self.assertEqual(0, result.exit_code)
1818
self.assertNotIn("Node rtr-1 is already stopped", result.output)
1919

20+
def test_cml_sto_by_id(self):
21+
with self.get_context() as m:
22+
self.setup_func("get", m, "labs/{}/nodes/n1/check_if_converged".format(self.get_test_id()), json=True)
23+
self.setup_func("put", m, "labs/{}/nodes/n1/state/stop".format(self.get_test_id()), json=None)
24+
self.setup_mocks(m)
25+
virl = self.get_virl()
26+
runner = CliRunner()
27+
result = runner.invoke(virl, ["stop", "--id", "88119b68-9d08-40c4-90f5-6dc533fd0256"])
28+
self.assertEqual(0, result.exit_code)
29+
self.assertNotIn("Node rtr-1 is already stopped", result.output)
30+
2031
def test_cml_stop_already_stopped(self):
2132
with self.get_context() as m:
2233
# Mock the request to return what we expect from the API.
@@ -27,6 +38,26 @@ def test_cml_stop_already_stopped(self):
2738
self.assertEqual(0, result.exit_code)
2839
self.assertIn("Node rtr-2 is already stopped", result.output)
2940

41+
def test_cml_stop_already_stopped_by_id(self):
42+
with self.get_context() as m:
43+
# Mock the request to return what we expect from the API.
44+
self.setup_mocks(m)
45+
virl = self.get_virl()
46+
runner = CliRunner()
47+
result = runner.invoke(virl, ["stop", "--id", "88119b68-9d08-40c4-90f5-6dc533fd0257"])
48+
self.assertEqual(0, result.exit_code)
49+
self.assertIn("Node rtr-2 is already stopped", result.output)
50+
51+
def test_cml_stop_missing_args(self):
52+
with self.get_context() as m:
53+
# Mock the request to return what we expect from the API.
54+
self.setup_mocks(m)
55+
virl = self.get_virl()
56+
runner = CliRunner()
57+
result = runner.invoke(virl, ["stop"])
58+
self.assertEqual(1, result.exit_code)
59+
self.assertIn("Usage: cml stop", result.output)
60+
3061
def test_cml_stop_bogus_node(self):
3162
with self.get_context() as m:
3263
# Mock the request to return what we expect from the API.

0 commit comments

Comments
 (0)