Пример #1
0
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
Пример #2
0
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
Пример #3
0
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() == {}
Пример #4
0
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'
Пример #5
0
 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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
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
Пример #9
0
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
Пример #10
0
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
Пример #11
0
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
Пример #12
0
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