def test_dispatch_returns_error_if_bad_action(self):
        manager = ClaraManager(clara)
        msg = 'clara:launch:python:dpe'

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(res, ['ERROR', 'Unsupported action: launch'])
    def test_dispatch_returns_error_if_bad_request(self):
        manager = ClaraManager(clara)
        msg = 'clara:start'

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(res, ['ERROR', 'Bad request: "clara:start"'])
    def test_dispatch_returns_error_if_empty_request(self):
        manager = ClaraManager(clara)
        msg = ''

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(res, ['ERROR', 'Empty request'])
    def test_dispatch_returns_error_if_standard_request_failed(self, mock_sr):
        manager = ClaraManager(clara)
        msg = 'clara:request:java:list-dpes'
        mock_sr.return_value = ['OUT1', 'OUT2'], ['ERR'], 1

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(res, ['ERROR', 'OUT1', 'OUT2', 'ERR'])
    def test_dispatch_returns_error_if_request_failed(self, mock_sc):
        manager = ClaraManager(clara)
        msg = 'clara:start:python:monitor'
        mock_sc.side_effect = ClaraManagerError('Bad instance: monitor')

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(res, ['ERROR', 'Bad instance: monitor'])
    def test_dispatch_successful_stop_request(self, mock_sc):
        manager = ClaraManager(clara)
        msg = 'clara:stop:python:dpe'

        res = manager.dispatch_request(msg)

        mock_sc.assert_called_once_with('python', 'dpe')
        self.assertSequenceEqual(res, ['SUCCESS', ''])
    def test_dispatch_returns_error_on_request_error(self, mock_sc):
        manager = ClaraManager(clara)
        msg = 'clara:start:python:dpe'
        mock_sc.side_effect = OSError('Popen error')

        res = manager.dispatch_request(msg)

        self.assertSequenceEqual(
            res, ['ERROR', 'Unexpected exception: Popen error'])
    def test_dispatch_sucessful_stop_all_request(self, mock_sa):
        manager = ClaraManager(clara)
        msg = 'clara:stop:all:all'

        res = manager.dispatch_request(msg)

        mock_sa.assert_called_once_with(manager)
        self.assertSequenceEqual(res, ['SUCCESS', ''])
        self.assertTrue(not manager.instances)
    def test_dispatch_successful_standard_request(self, mock_sr):
        manager = ClaraManager(clara)
        msg = 'clara:request:java:list-dpes'
        mock_sr.return_value = ['OK'], [''], 0

        res = manager.dispatch_request(msg)

        mock_sr.assert_called_once_with('java', 'list-dpes')
        self.assertSequenceEqual(res, ['SUCCESS', 'OK'])