Exemplo n.º 1
0
def users(db):
    """
    Create user fixtures. They reset per test.

    :param db: Pytest fixture
    :return: SQLAlchemy database session
    """
    db.session.query(User).delete()

    users = [{
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******'
    }, {
        'active': False,
        'email': '*****@*****.**',
        'password': '******'
    }]

    for user in users:
        db.session.add(User(**user))

    db.session.commit()

    return db
Exemplo n.º 2
0
def signup():
    form = SignupForm()

    if form.validate_on_submit():
        u = User()

        form.populate_obj(u)
        u.password = User.encrypt_password(request.form.get('password'))
        u.save()

        if login_user(u):
            flash('Awesome, thanks for signing up!', 'success')
            return redirect(url_for('user.welcome'))

    return render_template('user/signup.html', form=form)
Exemplo n.º 3
0
def seed():
    """
    Seed the database with an initial user.

    :return: User instance
    """

    if User.find_by_identity(app.config['SEED_ADMIN_EMAIL']) is not None:
        return None

    params = {
        'role': 'admin',
        'email': app.config['SEED_ADMIN_EMAIL'],
        'password': app.config['SEED_ADMIN_PASSWORD']
    }

    return User(**params).save()
Exemplo n.º 4
0
def db(app):
    """
    Setup our database, this only gets executed once per session.

    :param app: Pytest fixture
    :return: SQLAlchemy database session
    """
    _db.drop_all()
    _db.create_all()

    # Create a single user because a lot of tests do not mutate this user.
    # It will result in faster tests.
    params = {
        'role': 'admin',
        'email': '*****@*****.**',
        'password': '******'
    }

    admin = User(**params)

    _db.session.add(admin)
    _db.session.commit()

    return _db