def test_serializer_class_map_view_schema(
    path,
    method,
    expected_operation_id,
    expected_responses_required,
):
    generator = RefsSchemaGenerator()

    view = generator.create_view(SerializerClassMapView.as_view(), method,
                                 None)
    schema = view.schema
    schema.generator = None
    result = view.schema.get_operation(path, method)
    code, _ = view.schema._get_action_code_description(path, method)
    responses_schema = result['responses'][code]['content'][
        'application/vnd.vendor']['schema']
    responses_properties = responses_schema['properties']['data']
    if 'items' in responses_properties:
        responses_properties = responses_properties['items']

    assert result['operationId'] == expected_operation_id
    assert responses_properties['required'] == expected_responses_required
Beispiel #2
0
    def with_args(prefix, viewset, basename, router=None):
        router = router or SimpleRouter()
        generator = RefsSchemaGenerator()

        router.register(prefix, viewset, basename=basename)
        urlconf = UrlConf()
        urlconf.urlpatterns = router.urls

        def create_view(path, method):
            match = resolve(path, urlconf)
            view = generator.create_view(match.func, method, None)
            return view

        return create_view
def test_schema_with_tags_success_case(settings, api_format, expected_api_format):
    settings.API_FORMATS = api_format

    refs_schema = RefsSchemaGenerator()

    assert refs_schema.api_formats == expected_api_format
import pytest

from restdoctor.rest_framework.schema import RefsSchemaGenerator
from tests.test_unit.test_schema.stubs import DefaultViewSet


@pytest.mark.parametrize(
    'generator,expected_schema_keys',
    (
        (None, ['type', 'properties', 'required']),
        (RefsSchemaGenerator(), ['$ref']),
    ),
)
def test_schema_get_operation_with_refs_schema_generator_success_case(
    get_create_view_func, generator, expected_schema_keys,
):
    create_view = get_create_view_func('test', DefaultViewSet, 'test')

    view = create_view('/test/', 'GET')
    view.schema.generator = generator
    operation = view.schema.get_operation('/test/', 'GET')
    responses_schema = operation['responses']['200']['content']['application/vnd.vendor']['schema']
    responses_properties = responses_schema['properties']['data']
    if 'items' in responses_properties:
        responses_properties = responses_properties['items']

    assert list(responses_properties.keys()) == expected_schema_keys
import pytest

from restdoctor.rest_framework.schema import RefsSchemaGenerator
from tests.test_unit.test_schema.stubs import DefaultViewSet


@pytest.mark.parametrize(
    'generator,expected_codes',
    (
        (None, ['200']),
        (RefsSchemaGenerator(), ['200', '400', '404']),
    ),
)
def test_errors_handlers_sc(
    get_create_view_func,
    generator,
    expected_codes,
):
    create_view = get_create_view_func('test', DefaultViewSet, 'test')

    view = create_view('/test/123/', 'GET')
    view.schema.generator = generator
    operation = view.schema.get_operation('/test/123/', 'GET')

    print(generator, operation)
    assert list(operation['responses'].keys()) == expected_codes