def test_name_can_be_explicitly_given(api: API): @api.route("/about/{who}", name="about-someone") async def about(req, res, who): pass with pytest.raises(HTTPError): api.url_for(name="about", who="me") url = api.url_for("about-someone", who="me") assert url == "/about/me"
def test_name_is_inferred_from_view_name(api: API): @api.route("/about/{who}") class AboutPerson: async def get(self, req, res, who): pass url = api.url_for("about_person", who="Godzilla") assert url == "/about/Godzilla" @api.route("/about/{who}") async def about_who(req, res, who): pass url = api.url_for("about_who", who="Godzilla") assert url == "/about/Godzilla"
def test_use_namespace(api: API): @api.route("/about", namespace="blog") async def about(req, res): pass url = api.url_for("blog:about") assert url == "/about"
def test_on_class_based_views(api: API): @api.route("/about/{who}") class AboutPerson: pass url = api.url_for("about_person", who="Godzilla") assert url == "/about/Godzilla"
def test_if_route_exists_then_url_for_returns_full_path(api: API): @api.route("/about/{who}") async def about(req, res, who): pass url = api.url_for("about", who="me") assert url == "/about/me"
def test_if_prefix_not_given_then_routes_mounted_at_slash_name(api: API): numbers = Recipe("numbers") @numbers.route("/real") async def real(req, res): pass api.recipe(numbers) assert api.url_for("numbers:real") == "/numbers/real"
def test_if_prefix_then_routes_mounted_at_prefix(api: API): numbers = Recipe("numbers", prefix="/numbers-yo") @numbers.route("/real") async def real(req, res): pass api.recipe(numbers) assert api.url_for("numbers:real") == "/numbers-yo/real"
def test_if_no_route_exists_for_name_then_url_for_raises_404(api: API): with pytest.raises(HTTPError): api.url_for(name="about")