コード例 #1
0
    def test_execute_sends_callbacks(self):
        action = Action(app_name='HelloWorld',
                        action_name='Add Three',
                        name='helloWorld',
                        arguments=[
                            Argument('num1', value='-5.6'),
                            Argument('num2', value='4.3'),
                            Argument('num3', value='10.2')
                        ])
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'],
                              (WalkoffEvent.ActionStarted,
                               WalkoffEvent.ActionExecutionSuccess))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    self.assertIn('data', kwargs)
                    data = kwargs['data']
                    self.assertEqual(data['status'], 'Success')
                    self.assertAlmostEqual(data['result'], 8.9)
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)
        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #2
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
    def test_execute_sends_callbacks(self):
        action = Action(app_name='HelloWorld', action_name='Add Three', name='helloWorld',
                        arguments=[Argument('num1', value='-5.6'),
                                   Argument('num2', value='4.3'),
                                   Argument('num3', value='10.2')])
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'], (WalkoffEvent.ActionStarted, WalkoffEvent.ActionExecutionSuccess))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    self.assertIn('data', kwargs)
                    data = kwargs['data']
                    self.assertEqual(data['status'], 'Success')
                    self.assertAlmostEqual(data['result'], 8.9)
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)
        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #3
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
    def test_execute_return_failure(self):
        action = Action(app_name='HelloWorld',
                        action_name='dummy action',
                        name='helloWorld',
                        arguments=[Argument('status', value=False)])
        instance = AppInstance.create(app_name='HelloWorld',
                                      device_name='device1')
        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'],
                              (WalkoffEvent.ActionStarted,
                               WalkoffEvent.ActionExecutionError))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    self.assertIn('data', kwargs)
                    data = kwargs['data']
                    self.assertEqual(data['status'], 'Failure')
                    self.assertEqual(data['result'], False)
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(instance.instance, {})
        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #4
0
    def test_execute_default_return_success(self):
        action = Action(app_name='HelloWorld',
                        action_name='dummy action',
                        name='helloWorld',
                        arguments=[
                            Argument('status', value=True),
                            Argument('other', value=True)
                        ])
        instance = TestAction._make_app_instance()
        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'],
                              (WalkoffEvent.ActionStarted,
                               WalkoffEvent.ActionExecutionSuccess))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    self.assertIn('data', kwargs)
                    data = kwargs['data']
                    self.assertEqual(data['status'], 'Success')
                    self.assertEqual(data['result'], None)
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #5
0
    def test_execute_action_which_raises_exception_sends_callbacks(self):
        action = Action(app_name='HelloWorld',
                        action_name='Buggy',
                        name='helloWorld')
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'],
                              (WalkoffEvent.ActionStarted,
                               WalkoffEvent.ActionExecutionError))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                elif kwargs['event'] == WalkoffEvent.ActionExecutionError:
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #6
0
    def test_execute_with_accumulator_missing_action_callbacks(self):
        action = Action(app_name='HelloWorld',
                        action_name='Add Three',
                        name='helloWorld',
                        arguments=[
                            Argument('num1', reference='1'),
                            Argument('num2', reference='action2'),
                            Argument('num3', value='10.2')
                        ])
        accumulator = {'1': '-5.6', 'missing': '4.3', '3': '45'}
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'],
                              (WalkoffEvent.ActionStarted,
                               WalkoffEvent.ActionArgumentsInvalid))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)
        action.execute(LocalActionExecutionStrategy(), accumulator,
                       instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #7
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
    def test_execute_default_return_success(self):
        action = Action(app_name='HelloWorld', action_name='dummy action', name='helloWorld',
                        arguments=[Argument('status', value=True), Argument('other', value=True)])
        instance = TestAction._make_app_instance()
        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'], (WalkoffEvent.ActionStarted, WalkoffEvent.ActionExecutionSuccess))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    self.assertIn('data', kwargs)
                    data = kwargs['data']
                    self.assertEqual(data['status'], 'Success')
                    self.assertEqual(data['result'], None)
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #8
0
 def test_execute_action_which_raises_exception(self):
     action = Action(app_name='HelloWorld',
                     action_name='Buggy',
                     name='helloWorld')
     instance = TestAction._make_app_instance()
     acc = {}
     action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     self.assertIn(action.id, acc)
コード例 #9
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_with_accumulator_missing_action(self):
     action = Action(app_name='HelloWorld', action_name='Add Three', name='helloWorld',
                     arguments=[Argument('num1', reference='1'),
                                Argument('num2', reference='action2'),
                                Argument('num3', value='10.2')])
     accumulator = {'1': '-5.6', 'missing': '4.3', '3': '45'}
     instance = TestAction._make_app_instance()
     action.execute(LocalActionExecutionStrategy(), accumulator, instance.instance)
コード例 #10
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_action_which_raises_exception(self):
     action = Action(app_name='HelloWorld',
                     action_name='Buggy',
                     name='helloWorld')
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     action.execute(instance.instance, {})
     self.assertIsNotNone(action.get_output())
コード例 #11
0
 def test_execute_generates_id(self):
     action = Action(app_name='HelloWorld',
                     action_name='helloWorld',
                     name='helloWorld')
     original_execution_id = action.get_execution_id()
     instance = TestAction._make_app_instance()
     action.execute(LocalActionExecutionStrategy(), {}, instance.instance)
     self.assertNotEqual(action.get_execution_id(), original_execution_id)
コード例 #12
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_generates_id(self):
     action = Action(app_name='HelloWorld',
                     action_name='helloWorld',
                     name='helloWorld')
     original_execution_id = action.get_execution_id()
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     action.execute(instance.instance, {})
     self.assertNotEqual(action.get_execution_id(), original_execution_id)
コード例 #13
0
 def test_execute_with_accumulator_missing_action(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', reference='1'),
                         Argument('num2', reference='action2'),
                         Argument('num3', value='10.2')
                     ])
     accumulator = {'1': '-5.6', 'missing': '4.3', '3': '45'}
     instance = TestAction._make_app_instance()
     action.execute(LocalActionExecutionStrategy(), accumulator,
                    instance.instance)
