Ejemplo n.º 1
0
def test_lineup_designate_captain(session, match_data, person_data,
                                  position_data):
    capn_indx = 1
    lineups = [
        mcm.MatchLineups(match=mcm.Matches(**match_data),
                         player=mcp.Players(**plyr),
                         position=pos,
                         is_starting=True,
                         is_captain=(j == capn_indx))
        for j, (plyr,
                pos) in enumerate(zip(person_data['player'], position_data))
    ]
    session.add_all(lineups)

    capn_position = position_data[capn_indx]

    lineup_from_db = session.query(mcm.MatchLineups).join(
        mcp.Positions).filter(mcp.Positions.name == capn_position.name).all()
    assert len(lineup_from_db) == 1
    assert lineup_from_db[0].is_captain is True

    other_lineup_from_db = session.query(mcm.MatchLineups).join(
        mcp.Positions).filter(mcp.Positions.name != capn_position.name).all()
    for others in other_lineup_from_db:
        assert others.is_captain is False
Ejemplo n.º 2
0
def test_substitutions_insert(session, match_lineup, person_data):
    match_from_db, lineup_from_db = match_lineup

    bench_lineup = mcm.MatchLineups(
        match_id=match_from_db.id,
        player=mcp.Players(**person_data['generic']),
        position=mcp.Positions(name=u"Center back",
                               type=enums.PositionType.defender),
        is_starting=False,
        is_captain=False)
    session.add(bench_lineup)
    session.commit()

    substitution = mce.Substitutions(lineup_in_id=bench_lineup.id,
                                     lineup_out_id=lineup_from_db.id,
                                     time=67)
    session.add(substitution)

    lineup_alias = aliased(mcm.MatchLineups)
    substitution_from_db = session.query(mce.Substitutions)\
        .join(mcm.MatchLineups, mcm.MatchLineups.id == mce.Substitutions.lineup_in_id)\
        .join(lineup_alias, lineup_alias.id == mce.Substitutions.lineup_out_id)\
        .join(mcm.Matches).filter(mcm.Matches.id == match_from_db.id)

    assert substitution_from_db.count() == 1
    assert substitution_from_db[0].lineup_out.full_name == u"Cristiano Ronaldo"
    assert substitution_from_db[0].lineup_in.full_name == u"John Doe"
    assert substitution_from_db[0].time == 67
Ejemplo n.º 3
0
def test_match_lineup_generic_insert(session, match_data, person_data,
                                     position_data):
    lineup = mcm.MatchLineups(match=mcm.Matches(**match_data),
                              player=mcp.Players(**person_data['player'][1]),
                              position=position_data[1])
    session.add(lineup)

    lineup_from_db = session.query(mcm.MatchLineups).one()
    match_from_db = session.query(mcm.Matches).one()
    player_from_db = session.query(mcp.Players).one()

    assert lineup_from_db.is_starting is False
    assert lineup_from_db.is_captain is False
    assert lineup_from_db.match_id == match_from_db.id
    assert lineup_from_db.player_id == player_from_db.id
Ejemplo n.º 4
0
def match_lineup(session, match_data, person_data, position_data):
    match = mcm.Matches(**match_data)
    session.add(match)

    match_from_db = session.query(mcm.Matches).one()

    lineups = [
        mcm.MatchLineups(match_id=match_from_db.id,
                         player=mcp.Players(**plyr),
                         position=pos,
                         is_starting=True,
                         is_captain=False)
        for j, (plyr,
                pos) in enumerate(zip(person_data['player'], position_data))
    ]
    session.add_all(lineups)

    scorer_indx = 1

    lineup_from_db = session.query(mcm.MatchLineups).join(mcp.Players).\
        filter(mcp.Players.last_name == person_data['player'][scorer_indx]['last_name']).one()

    return match_from_db, lineup_from_db