Beispiel #1
0
 def test_create_route_map_from_string(self):
     "Validate building route map from single route string."
     call_router = urldispatch.CallRouter(calls, self.version_router)
     self.assertEqual(len(call_router.route_map), 1)
     route = call_router.route_map[0]
     self.assertEqual(route[0].pattern, "ping$")
     self.assertEqual(route[1].__name__, "PingCall")
Beispiel #2
0
 def test_get_child_no_route_match(self):
     "Validate retrieving non-existent resource."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.request.setHeader("X-DigiTar-API-Version", "test-1.0+prod")
     self.request.uri = "/myroute"
     res = call_router.getChild("noname", self.request)
     self.assertTrue(isinstance(res, urldispatch.UnknownCall))
Beispiel #3
0
 def test_get_child_route_match_url_arguments(self):
     "Validate that URL arguments do not interfere with matching a valid resource."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.request.setHeader("X-DigiTar-API-Version", "test-1.0+prod")
     self.request.uri = "/level1/ping%26io?arg1=ignored"
     res = call_router.getChild("noname", self.request)
     self.assertTrue(isinstance(res, calls_list.PingCall))
     self.assertTrue(res.url_matches.has_key("group1"))
     self.assertEqual(res.url_matches["group1"], "&io")
Beispiel #4
0
 def test_get_child_route_match(self):
     "Validate retrieving valid resource."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.request.setHeader("X-DigiTar-API-Version", "test-1.0+prod")
     self.request.uri = "/level1/ping%26io"
     res = call_router.getChild("noname", self.request)
     self.assertTrue(isinstance(res, calls_list.PingCall))
     self.assertTrue(res.url_matches.has_key("group1"))
     self.assertEqual(res.url_matches["group1"], "&io")
Beispiel #5
0
 def test_call_router_init_list_versions(self):
     "Validate call router initialization w/ version listing resource."
     call_router = urldispatch.CallRouter(calls, self.version_router, True)
     self.assertEqual(call_router.version_router, self.version_router)
     found_list_versions = False
     for route in call_router.route_map:
         self.assertEqual(route[0].pattern, route[1].routes + "$")
         if route[0].pattern == "list_versions$" and \
            route[1].__name__ == "ListVersionsCall":
             found_list_versions = True
     self.assertEqual(found_list_versions, True)
Beispiel #6
0
 def test_create_route_map_from_list(self):
     "Validate building route map from list of route strings."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.assertEqual(len(call_router.route_map), 2)
     ping_route_found = False
     me_route_found = False
     for route in call_router.route_map:
         if route[0].pattern == "ping(?P<group1>.*)$" and \
            route[1].__name__ == "PingCall":
             ping_route_found = True
         if route[0].pattern == "me$" and \
            route[1].__name__ == "PingCall":
             me_route_found = True
     self.assertEqual(ping_route_found, True)
     self.assertEqual(me_route_found, True)
Beispiel #7
0
    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())
Beispiel #8
0
 def test_get_child_unknown_api_mode(self):
     "Validate retrieving resource with an unknown API mode."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.request.setHeader("X-DigiTar-API-Version", "test-1.0+badmode")
     res = call_router.getChild("noname", self.request)
     self.assertTrue(isinstance(res, urldispatch.UnknownVersion))
Beispiel #9
0
 def test_get_child_malformed_version(self):
     "Validate retrieving resource with a malformed version header."
     call_router = urldispatch.CallRouter(calls_list, self.version_router)
     self.request.setHeader("X-DigiTar-API-Version", "bobbledygook")
     res = call_router.getChild("noname", self.request)
     self.assertTrue(isinstance(res, urldispatch.UnknownVersion))
Beispiel #10
0
 def test_call_router_init_no_list_versions(self):
     "Validate call router initialization w/o version listing resource."
     call_router = urldispatch.CallRouter(calls, self.version_router)
     self.assertEqual(call_router.version_router, self.version_router)
     for route in call_router.route_map:
         self.assertEqual(route[0].pattern, route[1].routes + "$")
Beispiel #11
0
# -*- coding: utf-8-*-
####################################################################
# FILENAME: ./dummy_api/v1_0/__init__.py
# PROJECT: Shiji API
# DESCRIPTION: Dummy API v1.0
#
#
# $Id$
####################################################################
# (C)2015 DigiTar Inc.
# Licensed under the MIT License.
####################################################################

from shiji import urldispatch
import calls

# call_router is required to be present for VersionRouter to accept
# this module

call_router = urldispatch.CallRouter(calls, auto_list_versions=True)