Ejemplo n.º 1
0
def test_venue_altitude_error(session, venue_data):
    """Venue 005: Verify error if altitude of match venue is out of range."""
    for out_of_range in [-205, 4600]:
        venue_data['altitude'] = out_of_range
        venue = mco.Venues(**venue_data)
        with pytest.raises(IntegrityError):
            session.add(venue)
            session.commit()
        session.rollback()
Ejemplo n.º 2
0
def test_venue_longitude_error(session, venue_data):
    """Venue 004: Verify error if longitude of match venue exceeds range."""
    for direction in [-1, 1]:
        venue_data['longitude'] = 200.000000 * direction
        venue = mco.Venues(**venue_data)
        with pytest.raises(IntegrityError):
            session.add(venue)
            session.commit()
        session.rollback()
Ejemplo n.º 3
0
def test_venue_history_capacity_error(session, venue_data, venue_config):
    """Venue 007: Verify error if length/width fields in VenueHistory data are out of range."""
    emirates = mco.Venues(**venue_data)
    venue_config['venue'] = emirates
    for field in ['capacity', 'seats']:
        new_venue_config = dict(venue_config, **{field: -1})
        emirates_config = mco.VenueHistory(**new_venue_config)
        with pytest.raises(IntegrityError):
            session.add(emirates_config)
            session.commit()
        session.rollback()
Ejemplo n.º 4
0
def test_venue_empty_coordinates(session, venue_data):
    """Venue 002: Verify that lat/long/alt coordinates are zeroed if not present in Venues object definition."""
    revised_venue_data = {key: value for key, value in venue_data.items()
                          if key not in ['latitude', 'longitude', 'altitude']}
    session.add(mco.Venues(**revised_venue_data))

    emirates = session.query(mco.Venues).one()

    assert emirates.latitude == 0.000000
    assert emirates.longitude == 0.000000
    assert emirates.altitude == 0
Ejemplo n.º 5
0
def test_venue_history_field_dimension_error(session, venue_data, venue_config):
    """Venue 007: Verify error if length/width fields in VenueHistory data are out of range."""
    emirates = mco.Venues(**venue_data)
    venue_config['venue'] = emirates
    for field, values in zip(['length', 'width'], [(85, 125), (40, 95)]):
        for out_of_range in values:
            venue_config[field] = out_of_range
            emirates_config = mco.VenueHistory(**venue_config)
            with pytest.raises(IntegrityError):
                session.add(emirates_config)
                session.commit()
            session.rollback()
Ejemplo n.º 6
0
def test_venue_generic_insert(session, venue_data):
    """Venue 001: Insert generic venue records into Venues table and verify data."""
    session.add(mco.Venues(**venue_data))

    emirates = session.query(mco.Venues).one()

    assert repr(emirates) == u"<Venue(name=Emirates Stadium, city=London, country=England)>"
    assert emirates.region is None
    assert emirates.latitude == 51.555000
    assert emirates.longitude == -0.108611
    assert emirates.altitude == 41
    assert repr(emirates.timezone) == "<Timezone(name=Europe/London, offset=+0.00, confederation=UEFA)>"
Ejemplo n.º 7
0
def test_venue_history_insert(session, venue_data, venue_config):
    """Venue 006: Insert venue history data into VenueHistory model and verify data."""
    emirates = mco.Venues(**venue_data)
    venue_config['venue'] = emirates
    emirates_config = mco.VenueHistory(**venue_config)
    session.add(emirates_config)

    record = session.query(mco.VenueHistory).one()

    assert repr(record) == u"<VenueHistory(name=Emirates Stadium, date=2006-07-22, " \
                           u"length=105, width=68, capacity=60361)>"
    assert record.seats == 60361
    assert record.surface.description == u"Desso GrassMaster"
    assert record.surface.type == enums.SurfaceType.hybrid
Ejemplo n.º 8
0
def test_venue_history_empty_numbers(session, venue_data, venue_config):
    """Venue 007: Verify that length/width/capacity/seats fields are set to default if missing in VenueHistory data."""
    emirates = mco.Venues(**venue_data)
    venue_config['venue'] = emirates
    revised_venue_config = {key: value for key, value in venue_config.items()
                            if key not in ['length', 'width', 'capacity', 'seats']}
    emirates_config = mco.VenueHistory(**revised_venue_config)
    session.add(emirates_config)

    record = session.query(mco.VenueHistory).one()

    assert record.length == 105
    assert record.width == 68
    assert record.capacity == 0
    assert record.seats == 0
