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