Пример #1
0
def test_undo_match(g):
    p = Player("test player")
    p2 = Player("test player 2")
    player_dao.create(p)
    p.id = 1
    player_dao.create(p2)
    p2.id = 2
    t = Tournament(0,'','T1','type',0)
    tournament_dao.create(t)
    t.id = 1
    match_dao.create([p.id, p2.id], t.id)
    match_id = 1
    match = Match(player1=p,player2=p2,id=match_id)
    match.score1 = 19
    match.score2 = 21
    match_dao.update(match)

    match_dao.undo(match)
    retrieved_match = match_dao.find(match_id)
    matches = match_dao.find_by_tournament(t.id)

    assert retrieved_match.score1 == 0
    assert retrieved_match.score2 == 0
    assert retrieved_match.player1.fname == p.fname
    assert retrieved_match.player2.fname == p2.fname
    assert retrieved_match.player1.id == p.id
    assert retrieved_match.player2.id == p2.id
    assert not matches[0].entered_time
Пример #2
0
def test_standings(g):
    p = Player("test player")
    p2 = Player("test player 2")
    p3 = Player("test player 3")
    player_dao.create(p)
    p.id = 1
    player_dao.create(p2)
    p2.id = 2
    player_dao.create(p3)
    p3.id = 3
    t = Tournament(0,'','T1','type',0)
    tournament_dao.create(t)
    t.id = 1
    match_dao.create([p.id, p2.id], t.id)
    match_dao.create([p.id, p3.id], t.id)
    match_dao.create([p3.id, p2.id], t.id)
    match = Match(player1=p,player2=p2,id=1)
    match.score1 = 19
    match.score2 = 21
    match2 = Match(player1=p,player2=p3,id=2)
    match2.score1 = 17
    match2.score2 = 21
    match3 = Match(player1=p3,player2=p2,id=3)
    match3.score1 = 23
    match3.score2 = 21

    match_dao.update(match)
    match_dao.update(match2)
    match_dao.update(match3)
    standings = standings_dao.find(t.id)

    assert standings[0].name == p.fname
    assert standings[0].win == 0
    assert standings[0].loss == 2
    assert standings[1].name == p2.fname
    assert standings[1].win == 1
    assert standings[1].loss == 1
    assert standings[2].name == p3.fname
    assert standings[2].win == 2
    assert standings[2].loss == 0
Пример #3
0
def find(id):
    select = """
    select p.fname, p.id, a.score, m.entered_time 
    from player p, attempt a, match m
    where p.id = a.player_id 
    and a.match_id = ?
    and m.id = a.match_id
    """
    m = Match(id=id)
    cur = g.db.execute(select, [id])
    attempts = cur.fetchall()
    player1 = Player(*attempts[0][:2])
    m.player1 = player1
    m.score1 = attempts[0][2]
    player2 = Player(*attempts[1][:2])
    m.player2 = player2
    m.score2 = attempts[1][2]
    m.entered_time = attempts[0][-1]
    return m