Ejemplo n.º 1
0
Archivo: load.py Proyecto: lkh/marcotti
 def venues(self, data_frame):
     remote_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_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'])
     self.session.add_all(venue_records)
     self.session.add_all(history_records)
     self.session.commit()
     map_records = [
         mcs.VenueMap(id=venue_record.id,
                      remote_id=remote_id,
                      supplier_id=self.supplier_id)
         for remote_id, venue_record in zip(remote_ids, venue_records)
         if remote_id
     ]
     self.session.bulk_save_objects(map_records)
     self.session.commit()
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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