Ejemplo n.º 9
0
def national_data():
    mexico = mco.Countries(name=u"Mexico",
                           confederation=enums.ConfederationType.north_america)
    england = mco.Countries(name=u"England",
                            confederation=enums.ConfederationType.europe)
    france = mco.Countries(name=u"France",
                           confederation=enums.ConfederationType.europe)
    italy = mco.Countries(name=u"Italy",
                          confederation=enums.ConfederationType.europe)
    tz_london = mco.Timezones(name=u"Europe/London",
                              offset=0.0,
                              confederation=enums.ConfederationType.europe)
    return {
        'date':
        date(1997, 11, 12),
        'competition':
        mco.InternationalCompetitions(
            name=u"International Cup",
            level=1,
            confederation=enums.ConfederationType.fifa),
        'season':
        mco.Seasons(start_year=mco.Years(yr=1997),
                    end_year=mco.Years(yr=1998)),
        'venue':
        mco.Venues(name=u"Emirates Stadium",
                   city=u"London",
                   country=england,
                   timezone=tz_london),
        'home_team':
        france,
        'away_team':
        mexico,
        'home_manager':
        mcp.Managers(first_name=u"Arsène",
                     last_name=u"Wenger",
                     birth_date=date(1949, 10, 22),
                     country=france),
        'away_manager':
        mcp.Managers(first_name=u"Gary",
                     last_name=u"Simpson",
                     birth_date=date(1961, 4, 11),
                     country=england),
        'referee':
        mcp.Referees(first_name=u"Pierluigi",
                     last_name=u"Collina",
                     birth_date=date(1960, 2, 13),
                     country=italy)
    }
Ejemplo n.º 10
0
def match_data(comp_data, season_data, venue_data, person_data):
    return {
        "date":
        date(2012, 12, 12),
        "competition":
        mco.DomesticCompetitions(**comp_data['domestic']),
        "season":
        mco.Seasons(**{k: mco.Years(**v)
                       for k, v in season_data.items()}),
        "venue":
        mco.Venues(**venue_data),
        "home_manager":
        mcp.Managers(**person_data['manager'][0]),
        "away_manager":
        mcp.Managers(**person_data['manager'][1]),
        "referee":
        mcp.Referees(**person_data['referee'][0])
    }
Ejemplo n.º 11
0
def club_data():
    england = mco.Countries(name=u"England",
                            confederation=enums.ConfederationType.europe)
    france = mco.Countries(name=u"France",
                           confederation=enums.ConfederationType.europe)
    tz_london = mco.Timezones(name=u"Europe/London",
                              offset=0.0,
                              confederation=enums.ConfederationType.europe)
    return {
        'date':
        date(2015, 1, 1),
        'competition':
        mco.DomesticCompetitions(name=u'Test Competition',
                                 level=1,
                                 country=england),
        'season':
        mco.Seasons(start_year=mco.Years(yr=2014),
                    end_year=mco.Years(yr=2015)),
        'venue':
        mco.Venues(name=u"Emirates Stadium",
                   city=u"London",
                   country=england,
                   timezone=tz_london),
        'home_team':
        mc.Clubs(name=u"Arsenal FC", country=england),
        'away_team':
        mc.Clubs(name=u"Lincoln City FC", country=england),
        'home_manager':
        mcp.Managers(first_name=u"Arsène",
                     last_name=u"Wenger",
                     birth_date=date(1949, 10, 22),
                     country=france),
        'away_manager':
        mcp.Managers(first_name=u"Gary",
                     last_name=u"Simpson",
                     birth_date=date(1961, 4, 11),
                     country=england),
        'referee':
        mcp.Referees(first_name=u"Mark",
                     last_name=u"Clattenburg",
                     birth_date=date(1975, 3, 13),
                     country=england)
    }
Ejemplo n.º 12
0
    def venues(self, data_frame):
        remote_ids = []
        local_ids = []
        venue_records = []
        history_records = []
        fields = ['name', 'city', 'region', 'latitude', 'longitude', 'altitude', 'country_id', 'timezone_id']
        history_fields = ['eff_date', 'length', 'width', 'capacity', 'seats', 'surface_id']
        for idx, row in data_frame.iterrows():
            venue_dict = {field: row[field] for field in fields if row[field]}
            if not self.record_exists(mco.Venues, **venue_dict):
                venue_dict.update(id=uuid.uuid4())
                venue_records.append(mco.Venues(**venue_dict))
                history_dict = {field: row[field] for field in history_fields if row[field]}
                history_records.append(mco.VenueHistory(venue_id=venue_dict['id'], **history_dict))
                remote_ids.append(row['remote_id'])
                local_ids.append(venue_dict['id'])
        self.session.bulk_save_objects(venue_records)
        self.session.bulk_save_objects(history_records)

        map_records = [mcs.VenueMap(id=local_id, remote_id=remote_id, supplier_id=self.supplier_id)
                       for remote_id, local_id in zip(remote_ids, local_ids) if remote_id]
        self.session.bulk_save_objects(map_records)
        self.session.commit()