示例#1
0
def test_path_for_model():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, "foo/{id}", lambda model: {"id": model.id}, {}, [])
    assert traject.path(IdModel("a")) == ("foo/a", {})
示例#2
0
def test_path_for_model_with_converter():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, "foo/{id}", lambda model: {"id": model.id}, dict(id=Converter(int)), [])
    assert traject.path(IdModel(1)) == ("foo/1", {})
示例#3
0
def test_path_for_model_with_converter():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, 'foo/{id:int}',
                    lambda model: {'id': model.id})
    assert traject.path(IdModel(1)) == 'foo/1'
示例#4
0
def test_path_for_model():
    traject = Traject()

    class IdModel(object):
        def __init__(self, id):
            self.id = id

    traject.inverse(IdModel, 'foo/{id}',
                    lambda model: {'id': model.id},
                    {}, [])
    assert traject.path(IdModel('a')) == ('foo/a', {})