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)
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()
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()
def route_approve_match(match_id): match = Match.query.filter_by(id=match_id).first_or_404() msg = tasks.approve_match(match, approver=current_user) flash(msg) return redirect(url_for('index'))