コード例 #14
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_with_accumulator_missing_action(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', reference='1'),
                         Argument('num2', reference='action2'),
                         Argument('num3', value='10.2')
                     ])
     accumulator = {'1': '-5.6', 'missing': '4.3', '3': '45'}
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     action.execute(instance.instance, accumulator)
コード例 #15
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_with_complex_args(self):
     action = Action(app_name='HelloWorld',
                     action_name='Json Sample',
                     name='helloWorld',
                     arguments=[
                         Argument('json_in',
                                  value={
                                      'a':
                                      '-5.6',
                                      'b': {
                                          'a': '4.3',
                                          'b': 5.3
                                      },
                                      'c': ['1', '2', '3'],
                                      'd': [{
                                          'a': '',
                                          'b': 3
                                      }, {
                                          'a': '',
                                          'b': -1.5
                                      }, {
                                          'a': '',
                                          'b': -0.5
                                      }]
                                  })
                     ])
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     result = action.execute(instance.instance, {})
     self.assertAlmostEqual(result.result, 11.0)
     self.assertEqual(result.status, 'Success')
     self.assertEqual(action._output, result)
コード例 #16
0
 def test_execute_with_complex_args(self):
     action = Action(app_name='HelloWorld',
                     action_name='Json Sample',
                     name='helloWorld',
                     arguments=[
                         Argument('json_in',
                                  value={
                                      'a':
                                      '-5.6',
                                      'b': {
                                          'a': '4.3',
                                          'b': 5.3
                                      },
                                      'c': ['1', '2', '3'],
                                      'd': [{
                                          'a': '',
                                          'b': 3
                                      }, {
                                          'a': '',
                                          'b': -1.5
                                      }, {
                                          'a': '',
                                          'b': -0.5
                                      }]
                                  })
                     ])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc,
                             instance.instance)
     self.assertAlmostEqual(acc[action.id], 11.0)
     self.assertEqual(result, 'Success')
