@@ -16,11 +16,60 @@ def setUp(self):
1616
1717 @mock .patch ('acos_client.Client' )
1818 def test_specified_target_without_one_target (self , mock_client ):
19- # set mock of action
20- mock_action = mock . Mock ()
21- mock_action . slb . server . get . return_value = 'test-result'
19+ def side_effect ( * args , ** extra_params ):
20+ # This checks authentication information that is passed to acos.Client
21+ self . assertEqual ( args , ( 'appliance_acos_v2.1' , 'v2.1' , 'admin' , 'hoge' ))
2222
23- mock_client .return_value = mock_action
23+ # This checks default extra params are set
24+ self .assertEqual (extra_params , {
25+ 'max_retries' : 3 , 'port' : 443 , 'protocol' : 'https' , 'timeout' : 5
26+ })
27+
28+ # set mock of action
29+ mock_action = mock .Mock ()
30+ mock_action .slb .server .get .return_value = 'test-result'
31+
32+ return mock_action
33+
34+ mock_client .side_effect = side_effect
35+
36+ # execute action
37+ params = {
38+ 'object_path' : 'slb.server' ,
39+ 'action' : 'get' ,
40+ 'name' : 'hoge' ,
41+ 'one_target' : False ,
42+ 'specified_target' : {
43+ 'target' : 'appliance_acos_v2.1' ,
44+ 'userid' : 'admin' ,
45+ 'passwd' : 'hoge' ,
46+ 'api_version' : 'v2.1' ,
47+ }
48+ }
49+ result = self .action .run (** params )
50+
51+ self .assertTrue (result [0 ])
52+ self .assertEqual (result [1 ], 'test-result' )
53+ self .assertEqual (len (self ._log_handler .messages ['error' ]), 0 )
54+
55+ @mock .patch ('acos_client.Client' )
56+ def test_specified_target_with_extra_params (self , mock_client ):
57+ def side_effect (* args , ** extra_params ):
58+ # This checks authentication information that is passed to acos.Client
59+ self .assertEqual (args , ('appliance_acos_v2.1' , 'v2.1' , 'admin' , 'hoge' ))
60+
61+ # This checks extra params are set as user specified
62+ self .assertEqual (extra_params , {
63+ 'max_retries' : 10 , 'port' : 80 , 'protocol' : 'http' , 'timeout' : 10
64+ })
65+
66+ # set mock of action
67+ mock_action = mock .Mock ()
68+ mock_action .slb .server .get .return_value = 'test-result'
69+
70+ return mock_action
71+
72+ mock_client .side_effect = side_effect
2473
2574 # execute action
2675 params = {
@@ -33,6 +82,10 @@ def test_specified_target_without_one_target(self, mock_client):
3382 'userid' : 'admin' ,
3483 'passwd' : 'hoge' ,
3584 'api_version' : 'v2.1' ,
85+ 'max_retries' : 10 ,
86+ 'port' : 80 ,
87+ 'protocol' : 'http' ,
88+ 'timeout' : 10 ,
3689 }
3790 }
3891 result = self .action .run (** params )
0 commit comments