Beispiel #1
0
def test_routelist__pop():
    routes = RouteList()

    foobar = Route(method="GET")
    hamspam = Route(method="POST")
    routes.add(foobar, name="foobar")
    routes.add(hamspam, name="hamspam")
    assert list(routes) == [foobar, hamspam]

    _foobar = routes.pop("foobar")
    assert _foobar == foobar
    assert list(routes) == [hamspam]

    default = Route()
    route = routes.pop("egg", default)
    assert route is default
    assert list(routes) == [hamspam]

    with pytest.raises(KeyError):
        routes.pop("egg")
Beispiel #2
0
def test_routelist__replaces_same_name_other_pattern_other_name():
    routes = RouteList()

    foobar1 = Route(method="GET")
    hamspam = Route(method="POST")

    routes.add(foobar1, name="foobar")
    routes.add(hamspam, name="hamspam")
    assert list(routes) == [foobar1, hamspam]

    foobar2 = Route(method="POST")
    routes.add(foobar2, name="foobar")
    assert list(routes) == [foobar2]
    assert routes["foobar"] is foobar1
Beispiel #3
0
def test_routelist__replaces_same_pattern_diff_name():
    routes = RouteList()

    foobar1 = Route(method="GET")
    routes.add(foobar1, name="name")
    assert list(routes) == [foobar1]

    foobar2 = Route(method="GET")
    routes.add(foobar2, name="foobar")
    assert list(routes) == [foobar2]
    assert routes[0] is foobar1
Beispiel #4
0
def test_routelist__add():
    routes = RouteList()

    foobar = Route(method="PUT")
    routes.add(foobar, name="foobar")
    assert routes
    assert list(routes) == [foobar]
    assert routes["foobar"] == foobar
    assert routes["foobar"] is routes[0]

    hamspam = Route(method="POST")
    routes.add(hamspam, name="hamspam")
    assert list(routes) == [foobar, hamspam]
    assert routes["hamspam"] == hamspam