Exemplo n.º 1
0
    def test_command_post_process(self):
        cp = CompletedProcess(success=True,
                              stdout='{"output": "this is a message"}',
                              stderr='',
                              rc=0,
                              start_time=datetime(2019, 4, 1))
        self.mock_implementation.execute.return_value = cp
        c = Command(implementation=self.mock_implementation,
                    var_context=self.mock_context,
                    undo_on_error=False,
                    post_process=
                    "import json\nvc.set('response', json.loads(cp.stdout))",
                    id_=1)

        c.invoke()
        self.mock_context.set.assert_called_once_with(
            'response', {"output": "this is a message"})

        c = Command(implementation=self.mock_implementation,
                    var_context=self.mock_context,
                    undo_on_error=False,
                    post_process="raise RuntimeError()",
                    id_=1)

        c.invoke()
        self.assertIn("Post-Process error", cp.stderr)
        self.assertIn("RuntimeError", cp.stderr)
        self.assertFalse(cp.success)
Exemplo n.º 2
0
    def test_invoke(self):
        with mock.patch('dimensigon.use_cases.deployment.Command.success',
                        new_callable=mock.PropertyMock) as mock_success:
            mock_success.return_value = True

            c = Command(implementation=self.mock_implementation,
                        undo_command=self.mock_undo_command,
                        var_context=self.mock_context,
                        undo_on_error=False,
                        id_=1)
            r = c.invoke()
            # call a second time to see if only one time is called
            r = c.invoke()
            self.mock_implementation.execute.assert_called_once_with(
                self.params, context=self.mock_context, timeout=None)
            self.assertTrue(r)
Exemplo n.º 3
0
    def test_command_register(self):
        cp = CompletedProcess(success=True,
                              stdout='{"output": "this is a message"}',
                              stderr='',
                              rc=0,
                              start_time=datetime(2019, 4, 1))
        self.mock_implementation.execute.return_value = cp
        mock_register = mock.Mock()
        c = Command(implementation=self.mock_implementation,
                    var_context=self.mock_context,
                    register=mock_register,
                    undo_on_error=False,
                    post_process="",
                    id_=1)

        c.invoke()

        mock_register.save_step_execution.assert_called_once()
Exemplo n.º 4
0
    def test_command_no_undo(self):
        cp = CompletedProcess(success=True,
                              stdout='output: var',
                              stderr='',
                              rc=0,
                              start_time=datetime(2019, 4, 1))
        self.mock_implementation.execute.return_value = cp
        c = Command(implementation=self.mock_implementation,
                    var_context=self.mock_context,
                    undo_on_error=False,
                    id_=1)

        r = c.invoke()
        self.assertTrue(r)
        r = c.undo()
        self.assertTrue(r)
        self.assertDictEqual({1: cp}, c.result)