Skip to main content

Uses filter groups to validate requests

Project description

Request Filter Groups

Description

A Python wrapper and utility function for validating requests.

The funtions takes a list of dictionaries containing JSON paths keys to search for the attribute to validate and filter rule values to validate the attributes with. Under the hood, the validation process uses Validator to validate the JSON path values with the Validator rules. If atleast one filter group is validated, then the funcion returns True. List of possible Validator rules can be found here:

Examples

Decorator:

Succeeded Validation

r = RequestFilter()

@r.request_filter_groups([
    {
        "A.B": "regex:foo",
        "C": "required|min:3"
    }
])
def func(data):
    # <response logic>
    return {"statusCode": 200}

request_data = {
    "A": {"B": "foo"},
    "C": [1, 2, 3]
},

response = func(data)

Returns dummy func() return value:

{"statusCode": 200}

Failed Validation

r = RequestFilter()

@r.request_filter_groups([
    {
        "A.B": "regex:foo",
        "C": "required|min:10"
    }
])
def func(data):
    # <response logic>
    return {"statusCode": 200}

request_data = {
    "A": {"B": "foo"},
    "C": [1, 2, 3]
},

response = func(data)

Returns validate() return value

{'statusCode': 422, 'body': ValidationError({'C': {'Min': 'Expected Maximum: 10, Got: 3'}})}

Installation

Package can be found on PyPI

pip install request-filter-groups

TODO:

  • Add Flask-related tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

request-filter-groups-0.0.4.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

request_filter_groups-0.0.4-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page