Ejemplo n.º 1
0
def test_user_salts_are_random():
    u = User()
    u.password = '******'
    u2 = User()
    u2.password = '******'

    assert u.password_hash != u2.password_hash
Ejemplo n.º 2
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        username = form.username.data

        user = User(email=email, username=username)
        user.password = form.password.data

        company = Company()
        company.name = form.company.data

        db.session.add(user)
        db.session.add(company)

        company.set_company_owner(user)
        company.add_user(user)

        db.session.commit()
        token = user.generate_confirmation_token()
        send_email(user.email, 'Confirm Your Account',
                   'auth/email/confirm', user=user, token=token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 3
0
def test_valid_confirmation_token(clean_db):
    u = User()
    u.password = '******'
    db.session.add(u)
    db.session.commit()

    token = u.generate_confirmation_token()

    assert u.confirm(token)
def test_user_login_redirects_to_index(client, user):
    u = User()
    u.email = user['email']
    u.password = user['password']
    u.confirmed = True
    db.session.add(u)
    db.session.commit()
    data = {'email': user['email'], 'password': user['password']}
    response = client.post(url_for('auth.login'),
                           data=data,
                           follow_redirects=True)

    assert b'<h1>Page Header</h1>' in response.data
def test_login_required(clean_db, client, path):
    u = User()
    u.password = '******'
    u.email = '*****@*****.**'
    u.confirmed = True

    response = client.post(url_for('auth.login'),
                           data={
                               'email': '*****@*****.**',
                               'password': '******'
                           },
                           follow_redirects=True)

    assert client.get(url_for(path), follow_redirects=True).status_code == 200
Ejemplo n.º 6
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data
        username = form.username.data

        user = User(email=email, username=username)
        user.password = form.password.data

        db.session.add(user)

        db.session.commit()
        flash('You have been signed up. Please login.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)
Ejemplo n.º 7
0
def test_user_password_setter():
    u = User()
    u.password = '******'
    assert u.password_hash is not None
Ejemplo n.º 8
0
def test_user_password_verification():
    u = User()
    u.password = '******'
    assert u.verify_password('cat')
    assert not u.verify_password('dog')
Ejemplo n.º 9
0
def test_user_no_password_getter():
    u = User()
    u.password = '******'
    with pytest.raises(AttributeError):
        b = u.password