Пример #1
0
def test_merge():
    from ldap2pg.role import Role

    a = Role(name='daniel', parents=['group0'])
    b = Role(name='daniel', parents=['group1'])
    c = Role(name='daniel', members=['group2'])

    a.merge(b)
    assert 2 == len(a.parents)

    a.merge(c)
    assert 1 == len(a.members)
Пример #2
0
def test_merge_options():
    from ldap2pg.role import Role

    a = Role(name='daniel', options=dict(SUPERUSER=True))
    b = Role(name='daniel', options=dict(SUPERUSER=False))
    c = Role(name='daniel', options=dict(SUPERUSER=None))
    d = Role(name='daniel', options=dict(SUPERUSER=None))

    with pytest.raises(ValueError):
        a.merge(b)

    # True is kept
    a.merge(c)
    assert a.options['SUPERUSER'] is True
    # False is kept
    b.merge(c)
    assert b.options['SUPERUSER'] is False
    # None is kept
    c.merge(d)
    assert c.options['SUPERUSER'] is None
    # None is replaced.
    d.merge(a)
    assert d.options['SUPERUSER'] is True