コード例 #1
0
def cache():
    """Empty cache."""
    try:
        current_cache.clear()
        yield current_cache
    finally:
        current_cache.clear()
コード例 #2
0
def cache():
    """Clean cache"""
    try:
        current_cache.clear()
        yield current_cache
    finally:
        current_cache.clear()
コード例 #3
0
def clear_cache(app):
    current_cache.clear()
    yield
    current_cache.clear()
コード例 #4
0
def clear_cache(app):
    current_cache.clear()
    yield
    current_cache.clear()
コード例 #5
0
def users(app):
    # Create test users
    hashed_password = hash_password('123456')
    user = User(email='*****@*****.**',
                password=hashed_password,
                active=True)
    user_partially_allowed = User(
        email='*****@*****.**',
        password=hashed_password,
        active=True,
    )
    user_allowed = User(
        email='*****@*****.**',
        password=hashed_password,
        active=True,
    )

    collection_restricted_role = Role(name='restrictedcollmaintainer')

    user_allowed_with_role = User(email='*****@*****.**',
                                  password=hashed_password,
                                  active=True,
                                  roles=[collection_restricted_role])

    db.session.add_all([
        user, user_partially_allowed, user_allowed, user_allowed_with_role,
        collection_restricted_role
    ])
    db.session.commit()

    # Create actions for the allowed user
    restricted_collection_action = ActionUsers(
        action='view-restricted-collection',
        argument='Restricted Collection',
        user_id=user_allowed.id)
    another_restricted_collection_action = ActionUsers(
        action='view-restricted-collection',
        argument='Another Restricted Collection',
        user_id=user_allowed.id)

    # Create actions for the partially allowed user
    partial_restricted_collection_action = ActionUsers(
        action='view-restricted-collection',
        argument='Restricted Collection',
        user_id=user_partially_allowed.id)

    # Create actions for the allowed role
    partial_restricted_collection_role_action = ActionRoles(
        action='view-restricted-collection',
        argument='Restricted Collection',
        role_id=collection_restricted_role.id)

    role_only_collection_action = ActionRoles(
        action='view-restricted-collection',
        argument='Role only collection',
        role_id=collection_restricted_role.id)

    db.session.add_all([
        restricted_collection_action, another_restricted_collection_action,
        partial_restricted_collection_action,
        partial_restricted_collection_role_action, role_only_collection_action
    ])
    db.session.commit()

    yield

    current_cache.clear()
    SessionActivity.query.delete()
    ActionRoles.query.filter_by(action='view-restricted-collection').delete()
    ActionUsers.query.filter_by(action='view-restricted-collection').delete()
    User.query.filter_by(email='*****@*****.**').delete()
    User.query.filter_by(email='*****@*****.**').delete()
    User.query.filter_by(email='*****@*****.**').delete()
    db.session.delete(
        Role.query.filter_by(name='restrictedcollmaintainer').one())
    db.session.delete(
        User.query.filter_by(email='*****@*****.**').one())
    db.session.commit()