Skip to content

validate_operation fails for TSV on Python 3.9.5 #234

@bnavigator

Description

@bnavigator
======================================================================= test session starts ========================================================================
platform linux -- Python 3.9.5, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /usr/bin/python3.9
cachedir: .pytest_cache
rootdir: /home/abuild/rpmbuild/BUILD/flex-6.14.1, configfile: pytest.ini
plugins: Faker-8.1.4, httpbin-1.0.0, pythonpath-0.7.3
collected 1459 items    
...
tests/validation/request/test_request_parameter_validation.py::test_request_parameter_array_extraction[tsv-1\t2\t3] FAILED                                   [ 84%]
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

format_ = 'tsv', value = '1\t2\t3'

    @pytest.mark.parametrize(
        'format_,value',
        (
            (CSV, '1,2,3'),
            (SSV, '1 2 3'),
            (TSV, '1\t2\t3'),
            (PIPES, '1|2|3'),
        ),
    )
    def test_request_parameter_array_extraction(format_, value):
        schema = SchemaFactory(
            paths={
                '/get/': {
                    'get': {
                        'responses': {'200': {'description': "Success"}},
                        'parameters': [
                            {
                                'name': 'id',
                                'in': QUERY,
                                'type': ARRAY,
                                'collectionFormat': format_,
                                'minItems': 3,
                                'maxItems': 3,
                                'items': {
                                    'type': INTEGER,
                                    'minimum': 1,
                                    'maximum': 3,
                                },
                            },
                        ],
                    },
                },
            },
        )
    
        request = RequestFactory(url='http://www.example.com/get/?id={}'.format(value))
    
>       validate_request(
            request=request,
            schema=schema,
        )

tests/validation/request/test_request_parameter_validation.py:187: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

request = <flex.http.Request object at 0x7ff63b40d5e0>
schema = {'info': {'title': 'Test API', 'version': '0.0.1'}, 'paths': {'/get/': {'get': {'parameters': [{'collectionFormat': 't...: 'query', 'items': {...}, 'maxItems': 3, ...}], 'responses': {'200': {'description': 'Success'}}}}}, 'swagger': '2.0'}

    def validate_request(request, schema):
        """
        Request validation does the following steps.
    
           1. validate that the path matches one of the defined paths in the schema.
           2. validate that the request method conforms to a supported methods for the given path.
           3. validate that the request parameters conform to the parameter
              definitions for the operation definition.
        """
        with ErrorDict() as errors:
            # 1
            try:
                api_path = validate_path_to_api_path(
                    path=request.path,
                    context=schema,
                    **schema
                )
            except ValidationError as err:
                errors['path'].add_error(err.detail)
                return  # this causes an exception to be raised since errors is no longer falsy.
    
            path_definition = schema['paths'][api_path] or {}
    
            if not path_definition:
                # TODO: is it valid to not have a definition for a path?
                return
    
            # 2
            try:
                operation_definition = validate_request_method_to_operation(
                    request_method=request.method,
                    path_definition=path_definition,
                )
            except ValidationError as err:
                errors['method'].add_error(err.detail)
                return
    
            if operation_definition is None:
                # TODO: is this compliant with swagger, can path operations have a null
                # definition?
                return
    
            # 3
            operation_validators = construct_operation_validators(
                api_path=api_path,
                path_definition=path_definition,
                operation_definition=operation_definition,
                context=schema,
            )
            try:
                validate_operation(request, operation_validators, context=schema)
            except ValidationError as err:
>               errors['method'].add_error(err.detail)

flex/validation/request.py:65: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = ErrorDict(<class 'flex.exceptions.ErrorList'>, {'method': [ErrorDict(<class 'flex.exceptions.ErrorList'>, {'parameters...rrorDict(<class 'flex.exceptions.ErrorList'>, {'maximum': ['123 must be less than or equal to than 3']})]})]})]})]})]})
type_ = None, value = None, traceback = None

    def __exit__(self, type_, value, traceback):
        if any((type_, value, traceback)):
            if not issubclass(type_, ValidationError):
                return False
        if self:
>           self.raise_()

flex/exceptions.py:22: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = ErrorDict(<class 'flex.exceptions.ErrorList'>, {'method': [ErrorDict(<class 'flex.exceptions.ErrorList'>, {'parameters...rrorDict(<class 'flex.exceptions.ErrorList'>, {'maximum': ['123 must be less than or equal to than 3']})]})]})]})]})]})

    def raise_(self):
>       raise ValidationError(self)
E       flex.exceptions.ValidationError: 'method':
E           - 'parameters':
E               - 'query':
E                   - 'id':
E                       - 'minItems':
E                           - 'Array must have at least 3 items. It had only had 1 items.'
E                       - 'items':
E                           - 'maximum':
E                               - '123 must be less than or equal to than 3'

flex/exceptions.py:25: ValidationError

Python 3.8.10 is fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions