def test_parameter_substrings(self): def route_url(_, **kwargs): return "/api/{}/things/{}".format(kwargs["id"], kwargs["thing_id"]) templater = AngularRouteTemplater(route_url, params=["id", "thing_id"]) assert templater.route_template("foo") == "/api/:id/things/:thing_id"
def test_static_route(self): def route_url(route_name, **kwargs): return "/" + route_name templater = AngularRouteTemplater(route_url, params=[]) assert templater.route_template("foo") == "/foo"
def test_custom_parameter(self): def route_url(_, **kwargs): return "/things/{}".format(kwargs["thing_id"]) templater = AngularRouteTemplater(route_url, params=["thing_id"]) assert templater.route_template("foo") == "/things/:thing_id"
def test_multiple_parameters(self): def route_url(_, **kwargs): return "/{}/{}".format(kwargs["foo"], kwargs["bar"]) templater = AngularRouteTemplater(route_url, params=["foo", "bar"]) assert templater.route_template("foo") == "/:foo/:bar"
def test_parameter_substrings(self): def route_url(_, **kwargs): return f"/api/{kwargs['id']}/things/{kwargs['thing_id']}" templater = AngularRouteTemplater(route_url, params=["id", "thing_id"]) assert templater.route_template("foo") == "/api/:id/things/:thing_id"
def test_route_with_id_placeholder(self): def route_url(route_name, **kwargs): return "/{}/{}".format(route_name, kwargs["id"]) templater = AngularRouteTemplater(route_url, params=["id"]) assert templater.route_template("foo") == "/foo/:id"
def test_static_route(self): def route_url(route_name, **kwargs): # pylint:disable=unused-argument return "/" + route_name templater = AngularRouteTemplater(route_url, params=[]) assert templater.route_template("foo") == "/foo"
def test_multiple_parameters(self): def route_url(_, **kwargs): return f"/{kwargs['foo']}/{kwargs['bar']}" templater = AngularRouteTemplater(route_url, params=["foo", "bar"]) assert templater.route_template("foo") == "/:foo/:bar"
def test_route_with_id_placeholder(self): def route_url(route_name, **kwargs): return f"/{route_name}/{kwargs['id']}" templater = AngularRouteTemplater(route_url, params=["id"]) assert templater.route_template("foo") == "/foo/:id"
def index(context, request): """Return the API descriptor document. Clients may use this to discover endpoints for the API. """ api_links = request.registry.api_links # We currently need to keep a list of the parameter names we use in our API # paths and pass these explicitly into the templater. As and when new # parameter names are added, we'll need to add them here, or this view will # break (and get caught by the `test_api_index` functional test). templater = AngularRouteTemplater( request.route_url, params=["id", "pubid", "user", "userid", "username"]) links = {} for link in api_links: method_info = { "method": link["method"], "url": templater.route_template(link["route_name"]), "desc": link["description"], } _set_at_path(links, link["name"].split("."), method_info) return {"links": links}
def links(context, request): templater = AngularRouteTemplater(request.route_url, params=["user"]) tag_search_url = request.route_url("activity.search", _query={"q": "_query_"}) tag_search_url = tag_search_url.replace("_query_", 'tag:":tag"') oauth_authorize_url = request.route_url("oauth_authorize") oauth_revoke_url = request.route_url("oauth_revoke") return { "account.settings": request.route_url("account"), "forgot-password": request.route_url("forgot_password"), "groups.new": request.route_url("group_create"), "help": request.route_url("help"), "oauth.authorize": oauth_authorize_url, "oauth.revoke": oauth_revoke_url, "search.tag": tag_search_url, "signup": request.route_url("signup"), "user": templater.route_template("stream.user_query"), }
def index_v2(context, request): """Return the API descriptor document. Clients may use this to discover endpoints for the API. """ api_links = request.registry.api_links["v2"] templater = AngularRouteTemplater( request.route_url, params=["id", "pubid", "user", "userid", "username"]) return {"links": link_helpers.format_nested_links(api_links, templater)}
def index(context, request): """Return the API descriptor document. Clients may use this to discover endpoints for the API. """ api_links = request.registry.api_links["v1"] # We currently need to keep a list of the parameter names we use in our API # paths and pass these explicitly into the templater. As and when new # parameter names are added, we'll need to add them here, or this view will # break (and get caught by the `test_api_index` functional test). templater = AngularRouteTemplater( request.route_url, params=["id", "pubid", "user", "userid", "username"]) return {"links": link_helpers.format_nested_links(api_links, templater)}