Ejemplo n.º 1
0
def test_get_swagger12_objects_if_only_swagger12_version_is_present(
        settings, registry):
    registry.settings['pyramid_swagger.swagger_versions'] = [SWAGGER_12]
    registry.settings['pyramid_swagger.schema12'] = 'schema12'
    swagger_handler, spec = get_swagger_objects(settings, {}, registry)
    assert 'swagger12_handler' in str(swagger_handler)
    assert 'schema12' == spec
Ejemplo n.º 2
0
def test_get_swagger12_objects_if_only_swagger12_version_is_present(
        settings, registry):
    registry.settings['pyramid_swagger.swagger_versions'] = [SWAGGER_12]
    registry.settings['pyramid_swagger.schema12'] = 'schema12'
    swagger_handler, spec = get_swagger_objects(settings, {}, registry)
    assert 'swagger12_handler' in str(swagger_handler)
    assert 'schema12' == spec
Ejemplo n.º 3
0
def reduce_result(request, result):
    global TWEEN_SETTINGS, SPEC_MAPPING_CACHE
    route_mapper = request.registry.queryUtility(IRoutesMapper)
    if route_mapper is None:
        # for testing
        return result
    route_info = route_mapper(request)
    route = route_info['route']
    cacheKey = route.path + route.predicates[0].text()
    if cacheKey not in SPEC_MAPPING_CACHE:
        if TWEEN_SETTINGS is None:
            TWEEN_SETTINGS = tween.load_settings(request.registry)
        swagger_handler, spec = tween.get_swagger_objects(
            TWEEN_SETTINGS,
            route_info,
            request.registry
        )
        op = swagger_handler.op_for_request(
            request,
            route_info=route_info,
            spec=spec
        )
        response_spec = tween.get_response_spec(
            request.response.status_int, op
        )
        resolved = api.resolve_refs(spec, response_spec).get('schema', {})
        spec_mapping = build_spec_mapping(resolved)
        SPEC_MAPPING_CACHE[cacheKey] = spec_mapping
    else:
        spec_mapping = SPEC_MAPPING_CACHE[cacheKey]
    return reduce_mapping(spec_mapping, result)
Ejemplo n.º 4
0
def test_get_swagger20_objects_if_both_present_but_no_prefer20_config(
        settings, registry):
    registry.settings['pyramid_swagger.swagger_versions'] = [
        SWAGGER_12, SWAGGER_20]
    registry.settings['pyramid_swagger.schema20'] = 'schema20'
    swagger_handler, spec = get_swagger_objects(settings, {}, registry)
    assert 'swagger20_handler' in str(swagger_handler)
    assert 'schema20' == spec
Ejemplo n.º 5
0
def test_get_swagger12_objects_if_both_present_but_route_not_in_prefer20(
        settings, registry):
    settings.prefer_20_routes = ['swagger20_route']
    registry.settings['pyramid_swagger.swagger_versions'] = [
        SWAGGER_12, SWAGGER_20]
    route_info = {'route': Mock()}
    route_info['route'].name = 'swagger12_route'
    registry.settings['pyramid_swagger.schema12'] = 'schema12'
    swagger_handler, spec = get_swagger_objects(settings, route_info, registry)
    assert 'swagger12_handler' in str(swagger_handler)
    assert 'schema12' == spec