def test_expand_defacl(): from ldap2pg.privilege import DefAcl, Acl, Grant, UserError priv = DefAcl('select', grant='ALTER FOR GRANT SELECT') item0 = Grant('select', Grant.ALL_DATABASES, schema=Grant.ALL_SCHEMAS) item1 = Grant('select', ['postgres'], schema=['information_schema']) assert repr(item0.schema) set_ = Acl([item0, item1]) items = sorted( set_.expandgrants( aliases=dict(select=['select']), privileges={priv.name: priv}, databases=dict( postgres=dict(information_schema=['postgres'], ), template1=dict(information_schema=['postgres'], ), ), ), key=lambda x: x.dbname, ) assert 3 == len(items) assert 'postgres' == items[0].dbname assert 'template1' == items[2].dbname with pytest.raises(UserError): list( set_.expandgrants( aliases=dict(select=['select']), privileges={priv.name: priv}, databases=dict(), ))
def test_expand_nok(): from ldap2pg.privilege import Acl, Grant set_ = Acl([Grant('inexistant')]) with pytest.raises(ValueError): list(set_.expandgrants( aliases=dict(), privileges=dict(), databases=dict(), )) set_ = Acl([Grant('inexistant_dep')]) with pytest.raises(ValueError): list(set_.expandgrants( aliases=dict(inexistant_dep=['inexistant']), privileges=dict(), databases=dict(), ))