Ejemplo n.º 1
0
def filled_db(empty_db):
    from app.models import User
    from app.tasks import make_new_match, create_user, approve_match

    u1 = create_user(shortname='kasper', nickname='7-11', password='******')
    u2 = create_user(shortname='felipe', nickname='coyote', password='******')

    m1 = make_new_match(winners=[u1],
                        losers=[u2],
                        w_score=10,
                        l_score=9,
                        importance=32,
                        user_creating_match=u1)  # Kasper wins
    m2 = make_new_match(winners=[u1],
                        losers=[u2],
                        w_score=10,
                        l_score=9,
                        importance=16,
                        user_creating_match=u1)  # Kasper wins
    m3 = make_new_match(winners=[u2],
                        losers=[u1],
                        w_score=10,
                        l_score=9,
                        importance=16,
                        user_creating_match=u1)  # Felipe Wins

    approve_match(m1, u2)
    approve_match(m2, u2)
    approve_match(m3, u2)
    yield empty_db
    empty_db.session.remove()
    empty_db.drop_all()
Ejemplo n.º 2
0
 def index(self):
     from app.tasks import create_user
     admins = User.query.filter(User.is_admin).all()
     if len(admins) == 0:
         create_user(shortname = "ADMIN", nickname = "admin", password = "******", company = None, is_admin = 1)
     if (not flask_login.current_user.is_authenticated) or (not flask_login.current_user.is_admin):
         return redirect(url_for('index'))
     return super(MyAdminIndexView, self).index()
Ejemplo n.º 3
0
def test_create_user(filled_db):
    from app.tasks import create_user

    u1 = create_user('NU', 'New User', 'hunter2')

    assert u1.shortname == 'NU'
    assert u1.password_hash != 'hunter2'

    with pytest.raises(AssertionError):
        u1 = create_user('NU', 'New User', 'hunter2')
Ejemplo n.º 4
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = tasks.create_user(shortname=form.shortname.data.upper(),
                                 nickname=form.nickname.data,
                                 password=form.password.data)
        if isinstance(user, User):
            flash('Congratulations! You are registered.')
        else:
            flash('Something went wrong')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Ejemplo n.º 5
0
def test_user_page(test_client, filled_db):
    # Test loading one user page
    response = test_client.get('/user/1')
    assert response.status_code == 200
    assert b'User' in response.data
    assert b'UserID: 1' in response.data

    # Test 404 error for wrong user id
    response = test_client.get('/user/1000')
    assert response.status_code == 404

    # Test undefined winrate when no matches played
    from app.tasks import create_user
    u = create_user(shortname='NM', nickname='No matches', password='******')
    response = test_client.get(f'/user/{u.id}')
    assert response.status_code == 200
    assert b'Winrate: Undefined' in response.data