From 2908015745524345d4111d477979b38390bd8ed4 Mon Sep 17 00:00:00 2001 From: Brendan McCollam Date: Wed, 12 Jun 2019 10:59:24 +0100 Subject: [PATCH] Adds test for request validator w/Flask wrapper formatting --- tests/integration/test_wrappers.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/integration/test_wrappers.py b/tests/integration/test_wrappers.py index e6104f0..d64e721 100644 --- a/tests/integration/test_wrappers.py +++ b/tests/integration/test_wrappers.py @@ -1,15 +1,14 @@ -import pytest - from flask.wrappers import Request, Response from werkzeug.datastructures import EnvironHeaders, ImmutableMultiDict from werkzeug.routing import Map, Rule, Subdomain from werkzeug.test import create_environ -from openapi_core.wrappers.flask import ( - FlaskOpenAPIRequest, FlaskOpenAPIResponse, -) +import pytest from openapi_core.shortcuts import create_spec from openapi_core.validation.response.validators import ResponseValidator +from openapi_core.validation.request.validators import RequestValidator +from openapi_core.wrappers.flask import (FlaskOpenAPIRequest, + FlaskOpenAPIResponse) @pytest.fixture @@ -81,7 +80,8 @@ class TestFlaskOpenAPIRequest(object): assert openapi_request.mimetype == request.mimetype def test_multiple_values(self, request_factory, request): - request = request_factory('GET', '/', subdomain='www', query_string='a=b&a=c') + request = request_factory( + 'GET', '/', subdomain='www', query_string='a=b&a=c') openapi_request = FlaskOpenAPIRequest(request) @@ -140,18 +140,21 @@ class TestFlaskOpenAPIResponse(object): assert openapi_response.mimetype == response.mimetype -class TestFlaskOpenAPIRequestValidation(object): +class TestFlaskOpenAPIValidation(object): specfile = 'data/v3.0/flask_wrapper.yaml' - def test_response_validator_path_pattern( - self, - factory, - request_factory, - response_factory): + def test_response_validator_path_pattern(self, factory, request_factory, response_factory): validator = ResponseValidator(create_spec(factory.spec_from_file(self.specfile))) request = request_factory('GET', '/browse/12/', subdomain='kb') openapi_request = FlaskOpenAPIRequest(request) openapi_response = FlaskOpenAPIResponse(response_factory('Some item', status_code=200)) result = validator.validate(openapi_request, openapi_response) assert not result.errors + + def test_request_validator_path_pattern(self, factory, request_factory): + validator = RequestValidator(create_spec(factory.spec_from_file(self.specfile))) + request = request_factory('GET', '/browse/12/', subdomain='kb') + openapi_request = FlaskOpenAPIRequest(request) + result = validator.validate(openapi_request) + assert not result.errors