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 create_match():
    if not current_user.is_authenticated:
        flash('You have to login before creating a match.')
        return redirect(url_for('index'))
    form = CreateMatchForm()
    if form.validate_on_submit():
        if not current_user in form.winners.data + form.losers.data:
            flash('Logged in user should be playing in match')
            return redirect(url_for('create_match'))
        match = tasks.make_new_match(
            timestamp=form.timestamp.data,
            winners=form.winners.data,
            losers=form.losers.data,
            w_score=form.winner_score.data,
            l_score=form.loser_score.data,
            importance=form.importance.data,
            user_creating_match=current_user,
        )
        if isinstance(match, Match):
            flash('Match created')
        else:
            flash('Something went wrong')
        return redirect(url_for('login'))
    return render_template('create_match.html',
                           title='Create match',
                           form=form)
Ejemplo n.º 3
0
def test_approve_match(filled_db):
    from app.tasks import approve_match, make_new_match
    from app.models import User

    u1, u2 = User.query.all()
    elo1, elo2 = u1.get_current_elo(), u2.get_current_elo()

    m = make_new_match(winners=[u1], losers=[u2], w_score=10, l_score=4,
        importance=16)
    
    assert elo1 == u1.get_current_elo()
    assert elo2 == u2.get_current_elo()

    assert u1.can_approve_match(m)
    assert u2.can_approve_match(m)

    approve_match(m, u1)
    assert elo1 == u1.get_current_elo()
    assert elo2 == u2.get_current_elo()
    assert not u1.can_approve_match(m)
    assert u2.can_approve_match(m)
    

    approve_match(m, u2)
    assert elo1 != u1.get_current_elo()
    assert elo2 != u2.get_current_elo()
    assert not u1.can_approve_match(m)
    assert not u2.can_approve_match(m)
Ejemplo n.º 4
0
def test_create_match(empty_db):
    from app.models import User
    from app.tasks import make_new_match

    u1 = User(shortname='kasper')
    u2 = User(shortname='felipe')
    
    m1 = make_new_match(winners=[u1], losers=[u2], w_score=10, 
        l_score=9, importance=32) # Kasper wins
    
    assert u1.matches == [m1]
    assert u1.won_matches == [m1]
    assert not u1.lost_matches == [m1]
    assert u1.won_matches == u2.lost_matches

    assert m1.players == [u1, u2]
    assert m1.winning_players == [u1]
    assert m1.losing_players == [u2]
Ejemplo n.º 5
0
def many_matches_db(filled_db):
    from app.models import User
    from app.tasks import make_new_match, approve_match
    u1, u2 = User.query.all()

    matches = [
        make_new_match(winners=[u1],
                       losers=[u2],
                       w_score=1,
                       l_score=0,
                       importance=16,
                       user_creating_match=u1) for i in range(20)
    ]
    for m in matches:
        approve_match(m, u2)

    yield filled_db
    filled_db.session.remove()
    filled_db.drop_all()