예제 #1
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)
예제 #2
0
def test_users_company_name(clean_db):
    company = Company()
    company.name = 'test name'

    user1 = User()
    user1.username = '******'

    db.session.add(user1)
    db.session.add(company)

    company.add_user(user1)

    db.session.commit()

    assert user1.company.name == company.name
예제 #3
0
def test_company_add_users(clean_db):
    company = Company()
    company.name = 'test name'

    user1 = User()
    user1.username = '******'
    user2 = User()
    user2.username = '******'

    db.session.add(user1)
    db.session.add(user2)
    db.session.add(company)

    company.add_user(user1)
    company.add_user(user2)

    users = company.users

    assert user1 in users
    assert user2 in users
예제 #4
0
def sample_data():
    set_up()

    user1 = User(username='******',
                 email='*****@*****.**',
                 password='******',
                 confirmed=True)
    user2 = User(username='******',
                 email='*****@*****.**',
                 password='******',
                 confirmed=True)
    user3 = User(username='******',
                 email='*****@*****.**',
                 password='******',
                 confirmed=True)
    user4 = User(username='******',
                 email='*****@*****.**',
                 password='******',
                 confirmed=True)

    company1 = Company(name='ExampleCompanyOne.com')
    company2 = Company(name='ExampleCompanyTwo.com')

    db.session.add(user1)
    db.session.add(user2)
    db.session.add(user3)
    db.session.add(user4)

    company1.add_user(user1)
    company1.add_user(user2)
    company1.set_company_owner(user1)
    company1.add_asset('company1_asset')
    db.session.add(company1)

    company2.add_user(user3)
    company2.add_user(user4)
    company2.set_company_owner(user3)
    company2.add_asset('company2_asset')
    db.session.add(company2)

    db.session.commit()