Example #1
0
def test_grant_rule():
    from ldap2pg.privilege import GrantRule

    r = GrantRule(
        privilege='{extensionAttribute0}',
        databases=['{extensionAttribute1}'],
        schemas=['{cn}'],
        roles=['{cn}'],
    )

    map_ = r.attributes_map
    assert '__self__' in map_
    assert 'extensionAttribute0' in map_['__self__']
    assert 'extensionAttribute1' in map_['__self__']
    assert 'cn' in map_['__self__']

    assert repr(r)

    d = r.as_dict()
    assert '{extensionAttribute0}' == d['privilege']
    assert ['{extensionAttribute1}'] == d['databases']
    assert ['{cn}'] == d['schemas']
    assert ['{cn}'] == d['roles']

    vars_ = dict(__self__=[dict(
        cn=['rol0', 'rol1'],
        extensionAttribute0=['ro'],
        extensionAttribute1=['appdb'],
    )])
    grants = list(r.generate(vars_))
    assert 2 == len(grants)
Example #2
0
def test_grant_rule():
    from ldap2pg.privilege import GrantRule

    r = GrantRule(
        privilege='{extensionAttribute0}',
        databases=['{extensionAttribute1}'],
        schemas=['{cn}'],
        roles=['{cn}'],
    )

    assert 3 == len(r.all_fields)
    assert repr(r)

    d = r.as_dict()
    assert '{extensionAttribute0}' == d['privilege']
    assert ['{extensionAttribute1}'] == d['databases']
    assert ['{cn}'] == d['schemas']
    assert ['{cn}'] == d['roles']

    vars_ = dict(
        cn=['rol0', 'rol1'],
        extensionAttribute0=['ro'],
        extensionAttribute1=['appdb'],
    )
    grants = list(r.generate(vars_))
    assert 2 == len(grants)