コード例 #17
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_global_action(self):
     action = Action(app_name='HelloWorld', action_name='global2', name='helloWorld',
                     arguments=[Argument('arg1', value='something')])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     self.assertAlmostEqual(acc[action.id], 'something')
     self.assertEqual(result, 'Success')
コード例 #18
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_no_args(self):
     action = Action('HelloWorld', action_name='helloWorld', name='helloWorld')
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     expected = ActionResult({'message': 'HELLO WORLD'}, 'Success')
     self.assertEqual(result, expected.status)
     self.assertEqual(acc[action.id], expected.result)
コード例 #19
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_no_args(self):
     action = Action(app_name='HelloWorld',
                     action_name='helloWorld',
                     name='helloWorld')
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     self.assertEqual(action.execute(instance.instance, {}),
                      ActionResult({'message': 'HELLO WORLD'}, 'Success'))
     self.assertEqual(action._output,
                      ActionResult({'message': 'HELLO WORLD'}, 'Success'))
コード例 #20
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_with_args(self):
     action = Action(app_name='HelloWorld', action_name='Add Three', name='helloWorld',
                     arguments=[Argument('num1', value='-5.6'),
                                Argument('num2', value='4.3'),
                                Argument('num3', value='10.2')])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     self.assertAlmostEqual(acc[action.id], 8.9)
     self.assertEqual(result, 'Success')
コード例 #21
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_global_action(self):
     action = Action(app_name='HelloWorld',
                     action_name='global2',
                     name='helloWorld',
                     arguments=[Argument('arg1', value='something')])
     instance = AppInstance.create(app_name='HelloWorld', device_name='')
     result = action.execute(instance.instance, {})
     self.assertAlmostEqual(result.result, 'something')
     self.assertEqual(result.status, 'Success')
     self.assertEqual(action._output, result)
コード例 #22
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_with_accumulator_with_extra_actions(self):
     action = Action(app_name='HelloWorld', action_name='Add Three', name='helloWorld',
                     arguments=[Argument('num1', reference='1'),
                                Argument('num2', reference='action2'),
                                Argument('num3', value='10.2')])
     accumulator = {'1': '-5.6', 'action2': '4.3', '3': '45'}
     instance = TestAction._make_app_instance()
     result = action.execute(LocalActionExecutionStrategy(), accumulator, instance.instance)
     self.assertAlmostEqual(accumulator[action.id], 8.9)
     self.assertEqual(result, 'Success')
コード例 #23
0
 def test_execute_no_args(self):
     action = Action('HelloWorld',
                     action_name='helloWorld',
                     name='helloWorld')
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc,
                             instance.instance)
     expected = ActionResult({'message': 'HELLO WORLD'}, 'Success')
     self.assertEqual(result, expected.status)
     self.assertEqual(acc[action.id], expected.result)
コード例 #24
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_with_complex_args(self):
     action = Action(app_name='HelloWorld', action_name='Json Sample', name='helloWorld',
                     arguments=[
                         Argument('json_in', value={'a': '-5.6', 'b': {'a': '4.3', 'b': 5.3}, 'c': ['1', '2', '3'],
                                                    'd': [{'a': '', 'b': 3}, {'a': '', 'b': -1.5},
                                                          {'a': '', 'b': -0.5}]})])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     self.assertAlmostEqual(acc[action.id], 11.0)
     self.assertEqual(result, 'Success')
コード例 #25
0
 def test_execute_global_action(self):
     action = Action(app_name='HelloWorld',
                     action_name='global2',
                     name='helloWorld',
                     arguments=[Argument('arg1', value='something')])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc,
                             instance.instance)
     self.assertAlmostEqual(acc[action.id], 'something')
     self.assertEqual(result, 'Success')
