phi/test/aux_async_model.py

62 lines
1.2 KiB
Python
Raw Normal View History

2019-04-28 15:34:37 +02:00
# coding: utf-8
import asyncio
2020-08-31 11:02:03 +02:00
from pprint import pprint as pp
2019-04-28 15:34:37 +02:00
2020-08-31 11:02:03 +02:00
from phi.async_ldap.model import (
# Hackers,
# User,
2019-04-28 15:34:37 +02:00
Robots,
Service,
2020-08-31 11:02:03 +02:00
Congregations,
Group,
2019-04-28 15:34:37 +02:00
build_heritage,
iter_children,
)
2020-08-31 11:02:03 +02:00
from phi.async_ldap.new_model import Hackers, User
from phi.async_ldap.client import AsyncClient
2019-04-28 15:34:37 +02:00
2020-08-31 11:02:03 +02:00
async def dlv(h, cls):
return [el async for el in build_heritage(h, cls)]
2019-04-28 15:34:37 +02:00
cl = AsyncClient(
"ldap://localhost",
port=389,
encryption=True,
2020-08-31 11:02:03 +02:00
# validate=True,
ca_cert="/home/leo/Documents/coding/phi/openldap/cert.pem",
2019-04-28 15:34:37 +02:00
username="root",
password="root",
base_dn="dc=unit,dc=macaomilano,dc=org",
attribute_id="cn",
)
2020-08-31 11:02:03 +02:00
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"))))