Exemple #1
0
def test_permissions_with_is_the_same_condition():
    guard = Guard()
    role = Role()
    role.grant('check_for_something', Store, is_the_same_condition)
    identity = Identity([role])
    identity.something = 'check'

    store = Store()
    store.something = 'check'
    assert_true(guard.can(identity, 'check_for_something', store))
    store.something = 2
    assert_false(guard.can(identity, 'check_for_somethingone', store))
    store.something = True
    assert_false(guard.can(identity, 'check_for_somethingone', store))
Exemple #2
0
def test_predicate():
    guard = Guard()
    store = Store(owner_id=1)

    role = Role()
    role.grant('delete', Store, condition=lambda store, identity: identity.id == store.owner_id)

    valid_identity = Identity([role])
    valid_identity.id = 1

    invalid_identity = Identity([role])
    invalid_identity.id = 2

    assert_true(guard.can(valid_identity, 'delete', store))
    assert_false(guard.can(invalid_identity, 'delete', store))