def test_add_url_rule_methods(methods: Set[str], required_methods: Set[str], automatic_options: bool) -> None: app = Quart(__name__) def route() -> str: return "" route.methods = methods # type: ignore route.required_methods = required_methods # type: ignore non_func_methods = {"PATCH"} if not methods else None app.add_url_rule("/", "end", route, methods=non_func_methods, provide_automatic_options=automatic_options) result = {"PATCH"} if not methods else set() if automatic_options: result.add("OPTIONS") result.update(methods) result.update(required_methods) if "GET" in result: result.add("HEAD") assert app.url_map._rules_by_endpoint["end"][ 0].methods == result # type: ignore
def test_add_url_rule_methods( methods: Set[str], required_methods: Set[str], automatic_options: bool, ) -> None: app = Quart(__name__) def route() -> str: return '' route.methods = methods # type: ignore route.required_methods = required_methods # type: ignore non_func_methods = {'PATCH'} if not methods else None app.add_url_rule( '/', 'end', route, non_func_methods, provide_automatic_options=automatic_options, ) result = {'PATCH'} if not methods else set() if automatic_options: result.add('OPTIONS') result.update(methods) result.update(required_methods) if 'GET' in result: result.add('HEAD') assert app.url_map.endpoints['end'][0].methods == result
def test_endpoint_overwrite() -> None: app = Quart(__name__) def route() -> str: return '' app.add_url_rule('/', 'index', route, ['GET']) with pytest.raises(AssertionError): app.add_url_rule('/a', 'index', route, ['GET'])
def test_add_url_rule_host_and_subdomain_errors( host_matching: bool, server_name: Optional[str], subdomain: Optional[str], host: Optional[str], error: Exception, ) -> None: static_host = 'quart.com' if host_matching else None app = Quart(__name__, static_host=static_host, host_matching=host_matching) app.config['SERVER_NAME'] = server_name def route() -> str: return '' with pytest.raises(error): app.add_url_rule('/', route, subdomain=subdomain, host=host)
def test_add_url_rule_automatic_options( methods: Set[str], arg_automatic: Optional[bool], func_automatic: Optional[bool], expected_methods: Set[str], expected_automatic: bool, ) -> None: app = Quart(__name__) def route() -> str: return '' route.provide_automatic_options = func_automatic # type: ignore app.add_url_rule('/', 'end', route, methods, provide_automatic_options=arg_automatic) assert app.url_map.endpoints['end'][0].methods == expected_methods assert app.url_map.endpoints['end'][0].provide_automatic_options == expected_automatic
def test_add_url_rule_automatic_options( methods: Set[str], arg_automatic: Optional[bool], func_automatic: Optional[bool], expected_methods: Set[str], expected_automatic: bool, ) -> None: app = Quart(__name__) def route() -> str: return "" route.provide_automatic_options = func_automatic # type: ignore app.add_url_rule("/", "end", route, methods, provide_automatic_options=arg_automatic) assert app.url_map._rules_by_endpoint["end"][0].methods == expected_methods # type: ignore assert app.url_map._rules_by_endpoint["end"][0].provide_automatic_options == expected_automatic # type: ignore # noqa: E501
def test_endpoint_overwrite() -> None: app = Quart(__name__) def route() -> str: return "" def route2() -> str: return "" async def route3() -> str: return "" app.add_url_rule("/a", "index", route, ["GET"]) app.add_url_rule("/a/a", "index", route, ["GET"]) # Should not assert, as same view func with pytest.raises(AssertionError): app.add_url_rule("/a/b", "index", route2, ["GET"]) app.add_url_rule("/b", "async", route3, ["GET"]) app.add_url_rule("/b/a", "async", route3, ["GET"]) # Should not assert, as same view func with pytest.raises(AssertionError): app.add_url_rule("/b/b", "async", route2, ["GET"])
def test_endpoint_overwrite() -> None: app = Quart(__name__) def route() -> str: return '' def route2() -> str: return '' async def route3() -> str: return '' app.add_url_rule('/a', 'index', route, ['GET']) app.add_url_rule('/a/a', 'index', route, ['GET']) # Should not assert, as same view func with pytest.raises(AssertionError): app.add_url_rule('/a/b', 'index', route2, ['GET']) app.add_url_rule('/b', 'async', route3, ['GET']) app.add_url_rule('/b/a', 'async', route3, ['GET']) # Should not assert, as same view func with pytest.raises(AssertionError): app.add_url_rule('/b/b', 'async', route2, ['GET'])