Example #1
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
Example #2
0
def test_position_insert(session):
    """Positions 001: Insert generic data into Positions model and verify data."""
    left_fb = mcp.Positions(name="Left full-back",
                            type=enums.PositionType.defender)
    session.add(left_fb)

    position_from_db = session.query(mcp.Positions).one()
    assert repr(
        position_from_db) == u"<Position(name=Left full-back, type=Defender)>"
Example #3
0
def test_player_history_insert(session, person_data, player_history_data):
    player_data = dict(position=mcp.Positions(
        name='Central Midfielder', type=enums.PositionType.midfielder),
                       **person_data['generic'])
    generic_player = mcp.Players(**player_data)
    player_history = [
        mcp.PlayerHistory(**dict(player=generic_player, **data))
        for data in player_history_data
    ]
    session.add_all(player_history)

    history_from_db = session.query(mcp.PlayerHistory).join(mcp.Players).\
        filter(mcp.Players.last_name == u"Doe")

    assert history_from_db.count() == len(player_history)
Example #4
0
def test_player_history_representation(session, person_data,
                                       player_history_data):
    player_data = dict(position=mcp.Positions(
        name='Central Midfielder', type=enums.PositionType.midfielder),
                       **person_data['generic'])
    generic_player = mcp.Players(**player_data)
    player_history = [
        mcp.PlayerHistory(**dict(player=generic_player, **data))
        for data in player_history_data
    ]
    session.add_all(player_history)

    history_from_db = session.query(mcp.PlayerHistory).join(mcp.Players).\
        filter(mcp.Players.last_name == u"Doe", mcp.PlayerHistory.date == date(1998, 7, 15)).one()

    assert repr(
        history_from_db
    ) == u"<PlayerHistory(name=John Doe, date=1998-07-15, height=1.74, weight=76)>"
Example #5
0
def position_data():
    return [
        mcp.Positions(name=u"Left back", type=enums.PositionType.defender),
        mcp.Positions(name=u"Forward", type=enums.PositionType.forward),
        mcp.Positions(name=u"Second striker", type=enums.PositionType.forward)
    ]
Example #6
0
def test_position_blank_error(session):
    """Positions 002: Verify error if blank name in Positions model."""
    left_fb = mcp.Positions(type=enums.PositionType.defender)
    with pytest.raises(IntegrityError):
        session.add(left_fb)
        session.commit()