def test_format_list_expand(): from ldap2pg.utils import FormatList, Settable list_ = FormatList.factory([ "static", "{member.cn}", "{cn}_{member}", ]) vars_ = dict( dn=["cn=toto,ou=groups"], cn=["toto"], member=[ Settable(_str="a", cn="a"), Settable(_str="b", cn="b"), ], ) values = list(list_.expand(vars_)) assert 5 == len(values) assert "static" in values assert "a" in values assert "b" in values assert "toto_a" in values assert "toto_b" in values
def test_role_rule(): from ldap2pg.role import RoleRule from ldap2pg.utils import Settable r = RoleRule( names=['static', 'prefix_{cn}', '{uid}_{member}'], parents=['{uid}', '{member.cn}'], members=[], comment='From {dn}', options={'SUPERUSER': True}, ) assert 5 == len(r.all_fields) assert repr(r) d = r.as_dict() assert 'SUPERUSER' in d['options'] assert ['static', 'prefix_{cn}', '{uid}_{member}'] == d['names'] assert [] == d['members'] assert ['{uid}', '{member.cn}'] == d['parents'] assert 'From {dn}' == d['comment'] vars_ = dict( dn=['cn=group,ou=groups'], cn=['cn'], uid=['uid'], member=[ Settable(_str='cn=m0', cn=['m0']), Settable(_str='cn=m1', cn=['m1']), ], ) roles = list(r.generate(vars_)) assert 4 == len(roles)
def test_settable(): from ldap2pg.utils import Settable my = Settable(toto='titi') assert 'titi' == my.toto assert 'toto=titi' in repr(my)