def _create_dispatch_function(controller_class, route: Route): component = get_component(controller_class) @wraps(route.method.func) def dispatch(winter_view, request: Request, **path_variables): controller = build_controller(component.component_cls) return _call_controller_method(controller, route, request) return dispatch
def test_response_schema(controller_class: Type, method_name: str, expected_responses: Dict): component = get_component(controller_class) method = component.get_method(method_name) route = get_route(method) # Act responses = build_responses_schemas(route) # Assert assert responses == expected_responses
def test_with_raises_argument_not_supported(): component = get_component(ControllerWithPathParameters) argument = component.get_method('test').get_argument('param6') resolver = PathParametersArgumentResolver() request = Mock(spec=Request) request.path_info = f'/controller_with_path_parameters/123/456/one/{uuid_}/2/' with pytest.raises(ArgumentNotSupported) as exception: resolver.resolve_argument(argument, request, {}) assert str(exception.value) == 'Unable to resolve argument param6: str'
def test_is_supported_path_parameter(controller_class, method_name, arg_name, expected_value): component = get_component(controller_class) argument = component.get_method(method_name).get_argument(arg_name) resolver = PathParametersArgumentResolver() # Act is_supported = resolver.is_supported(argument) second_is_supported = resolver.is_supported(argument) # Assert assert is_supported == expected_value assert second_is_supported == expected_value
def create_django_urls(controller_class: Type) -> List: component = get_component(controller_class) django_urls = [] for url_path, routes in _group_routes_by_url_path(component.methods): django_view = _create_django_view(controller_class, component, routes) winter_url_path = f'^{url_path}$' methods = [route.method for route in routes] django_url_path = rewrite_uritemplate_with_regexps( winter_url_path, methods) for route in routes: django_urls.append( url(django_url_path, django_view, name=route.method.full_name)) return django_urls