Exemple #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", {})
Exemple #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", {})
Exemple #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'
Exemple #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', {})