示例#1
0
async def run2(db):
    ob = test_utils.create_content()
    start = time.time()
    for _ in range(ITERATIONS):
        getAdapter(ob, ISecurityInfo)
    end = time.time()
    print(f'Done with {ITERATIONS} in {end - start} seconds')
示例#2
0
async def run1():
    ob = test_utils.create_content()
    print("Test single adapter lookup")
    start = time.time()
    for _ in range(ITERATIONS):
        getAdapter(ob, ISecurityInfo)
    end = time.time()
    print(f"Done with {ITERATIONS} in {end - start} seconds")
示例#3
0
async def run1():
    ob = test_utils.create_content()
    print('Test single adapter lookup')
    start = time.time()
    for _ in range(ITERATIONS):
        getAdapter(ob, ISecurityInfo)
    end = time.time()
    print(f'Done with {ITERATIONS} in {end - start} seconds')
示例#4
0
async def test_get_security_data(dummy_request):
    request = dummy_request  # noqa
    ob = test_utils.create_content()
    adapter = getAdapter(ob, ISecurityInfo)
    data = adapter()
    assert 'access_users' in data
    assert 'access_roles' in data
示例#5
0
def test_configuration_machine_allows_overriding():
    from guillotina.configure.config import ConfigurationMachine
    from guillotina.configure import component
    from guillotina.component import adapter, named, getAdapter
    from zope.interface import implementer, Interface

    class IFoo(Interface):
        pass

    @implementer(IFoo)
    class Foo(object):
        pass

    class IBar(Interface):
        pass

    cm = ConfigurationMachine()

    @adapter(IFoo)
    @implementer(IBar)
    @named('bar')
    class _Factory(object):
        def __init__(self, context):
            self.context = context

    class _FactoryOverride(_Factory):
        pass

    component.adapter(cm, (_Factory, ))
    cm.execute_actions()
    cm.commit()

    component.adapter(cm, (_FactoryOverride, ))
    cm.execute_actions()

    adapter = getAdapter(Foo(), name='bar')
    assert isinstance(adapter, _FactoryOverride)
示例#6
0
 def _callFUT(self, *args, **kw):
     from guillotina.component import getAdapter
     return getAdapter(*args, **kw)
示例#7
0
async def test_RootSpecialPermissions_IApplication(dummy_guillotina):
    root = getUtility(IApplication, name='root')
    adapter = getAdapter(root, interface=IPrincipalPermissionManager)
    assert isinstance(adapter, ApplicationSpecialPermissions)
示例#8
0
async def test_DatabaseSpecialPermissions_IDatabase(dummy_txn_root):
    async with await dummy_txn_root as root:
        adapter = getAdapter(root, interface=IPrincipalPermissionManager)
        assert isinstance(adapter, DatabaseSpecialPermissions)
示例#9
0
def test_get_current_interaction(dummy_request):
    adapter = getAdapter(dummy_request, interface=IInteraction)
    assert isinstance(adapter, Interaction)
示例#10
0
def test_vocabulary():
    from guillotina.schema.vocabulary import SimpleVocabulary
    vocab = SimpleVocabulary.fromItems(
        ((u"Foo", "id_foo"), (u"Bar", "id_bar")))
    res = getAdapter(vocab, interface=IValueToJson)
    assert type(res) == list