def test_subrouter_groupdict(router, mock_req, mounts, req_path, match_dict): subrouter = Router() endpoint = mock.Mock() subrouter.add_route(GET, mounts[1], endpoint) router.add_router(mounts[0], subrouter) m = [x for x in router.match_routes(mock_req)] if m: assert m[0] is endpoint
def test_sinatra_path(): s = '/something' r = Router.sinatra_path_to_regex(s) assert r.match("/else") is None m = r.match(s) assert m is not None assert m.groupdict() == {}
def test_sinatra_key(): s = '/name/:name' r = Router.sinatra_path_to_regex(s) assert r.match("/not/right") is None matches = r.match("/name/growler") assert matches.group('name') == 'growler' gd = matches.groupdict() assert gd['name'] == 'growler'
def router(self): """ Property returning the router at the top of the middleware chain's stack (the last item in the list). If the list is empty OR the item is not an instance of growler.Router, one is created and added to the middleware chain, matching all requests. """ if not self.has_root_router: self.middleware.add(HTTPMethod.ALL, MiddlewareChain.ROOT_PATTERN, Router()) return self.middleware.last().func
def test_sinatra_passes_regex(): import re s = re.compile('/name/:name') r = Router.sinatra_path_to_regex(s) assert r.match("/not/right") is None
def test_sinatra_path_groupdict(path, req_path, match_dict): r = Router.sinatra_path_to_regex(path) m = r.match(req_path) assert m.groupdict() == match_dict
def test_sinatra_path_matches(path, req_path, matches): r = Router.sinatra_path_to_regex(path) assert (r.fullmatch(req_path) is not None) == matches
def test_property_subrouter(router): subrouter = Router() router.add(0, '/', subrouter) subrouters = list(router.subrouters) assert len(subrouters) == 1 assert subrouters[0].func is subrouter