コード例 #26
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
    def test_execute_action_which_raises_exception_sends_callbacks(self):
        action = Action(app_name='HelloWorld', action_name='Buggy', name='helloWorld')
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'], (WalkoffEvent.ActionStarted, WalkoffEvent.ActionExecutionError))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                elif kwargs['event'] == WalkoffEvent.ActionExecutionError:
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)

        action.execute(LocalActionExecutionStrategy(), {}, instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #27
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
    def test_execute_with_accumulator_missing_action_callbacks(self):
        action = Action(app_name='HelloWorld', action_name='Add Three', name='helloWorld',
                        arguments=[Argument('num1', reference='1'),
                                   Argument('num2', reference='action2'),
                                   Argument('num3', value='10.2')])
        accumulator = {'1': '-5.6', 'missing': '4.3', '3': '45'}
        instance = TestAction._make_app_instance()

        result = {'started_triggered': False, 'result_triggered': False}

        def callback_is_sent(sender, **kwargs):
            if isinstance(sender, Action):
                self.assertIn('event', kwargs)
                self.assertIn(kwargs['event'], (WalkoffEvent.ActionStarted, WalkoffEvent.ActionArgumentsInvalid))
                if kwargs['event'] == WalkoffEvent.ActionStarted:
                    result['started_triggered'] = True
                else:
                    result['result_triggered'] = True

        WalkoffEvent.CommonWorkflowSignal.connect(callback_is_sent)
        action.execute(LocalActionExecutionStrategy(), accumulator, instance.instance)

        self.assertTrue(result['started_triggered'])
        self.assertTrue(result['result_triggered'])
コード例 #28
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_with_args(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', value='-5.6'),
                         Argument('num2', value='4.3'),
                         Argument('num3', value='10.2')
                     ])
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     result = action.execute(instance.instance, {})
     self.assertAlmostEqual(result.result, 8.9)
     self.assertEqual(result.status, 'Success')
     self.assertEqual(action._output, result)
コード例 #29
0
 def test_execute_with_accumulator_with_extra_actions(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', reference='1'),
                         Argument('num2', reference='action2'),
                         Argument('num3', value='10.2')
                     ])
     accumulator = {'1': '-5.6', 'action2': '4.3', '3': '45'}
     instance = TestAction._make_app_instance()
     result = action.execute(LocalActionExecutionStrategy(), accumulator,
                             instance.instance)
     self.assertAlmostEqual(accumulator[action.id], 8.9)
     self.assertEqual(result, 'Success')
コード例 #30
0
 def test_execute_with_args(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', value='-5.6'),
                         Argument('num2', value='4.3'),
                         Argument('num3', value='10.2')
                     ])
     instance = TestAction._make_app_instance()
     acc = {}
     result = action.execute(LocalActionExecutionStrategy(), acc,
                             instance.instance)
     self.assertAlmostEqual(acc[action.id], 8.9)
     self.assertEqual(result, 'Success')
コード例 #31
0
ファイル: test_action.py プロジェクト: sunilpentapati/WALKOFF
 def test_execute_with_accumulator_with_extra_actions(self):
     action = Action(app_name='HelloWorld',
                     action_name='Add Three',
                     name='helloWorld',
                     arguments=[
                         Argument('num1', reference='1'),
                         Argument('num2', reference='action2'),
                         Argument('num3', value='10.2')
                     ])
     accumulator = {'1': '-5.6', 'action2': '4.3', '3': '45'}
     instance = AppInstance.create(app_name='HelloWorld',
                                   device_name='device1')
     result = action.execute(instance.instance, accumulator)
     self.assertAlmostEqual(result.result, 8.9)
     self.assertEqual(result.status, 'Success')
     self.assertEqual(action._output, result)
コード例 #32
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_generates_id(self):
     action = Action(app_name='HelloWorld', action_name='helloWorld', name='helloWorld')
     original_execution_id = action.get_execution_id()
     instance = TestAction._make_app_instance()
     action.execute(LocalActionExecutionStrategy(), {}, instance.instance)
     self.assertNotEqual(action.get_execution_id(), original_execution_id)
コード例 #33
0
ファイル: test_action.py プロジェクト: iadgov/WALKOFF
 def test_execute_action_which_raises_exception(self):
     action = Action(app_name='HelloWorld', action_name='Buggy', name='helloWorld')
     instance = TestAction._make_app_instance()
     acc = {}
     action.execute(LocalActionExecutionStrategy(), acc, instance.instance)
     self.assertIn(action.id, acc)