def test_rewrite_uritemplate_with_regexps_with_different_types_in_methods(): def method1(param: int): return param def method2(param: str): return param method1 = ComponentMethod(method1) method2 = ComponentMethod(method2) argument_types = {int, str} # Act with pytest.raises(Exception) as exception: rewrite_uritemplate_with_regexps('/{param}/', [method1, method2]) # Assert assert str(exception.value) == ( f'Different methods are bound to the same path variable, ' f'but have different types annotated: {argument_types}')
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
def test_rewrite_uritemplate_with_regexps(url_path, param_type, expected_url_path, example_url): def method(param: param_type): return param method = ComponentMethod(method) # Act rewritten_url_path = rewrite_uritemplate_with_regexps(url_path, [method]) # Assert assert rewritten_url_path == expected_url_path assert re.match(rewritten_url_path, example_url)