Example #1
0
def dispatcher():
    d = TreeUrlDispatcher()
    location = d.add_resource('/', name='root')
    location.add_route('GET', handler)
    d.add_route('GET', '/api/', handler)
    d.add_route('GET', '/api', handler)
    d.add_route('*', '/api/1/pets', handler)
    d.add_route('GET', '/api/1/pet/{id}', handler, name='pet')
    d.add_route('GET', '/api/1/pet/{id}/', handler)
    return d
Example #2
0
def test_add_resource(dispatcher: TreeUrlDispatcher):
    location = dispatcher.add_resource('/api/1/dogs', name='dogs')
    assert str(location.url_for()) == '/api/1/dogs'
Example #3
0
def test_novalid_path():
    r = TreeUrlDispatcher()
    with pytest.raises(ValueError):
        r.add_resource('dfsdf')
    with pytest.raises(ValueError):
        r.add_get('dfsdf', None)
def test_add_resource(dispatcher: TreeUrlDispatcher):
    location = dispatcher.add_resource('/api/1/dogs', name='dogs')
    assert str(location.url_for()) == '/api/1/dogs'
def test_novalid_path():
    r = TreeUrlDispatcher()
    with pytest.raises(ValueError):
        r.add_resource('dfsdf')
    with pytest.raises(ValueError):
        r.add_get('dfsdf', None)