Esempio n. 1
0
    def test_kwargs(self):
        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(["action_one", "action_two"])
                builder.bind_action("action_one", mock_action_one, a=1, b=2)
                builder.bind_action("action_two", mock_action_two, c=3)
                actions = builder.build_actions([{
                    "action_two": 3
                }, {
                    "action_one": 4
                }])
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call(a=1, b=2))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call(c=3))
        mock_action_two.assert_has_calls(mock_calls)

        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(["action_one", "action_two"])
                builder.bind_action("action_one", mock_action_one, a=1, b=2)
                builder.bind_action("action_two", mock_action_two, c=3)
                actions = builder.build_actions([{
                    "action_two": 3
                }, {
                    "action_one": 4
                }],
                                                d=4,
                                                e=5)
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call(a=1, b=2, d=4, e=5))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call(c=3, d=4, e=5))
        mock_action_two.assert_has_calls(mock_calls)
Esempio n. 2
0
    def test_positional_args(self):
        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(["action_one", "action_two"])
                builder.bind_action("action_one", mock_action_one, "a", "b")
                builder.bind_action("action_two", mock_action_two, "c")
                actions = builder.build_actions([{
                    "action_two": 3
                }, {
                    "action_one": 4
                }])
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call("a", "b"))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call("c"))
        mock_action_two.assert_has_calls(mock_calls)

        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(["action_one", "action_two"])
                builder.bind_action("action_one", mock_action_one, "a", "b")
                builder.bind_action("action_two", mock_action_two, "c")
                actions = builder.build_actions([{
                    "action_two": 3
                }, {
                    "action_one": 4
                }], "d", 5)
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call("a", "b", "d", 5))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call("c", "d", 5))
        mock_action_two.assert_has_calls(mock_calls)
Esempio n. 3
0
    def test_positional_args(self):
        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(['action_one', 'action_two'])
                builder.bind_action('action_one', mock_action_one, 'a', 'b')
                builder.bind_action('action_two', mock_action_two, 'c')
                actions = builder.build_actions([{
                    'action_two': 3
                }, {
                    'action_one': 4
                }])
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call('a', 'b'))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call('c'))
        mock_action_two.assert_has_calls(mock_calls)

        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(['action_one', 'action_two'])
                builder.bind_action('action_one', mock_action_one, 'a', 'b')
                builder.bind_action('action_two', mock_action_two, 'c')
                actions = builder.build_actions([{
                    'action_two': 3
                }, {
                    'action_one': 4
                }], 'd', 5)
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call('a', 'b', 'd', 5))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call('c', 'd', 5))
        mock_action_two.assert_has_calls(mock_calls)
Esempio n. 4
0
 def test_invalid_schema(self):
     builder = utils.ActionBuilder(["action_one", "action_two"])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           "action_oone": 1
                       }, {
                           "action_twoo": 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           "action_one": -1
                       }, {
                           "action_two": 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           "action_one": 0
                       }, {
                           "action_two": 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           1: 0
                       }, {
                           "action_two": 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           "action_two": "action_two"
                       }])
Esempio n. 5
0
 def test_invalid_schema(self):
     builder = utils.ActionBuilder(['action_one', 'action_two'])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           'action_oone': 1
                       }, {
                           'action_twoo': 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           'action_one': -1
                       }, {
                           'action_two': 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           'action_one': 0
                       }, {
                           'action_two': 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           1: 0
                       }, {
                           'action_two': 2
                       }])
     self.assertRaises(schema_exceptions.ValidationError, builder.validate,
                       [{
                           'action_two': 'action_two'
                       }])
Esempio n. 6
0
    def test_mixed_args(self):
        with mock.patch(self.mock_one) as mock_action_one:
            with mock.patch(self.mock_two) as mock_action_two:
                builder = utils.ActionBuilder(['action_one', 'action_two'])
                builder.bind_action('action_one',
                                    mock_action_one,
                                    'one',
                                    a=1,
                                    b=2)
                builder.bind_action('action_two', mock_action_two, 'two', c=3)
                actions = builder.build_actions([{
                    'action_two': 3
                }, {
                    'action_one': 4
                }],
                                                'three',
                                                d=4)
                for action in actions:
                    action()
        self.assertEqual(4, mock_action_one.call_count,
                         "action one not called 4 times")
        mock_calls = []
        for i in range(4):
            mock_calls.append(mock.call('one', 'three', a=1, b=2, d=4))
        mock_action_one.assert_has_calls(mock_calls)

        self.assertEqual(3, mock_action_two.call_count,
                         "action two not called 3 times")
        mock_calls = []
        for i in range(3):
            mock_calls.append(mock.call('two', 'three', c=3, d=4))
        mock_action_two.assert_has_calls(mock_calls)
Esempio n. 7
0
 def _bind_actions(self):
     actions = [
         "hard_reboot", "soft_reboot", "stop_start", "rescue_unrescue"
     ]
     action_builder = scenario_utils.ActionBuilder(actions)
     action_builder.bind_action("hard_reboot", self._reboot_server)
     action_builder.bind_action("soft_reboot", self._soft_reboot_server)
     action_builder.bind_action("stop_start", self._stop_and_start_server)
     action_builder.bind_action("rescue_unrescue",
                                self._rescue_and_unrescue_server)
     return action_builder
Esempio n. 8
0
 def _bind_actions(self):
     actions = [
         'hard_reboot', 'soft_reboot', 'stop_start', 'rescue_unrescue'
     ]
     action_builder = scenario_utils.ActionBuilder(actions)
     action_builder.bind_action('hard_reboot', self._reboot_server)
     action_builder.bind_action('soft_reboot', self._soft_reboot_server)
     action_builder.bind_action('stop_start', self._stop_and_start_server)
     action_builder.bind_action('rescue_unrescue',
                                self._rescue_and_unrescue_server)
     return action_builder
Esempio n. 9
0
 def test_invalid_bind(self):
     builder = utils.ActionBuilder(["action_one"])
     self.assertRaises(schema_exceptions.ValidationError,
                       builder.bind_action, "missing", action_one)
Esempio n. 10
0
 def test_invalid_keyword(self):
     builder = utils.ActionBuilder(["action_one", "action_two"])
     self.assertRaises(schema_exceptions.ValidationError,
                       builder.build_actions, [{
                           "missing": 1
                       }])
Esempio n. 11
0
 def test_invalid_keyword(self):
     builder = utils.ActionBuilder(['action_one', 'action_two'])
     self.assertRaises(schema_exceptions.ValidationError,
                       builder.build_actions, [{
                           'missing': 1
                       }])