From b7316ff5131333e65d84adde593cab7b0fa11116 Mon Sep 17 00:00:00 2001 From: Blallo Date: Mon, 31 Aug 2020 11:02:03 +0200 Subject: [PATCH] Refactor helper script --- test/aux_async_model.py | 52 ++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/test/aux_async_model.py b/test/aux_async_model.py index 875bfe8..c7d9554 100644 --- a/test/aux_async_model.py +++ b/test/aux_async_model.py @@ -1,35 +1,61 @@ # coding: utf-8 import asyncio +from pprint import pprint as pp -from phi.ldap.async_model import ( - Hackers, +from phi.async_ldap.model import ( + # Hackers, + # User, Robots, - Congregations, - User, Service, + Congregations, + Group, build_heritage, iter_children, ) -from phi.ldap.async_client import AsyncClient + +from phi.async_ldap.new_model import Hackers, User +from phi.async_ldap.client import AsyncClient -async def dlv(h): - return [el async for el in build_heritage(h, User)] +async def dlv(h, cls): + return [el async for el in build_heritage(h, cls)] cl = AsyncClient( "ldap://localhost", port=389, encryption=True, - validate=True, - ca_cert="openldap/cert.pem", + # validate=True, + ca_cert="/home/leo/Documents/coding/phi/openldap/cert.pem", username="root", password="root", base_dn="dc=unit,dc=macaomilano,dc=org", attribute_id="cn", ) -h = Hackers(cl) -r = Robots(cl) -g = Congregations(cl) -# asyncio.run(dlv(h)) + + +async def get_all_children(): + h = Hackers(cl) + r = Robots(cl) + g = Congregations(cl) + + hackers = await dlv(h, User) + robots = await dlv(r, Service) + groups = await dlv(g, Group) + + return (hackers, robots, groups) + + +async def print_async(awaitable): + result = await awaitable + pp(result) + + +async def describe(obj): + results = await obj.describe() + return results + + +asyncio.run(print_async(describe(Hackers(cl)))) +asyncio.run(print_async(describe(User(cl, "conte_mascetti"))))