def setUp(self): self.request = DummyRequest(api_mode="", api_version="1.0", api_name="") self.route_map = [("^/test/me/(?P<group1>.+)", calls.PingCall)] self.api_router = urldispatch.APIRouter(self.route_map) self.version_map = {"1.0": (r"1.0", v1_0)} self.version_router = urldispatch.VersionRouter( self.version_map, self.api_router)
def test_list_versions_get(self): "Test list versions." def versions_list(): return {"1.0": (r"1.0", object()), "0.9": (r"0.9", object())} version_router = urldispatch.VersionRouter(versions_list()) call_router = urldispatch.CallRouter(calls, version_router) res = urldispatch.ListVersionsCall(self.request, url_matches=self.route_map, call_router=call_router) res.render_GET(self.request) exp_res = json.dumps({ "all_versions": sorted(versions_list()), "curr_version": self.request.api_version }) self.assertEqual(res.routes, "list_versions") self.assertEqual(exp_res, self.request.content.getvalue())
# ################################################################### # FILENAME: ./mylogin_api/__init__.py # PROJECT: # DESCRIPTION: mylogin_api API # # # ################################################################### from shiji import urldispatch import v1_0 # api_name, api_versions and version_router are required to be # present for APIRouter to accept this module. api_name = "mylogin_api" api_versions = {"1.0": (r"1.0", v1_0)} version_router = urldispatch.VersionRouter(api_versions)