def test_schema_refs(rf, doc_version): router = get_router(f'{doc_version}/schema-refs.yaml') request = rf.post('/cat', json.dumps(lil_bub), content_type='application/json') request.api_info = APIInfo(router.get_path('/cat').get_operation('post')) params = read_parameters(request, {}) assert params['cat'] == lil_bub
def test_polymorphism(rf, doc_version, object): router = get_router(f'{doc_version}/schema-refs.yaml') request = rf.post('/pet', json.dumps(object), content_type='application/json') request.api_info = APIInfo(router.get_path('/pet').get_operation('post')) params = read_parameters(request, {}) assert params['pet'] == object
def test_exceptional_response(rf, doc_version): router = get_router('{}/parameter-test.yaml'.format(doc_version)) router.add_handlers({'greet': greet}) path_view = router.get_path_view_class('/greet').as_view() response = path_view(rf.get('/', { 'greeting': 'hello', 'greetee': 'world' })) assert response.content == b'oh no'
def test_path_refs(doc_version): router = get_router(f'{doc_version}/path-refs.yaml') assert router.get_path('/b').mapping == router.get_path('/a').mapping
def test_validator(doc_version): router = get_router('{}/schema-refs.yaml'.format(doc_version)) with pytest.raises(RouterValidationError) as ei: validate_router(router) assert len(ei.value.errors) == 2
def test_header_underscore(doc_version): router = get_router('{}/header-underscore.yaml'.format(doc_version)) with pytest.raises(RouterValidationError) as ei: validate_router(router) errors = list(ei.value.flat_errors) assert any(isinstance(e[1], InvalidParameterDefinition) for e in errors)
import pytest from django.core.exceptions import ImproperlyConfigured from django.core.files.base import ContentFile from django.core.files.uploadedfile import UploadedFile from jsonschema import ValidationError from lepo.api_info import APIInfo from lepo.apidef.doc import Swagger2APIDefinition from lepo.apidef.parameter.openapi import OpenAPI3BodyParameter from lepo.excs import ErroneousParameters, MissingParameter from lepo.parameter_utils import read_parameters from lepo_tests.tests.utils import DOC_VERSIONS, cast_parameter_value, get_router routers = pytest.mark.parametrize('router', [ get_router(f'{doc_version}/parameter-test.yaml') for doc_version in DOC_VERSIONS ], ids=DOC_VERSIONS) def test_parameter_validation(): with pytest.raises(ValidationError) as ei: cast_parameter_value( Swagger2APIDefinition({}), { 'type': 'array', 'collectionFormat': 'ssv', 'items': { 'type': 'string', 'maxLength': 3, },