예제 #1
0
def validate_params(connection, op_name, path_params):
    field_name = 'Invalid path_params provided'
    try:
        is_valid, validation_report = connection.validate_path_params(
            op_name, path_params)
        if not is_valid:
            raise ValidationError({field_name: validation_report})
    except Exception as e:
        raise ValidationError({field_name: str(e)})
예제 #2
0
    def validate_params(self, operation_name, params):
        report = {}
        op_spec = self.get_operation_spec(operation_name)
        data, query_params, path_params = _get_user_params(params)

        def validate(validation_method, field_name, user_params):
            key = 'Invalid %s provided' % field_name
            try:
                is_valid, validation_report = validation_method(
                    operation_name, user_params)
                if not is_valid:
                    report[key] = validation_report
            except Exception as e:
                report[key] = str(e)
            return report

        validate(self._conn.validate_query_params, ParamName.QUERY_PARAMS,
                 query_params)
        validate(self._conn.validate_path_params, ParamName.PATH_PARAMS,
                 path_params)
        if is_post_request(op_spec) or is_put_request(op_spec):
            validate(self._conn.validate_data, ParamName.DATA, data)

        if report:
            raise ValidationError(report)
예제 #3
0
    def test_module_should_fail_when_validation_error(self, resource_mock):
        operation_name = 'test name'
        msg = 'Foo error.'
        resource_mock.side_effect = ValidationError(msg)

        result = self._run_module_with_fail_json({'operation': operation_name})
        assert result['failed']
        assert msg == result['msg']
예제 #4
0
def validate_params(connection, op_name, query_params, path_params, data,
                    op_spec):
    report = {}

    def validate(validation_method, field_name, params):
        key = 'Invalid %s provided' % field_name
        try:
            is_valid, validation_report = validation_method(op_name, params)
            if not is_valid:
                report[key] = validation_report
        except Exception as e:
            report[key] = str(e)
        return report

    validate(connection.validate_query_params, 'query_params', query_params)
    validate(connection.validate_path_params, 'path_params', path_params)
    if is_post_request(op_spec) or is_post_request(op_spec):
        validate(connection.validate_data, 'data', data)

    if report:
        raise ValidationError(report)