Beispiel #1
0
    def test_validate_arguments(self):
        init_args = {
            'args': [{
                'name': 'arg1',
            }, {
                'name': 'arg2',
            }],
            'workflow': 'some workflow'
        }

        args_to_validate = {
            'arg1': 'something',
        }

        start_command = StartCommand('some name', init_args)

        # Default case.
        start_command.validate_arguments(args_to_validate)

        start_command.args = [
            StartCommandArgument({
                'name': 'arg1',
                'required': True,
            }),
            StartCommandArgument({
                'name': 'arg2',
                'required': True,
            })
        ]

        # Missing required argument
        with self.assertRaisesRegex(InvalidArgumentsException,
                                    'Argument arg2 is required'):
            start_command.validate_arguments(args_to_validate)

        args_to_validate = {'arg1': 'something', 'arg2': ''}

        # Present but empty required argument
        with self.assertRaisesRegex(InvalidArgumentsException,
                                    'Argument arg2 is required'):
            start_command.validate_arguments(args_to_validate)

        start_command.args = [
            StartCommandArgument({
                'name': 'arg1',
                'choices': ['c1', 'c2']
            })
        ]

        # Invalid choice
        with self.assertRaisesRegex(InvalidArgumentsException,
                                    'Argument arg1 must be one of'):
            start_command.validate_arguments(args_to_validate)

        args_to_validate = {'arg1': 'c1'}

        # Valid choice
        start_command.validate_arguments(args_to_validate)
Beispiel #2
0
    def test_parse_argument_with_user(self, mock_execute, mock_start_commands,
                                      mock_parser):
        wfc = WorkflowCommands()

        mock_parser.return_value = MockArgumentParser()
        MockArgumentParser.arguments['arg1'] = 'val1'
        MockArgumentParser.arguments['arg2'] = 'val2'
        MockArgumentParser.arguments['user'] = '******'
        wfc._extract_parser_arg_kwargs = MagicMock()

        start_command = StartCommand('command', {'workflow': 'theworkflow'})
        start_command.args = [
            StartCommandArgument({'name': 'arg1'}),
            StartCommandArgument({'name': 'user'}),
            StartCommandArgument({
                'name': 'arg2',
                'named': True
            })
        ]

        result = wfc._parse_arguments(start_command)

        self.assertEqual({
            'arg1': 'val1',
            'arg2': 'val2',
            'user': '******'
        }, result)

        # Expect a named argument has been added
        self.assertTrue(MockArgumentParser.named_argument_added)