Exemple #1
0
def test_create_company():
    c = Company()
    c.name = 'test name'

    db.session.add(c)

    db.session.commit()

    db_c = Company.query.filter_by(name='test name').first()

    assert db_c == c
Exemple #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
Exemple #3
0
def test_company_owner(clean_db):
    name = 'Test Company'
    company = Company()
    company.name = name

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

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

    company.set_company_owner(user1)
    db.session.commit()

    db_company = Company.query.filter_by(name=name).first()

    assert user1 == db_company.owner
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)
Exemple #5
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
def test_user_access_to_assets(client, clean_db, user):
    """Test if the user can see the company settings"""
    create_company()

    company = Company.load_company_by_name(user['company'])
    company.add_asset(user['asset'])

    check_string = user['check']

    login_user(user, client)

    response = client.get(url_for('main.test_asset', asset=user['asset']),
                          follow_redirects=True)

    answer = check_string in response.data

    assert answer == user['response']
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()