示例#1
0
    def test_build_actions_with_contexts(self):
        acts = [
            dict(self.actor_returns),
            dict(self.actor_returns),
            dict(self.actor_returns),
            dict(self.actor_returns)
        ]

        with mock.patch.object(group.BaseGroupActor,
                               '_build_action_group') as action_builder:
            action_builder.return_value = acts
            group.BaseGroupActor(
                'Unit Test Action', {
                    'acts': acts,
                    'contexts': [{
                        'TEST': 'TestA'
                    }, {
                        'TEST': 'TestB'
                    }]
                },
                init_context={'PRE': 'CONTEXT'})

        self.assertEquals(2, len(action_builder.mock_calls))
        action_builder.assert_has_calls([
            mock.call(context={
                'PRE': 'CONTEXT',
                'TEST': 'TestA'
            }),
            mock.call(context={
                'PRE': 'CONTEXT',
                'TEST': 'TestB'
            })
        ])
示例#2
0
    def test_build_actions_with_context_file(self):
        acts = [dict(self.actor_returns)]

        with mock.patch.object(group.BaseGroupActor,
                               '_build_action_group') as action_builder:
            action_builder.return_value = acts
            group.BaseGroupActor('ContextFile Actor', {
                'acts': acts,
                'contexts': {
                    'file': 'examples/test/context.json',
                    'tokens': {
                        'TOKEN_VALUE': 'tadaa'
                    }
                }
            },
                                 init_context={'init': 'stuff'})

        self.assertEquals(2, len(action_builder.mock_calls))
        action_builder.assert_has_calls([
            mock.call(context={
                'init': 'stuff',
                'key': 'value1'
            }),
            mock.call(context={
                'init': 'stuff',
                'key': 'tadaa'
            })
        ])
示例#3
0
 def test_build_actions_with_bad_context_file(self):
     with self.assertRaises(exceptions.InvalidOptions):
         group.BaseGroupActor('bad context', {
             'acts': [],
             'contexts': {
                 'file': 'no_such_file',
                 'tokens': {}
             }
         })
示例#4
0
    def test_build_action_group(self):
        acts = [
            dict(self.actor_returns),
            dict(self.actor_returns),
            dict(self.actor_returns),
            dict(self.actor_returns)
        ]

        actor = group.BaseGroupActor('Unit Test Action', {'acts': acts})
        ret = actor._build_action_group({'TEST': 'CONTEXT'})
        self.assertEquals(ret[0]._init_context, {'TEST': 'CONTEXT'})
示例#5
0
 def test_build_actions(self):
     actor = group.BaseGroupActor(
         'Unit Test Action', {
             'acts': [
                 dict(self.actor_returns),
                 dict(self.actor_returns),
                 dict(self.actor_returns),
                 dict(self.actor_returns)
             ]
         })
     ret = actor._build_actions()
     self.assertEquals(4, len(ret))
示例#6
0
    def test_execute_failure(self):
        actor = group.BaseGroupActor('Unit Test Action', {'acts': []})

        # Mock out the _run_actions method and make sure it just returns one
        # True and one False results.
        @gen.coroutine
        def run_actions_true(*args, **kwargs):
            raise gen.Return([True, False])

        actor._run_actions = run_actions_true

        ret = yield actor._execute()
        self.assertEquals(ret, None)
示例#7
0
    def test_execute_success(self):
        actor = group.BaseGroupActor('Unit Test Action', {'acts': []})

        # Mock out the _run_actions method and make sure it just returns two
        # True results.
        @gen.coroutine
        def run_actions_true(*args, **kwargs):
            raise gen.Return([True, True])

        actor._run_actions = run_actions_true

        ret = yield actor._execute()
        self.assertEqual(None, ret)