@@ -154,59 +154,80 @@ def test_command_unsetg_unknown_option(self, mock_print_error):
154154
155155 @mock .patch ('routersploit.utils.print_status' )
156156 def test_command_run (self , mock_print_status ):
157- with mock .patch .object (self .interpreter .current_module ,
158- 'run' ) as mock_run :
159- self .interpreter .command_run ()
160- mock_run .assert_called_once_with ()
161- mock_print_status .assert_called_once_with ('Running module...' )
157+ mock_run = mock .Mock ()
158+ mock_validate_setup = mock .Mock ()
159+ self .interpreter .current_module .run = mock_run
160+ self .interpreter .current_module .validate_setup = mock_validate_setup
161+
162+ self .interpreter .command_run ()
163+ mock_validate_setup .assert_called_once ()
164+ mock_run .assert_called_once_with ()
165+ mock_print_status .assert_called_once_with ('Running module...' )
162166
163167 @mock .patch ('routersploit.utils.print_success' )
164168 def test_command_check_target_vulnerable (self , mock_print_success ):
165- with mock .patch .object (self .interpreter .current_module ,
166- 'check' ) as mock_check :
167- mock_check .return_value = True
168- self .interpreter .command_check ()
169- mock_check .assert_called_once_with ()
170- mock_print_success .assert_called_once_with ('Target is vulnerable' )
169+ mock_check = mock .Mock ()
170+ mock_validate_setup = mock .Mock ()
171+ self .interpreter .current_module .check = mock_check
172+ self .interpreter .current_module .validate_setup = mock_validate_setup
173+ mock_check .return_value = True
174+
175+ self .interpreter .command_check ()
176+ mock_validate_setup .assert_called_once ()
177+ mock_check .assert_called_once_with ()
178+ mock_print_success .assert_called_once_with ('Target is vulnerable' )
171179
172180 @mock .patch ('routersploit.utils.print_error' )
173181 def test_command_check_target_not_vulnerable (self , print_error ):
174- with mock .patch .object (self .interpreter .current_module ,
175- 'check' ) as mock_check :
176- mock_check .return_value = False
177- self .interpreter .command_check ()
178- mock_check .assert_called_once_with ()
179- print_error .assert_called_once_with ('Target is not vulnerable' )
182+ mock_check = mock .Mock ()
183+ mock_validate_setup = mock .Mock ()
184+ self .interpreter .current_module .check = mock_check
185+ self .interpreter .current_module .validate_setup = mock_validate_setup
186+ mock_check .return_value = False
187+
188+ self .interpreter .command_check ()
189+ mock_validate_setup .assert_called_once ()
190+ mock_check .assert_called_once_with ()
191+ print_error .assert_called_once_with ('Target is not vulnerable' )
180192
181193 @mock .patch ('routersploit.utils.print_status' )
182194 def test_command_check_target_could_not_be_verified_1 (self , print_status ):
183- with mock .patch .object (self .interpreter .current_module ,
184- 'check' ) as mock_check :
185- mock_check .return_value = "something"
186- self .interpreter .command_check ()
187- mock_check .assert_called_once_with ()
188- print_status .assert_called_once_with (
189- 'Target could not be verified' )
195+ mock_check = mock .Mock ()
196+ mock_validate_setup = mock .Mock ()
197+ self .interpreter .current_module .check = mock_check
198+ self .interpreter .current_module .validate_setup = mock_validate_setup
199+ mock_check .return_value = "something"
200+
201+ self .interpreter .command_check ()
202+ mock_validate_setup .assert_called_once ()
203+ mock_check .assert_called_once_with ()
204+ print_status .assert_called_once_with ('Target could not be verified' )
190205
191206 @mock .patch ('routersploit.utils.print_status' )
192207 def test_command_check_target_could_not_be_verified_2 (self , print_status ):
193- with mock .patch .object (self .interpreter .current_module ,
194- 'check' ) as mock_check :
195- mock_check .return_value = None
196- self .interpreter .command_check ()
197- mock_check .assert_called_once_with ()
198- print_status .assert_called_once_with (
199- 'Target could not be verified' )
208+ mock_check = mock .Mock ()
209+ mock_validate_setup = mock .Mock ()
210+ self .interpreter .current_module .check = mock_check
211+ self .interpreter .current_module .validate_setup = mock_validate_setup
212+ mock_check .return_value = None
213+
214+ self .interpreter .command_check ()
215+ mock_validate_setup .assert_called_once ()
216+ mock_check .assert_called_once_with ()
217+ print_status .assert_called_once_with ('Target could not be verified' )
200218
201219 @mock .patch ('routersploit.utils.print_error' )
202220 def test_command_check_not_supported_by_module (self , print_error ):
203- with mock .patch .object (self .interpreter .current_module ,
204- 'check' ) as mock_check :
205- exception = NotImplementedError ("Not available" )
206- mock_check .side_effect = exception
207- self .interpreter .command_check ()
208- mock_check .assert_called_once_with ()
209- print_error .assert_called_once_with (exception )
221+ mock_check = mock .Mock ()
222+ mock_validate_setup = mock .Mock ()
223+ self .interpreter .current_module .check = mock_check
224+ self .interpreter .current_module .validate_setup = mock_validate_setup
225+ exception = NotImplementedError ("Not available" )
226+ mock_check .side_effect = exception
227+
228+ self .interpreter .command_check ()
229+ mock_check .assert_called_once_with ()
230+ print_error .assert_called_once_with (exception )
210231
211232 @mock .patch ('sys.exc_info' )
212233 @mock .patch ('traceback.format_exc' )
0 commit comments