コード例 #1
0
 def test_no_execute(self):
     device = Device('key')
     with patch.object(logger, 'warning') as warning_mock:
         device.execute()
         warning_mock.assert_called_once()
     with patch.object(Device, 'send_confirmation') as send_confirmation_mock:
         device.execute()
         send_confirmation_mock.assert_called_once()
コード例 #2
0
 def test_send_confirmation(self):
     device = Device('key', {'confirmation': 'tg'}, {'confirmations': {
         'tg': {'service': 'disabled'},
     }})
     with patch.object(DisabledConfirmation, 'send') as send_mock:
         device.execute()
         send_mock.assert_called_once()
コード例 #3
0
 def test_execute_400(self):
     self.session_mock.post(self.url, status_code=400)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with mock_patch.object(logger, 'warning') as warning_mock:
         execute_url.execute()
         warning_mock.assert_called_once()
コード例 #4
0
 def test_execute_exception(self):
     self.session_mock.post(self.url, exc=requests.exceptions.ConnectTimeout)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post', body='foo',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with mock_patch.object(logger, 'warning') as warning_mock:
         execute_url.execute()
         warning_mock.assert_called_once()
コード例 #5
0
 def test_execute_error(self):
     device = Device(
         'key', {
             'cmd': "command",
             'user': "******",
             'cwd': "/dir",
             'name': "Command Name",
         }, {'confirmations': {'tg': {'service': 'disabled'}}}
     )
     with patch.object(Device, 'send_confirmation') as send_confirmation_mock:
         self.execute_mock.stop()
         execute_mock = patch.object(ExecuteCmd, 'execute', side_effect=Exception())
         execute_mock.start()
         with self.assertRaises(Exception):
             device.execute()
         send_confirmation_mock.assert_called_once()
         execute_mock.stop()
         self.execute_mock.start()
コード例 #6
0
    def test_check_execution_success(self, popen_mock):
        popen_mock.return_value = Mock()
        popen_mock_obj = popen_mock.return_value

        popen_mock_obj.communicate.return_value = ("OUT", "ERR")
        popen_mock_obj.returncode = 1
        with mock_patch.object(logger, 'error') as logger_error:
            check_execution_success('ls', '/tmp')
            logger_error.assert_called_once()
コード例 #7
0
 def test_execute_cmd_start(self):
     with mock_patch.object(Thread, 'start') as start_mock:
         execute_cmd('ls', '/tmp')
         start_mock.assert_called_once()