Пример #1
0
def test_mapping_another():
    from pyramid_tiny_utility import get_mapping_from_class
    class A():
        pass

    class Adapter(object):
        def __init__(self, a):
            self.a = a

    class BAdapter(Adapter):
        pass
    class CAdapter(Adapter):
        pass

    _config.add_mapping(A, Adapter, BAdapter)
    _config.add_mapping(A, Adapter, CAdapter, name="c-case")
    
    class request:
        registry = _config.registry

    mapping = get_mapping_from_class(request, A, Adapter)
    a = A()
    mapped = mapping(a)
    assert isinstance(mapped, BAdapter)

    mapping = get_mapping_from_class(request, A, Adapter, name="c-case")
    a = A()
    mapped = mapping(a)
    assert isinstance(mapped, CAdapter)
Пример #2
0
def test_mapping():
    from pyramid_tiny_utility import get_mapping_from_class
    # src -> container
    class Container(object):
        def __init__(self, src):
            self.src = src

    class Source(object):
        pass

    _config.add_mapping(Source, Container)
    
    class request:
        registry = _config.registry
    mapping = get_mapping_from_class(request, Source, Container)

    src = Source()
    mapped = mapping(src)
    assert isinstance(mapped, Container)