4
4
5
5
from . import BaseCMLTest
6
6
7
+ try :
8
+ from unittest .mock import patch
9
+ except ImportError :
10
+ from mock import patch # type: ignore
11
+
7
12
8
13
class CMLStartTests (BaseCMLTest ):
9
14
def test_cml_start (self ):
@@ -22,13 +27,13 @@ def test_cml_start(self):
22
27
def test_cml_start_by_id (self ):
23
28
with self .get_context () as m :
24
29
# 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 )
30
+ self .setup_func ("get" , m , "labs/{}/nodes/{} /check_if_converged" .format (self .get_cml24_id (), self . get_cml24_rtr_2 ()), json = True )
31
+ self .setup_func ("put" , m , "labs/{}/nodes/{} /state/start" .format (self .get_cml24_id (), self . get_cml24_rtr_2 ()), json = None )
32
+ self .setup_func ("get" , m , "labs/{}/nodes/{} /check_if_converged" .format (self .get_cml24_id (), self . get_cml24_rtr_2 ()), json = True )
28
33
self .setup_mocks (m )
29
34
virl = self .get_virl ()
30
35
runner = CliRunner ()
31
- result = runner .invoke (virl , ["start" , "--id" ], "88119b68-9d08-40c4-90f5-6dc533fd0257" )
36
+ result = runner .invoke (virl , ["start" , "--id" ], self . get_cml24_rtr_2 () )
32
37
self .assertEqual (0 , result .exit_code )
33
38
self .assertNotIn ("Node rtr-2 is already active" , result .output )
34
39
@@ -48,19 +53,21 @@ def test_cml_start_already_active_by_id(self):
48
53
self .setup_mocks (m )
49
54
virl = self .get_virl ()
50
55
runner = CliRunner ()
51
- result = runner .invoke (virl , ["start" , "--id" , "88119b68-9d08-40c4-90f5-6dc533fd0256" ])
56
+ result = runner .invoke (virl , ["start" , "--id" , self . get_cml24_rtr_1 () ])
52
57
self .assertEqual (0 , result .exit_code )
53
58
self .assertIn ("Node rtr-1 is already active" , result .output )
54
59
55
- def test_cml_start_missing_args (self ):
60
+ @patch ("virl.cli.stop.commands.call" , autospec = False , return_value = 0 )
61
+ def test_cml_start_missing_args (self , call_mock ):
56
62
with self .get_context () as m :
57
63
# Mock the request to return what we expect from the API.
58
64
self .setup_mocks (m )
59
65
virl = self .get_virl ()
60
66
runner = CliRunner ()
61
67
result = runner .invoke (virl , ["start" ])
62
- self .assertEqual (1 , result .exit_code )
63
- self .assertIn ("Usage: cml start" , result .output )
68
+ self .assertEqual (0 , result .exit_code )
69
+ # The "call" function was called once
70
+ self .assertEqual (1 , len (call_mock .mock_calls ))
64
71
65
72
def test_cml_start_bogus_node (self ):
66
73
with self .get_context () as m :
0 commit comments