Exemple #1
0
 def test_get_options(self):
     "Test OPTIONS request."
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1": True, "arg2": 42}
     request = DummyRequest(api_mode="prod",
                            api_version="1.0",
                            api_name="dummy_api")
     request.method = "OPTIONS"
     request.setHeader("Access-Control-Request-Headers", "Content-Type")
     router = urldispatch.APIRouter(route_map,
                                    config=api_config,
                                    cross_origin_domains="*")
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.CORSInterrogation))
     resource.render_OPTIONS(request)
     self.assertEquals(request.getHeader("Content-Type"),
                       "application/json; charset=utf-8")
     self.assertEquals(request.getHeader("Access-Control-Allow-Origin"),
                       "*")
     self.assertEquals(
         request.getHeader("Access-Control-Allow-Credentials"), "true")
     self.assertEquals(request.getHeader("Access-Control-Allow-Headers"),
                       "Content-Type")
     self.assertEquals(
         request.getHeader("Access-Control-Allow-Methods"),
         "PUT,GET,DELETE,POST,HEAD,TRACE,CONNECT,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK"
     )
Exemple #2
0
 def test_config_import(self):
     "Test API config dictionary import"
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1": True, "arg2": 42}
     router = urldispatch.APIRouter(route_map, config=api_config)
     self.assertTrue(router.config["arg1"] == True)
     self.assertTrue(router.config["arg2"] == 42)
Exemple #3
0
 def test_options_request_with_acrh(self):
     "Test a OPTIONS request w/ supplied Access-Control-Request-Headers header."
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1": True, "arg2": 42}
     router = urldispatch.APIRouter(route_map,
                                    config=api_config,
                                    cross_origin_domains="*")
     request = DummyRequest(api_mode="", api_version="", api_name="")
     request.setHeader("Access-Control-Request-Headers", "Content-Type")
     resource = urldispatch.CORSInterrogation(request, api_router=router)
     body = resource.render_OPTIONS(request)
     self.assertEquals(request.response_code, 200)
     self.assertEquals(request.getHeader("Content-Type"),
                       "application/json; charset=utf-8")
     self.assertEquals(request.getHeader("Access-Control-Allow-Origin"),
                       "*")
     self.assertEquals(
         request.getHeader("Access-Control-Allow-Credentials"), "true")
     self.assertEquals(request.getHeader("Access-Control-Allow-Headers"),
                       "Content-Type")
     self.assertEquals(
         request.getHeader("Access-Control-Allow-Methods"),
         "PUT,GET,DELETE,POST,HEAD,TRACE,CONNECT,PROPFIND,PROPPATCH,MKCOL,COPY,MOVE,LOCK,UNLOCK"
     )
     self.assertEquals(body, "")
Exemple #4
0
 def test_get_child_version_unknown(self):
     "Test version extraction with bad header"
     request = DummyRequest(api_mode="", api_version="", api_name="")
     request.setHeader("X-DigiTar-API-Version", "dummyapi")
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownVersion))
Exemple #5
0
 def test_get_child_route_no_api_match(self):
     "Test route match with no API name match in version header"
     request = DummyRequest(api_mode="", api_version="", api_name="")
     request.setHeader("X-DigiTar-API-Version", "badmojoapi-1.0+prod")
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownVersion))
Exemple #6
0
 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)
Exemple #7
0
 def test_get_child_no_route_match(self):
     "Test no route match"
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1": True, "arg2": 42}
     request = DummyRequest(api_mode="prod",
                            api_version="1.0",
                            api_name="dummy_api")
     request.setHeader("X-DigiTar-API-Version", "dummy_api-1.0+prod")
     router = urldispatch.APIRouter(route_map, config=api_config)
     resource = router.getChild("/badmojo/", request)
     self.assertTrue(isinstance(resource, urldispatch.UnknownAPI))
Exemple #8
0
 def test_get_child_route_match_api_match(self):
     "Test route match with good API name match in version header"
     route_map = [(r"^/example/", dummy_api)]
     api_config = {"arg1": True, "arg2": 42}
     request = DummyRequest(api_mode="prod",
                            api_version="1.0",
                            api_name="dummy_api")
     request.setHeader("X-DigiTar-API-Version", "dummy_api-1.0+prod")
     router = urldispatch.APIRouter(route_map, config=api_config)
     resource = router.getChild("/example/", request)
     self.assertTrue(isinstance(resource, urldispatch.VersionRouter))
     self.assertEquals(resource.api_router, router)
Exemple #9
0
                    api_name, str(e))
                sys.exit(-1)
            config[api_name] = api_module.config.validate_config(
                config[api_name])

    # Setup the API routes...list of tuples
    api_hash = dict(cfg_central.items("apis"))

    routes = []

    for api in api_hash.keys():
        api_module = __import__(api, globals(), locals(), [], -1)
        routes.append((api_hash[api], api_module))

    root = urldispatch.APIRouter(routes,
                                 config=config,
                                 cross_origin_domains=cross_origin_domains,
                                 inhibit_http_caching=inhibit_http_caching)
    shiji.change_server_ident(server_ident)

    # Setup logging
    try:
        fn_log = cfg_central.get("logging", "log_file")
    except NoOptionError:
        fn_log = ""

    try:
        log_prefix = cfg_central.get("logging", "syslog_prefix")
    except NoOptionError:
        log_prefix = "Shiji"

    if fn_log:
Exemple #10
0
 def test_get_route_map(self):
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     self.assertEqual(router.route_map, router.get_route_map())
Exemple #11
0
 def test_build_route_map_api_module(self):
     "Test initializing the route map - API module"
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     self.assertTrue(isinstance(router.route_map[0][1], types.ModuleType))
Exemple #12
0
 def test_build_route_map_regex(self):
     "Test initializing the route map  - regex"
     route_map = [(r"^/example/", dummy_api)]
     router = urldispatch.APIRouter(route_map)
     self.assertTrue(router.route_map[0][0].match("/example/"))