def test_season_insert(session): """Season 001: Insert records into Seasons table and verify data.""" yr_1994 = mco.Years(yr=1994) yr_1995 = mco.Years(yr=1995) season_94 = mco.Seasons(start_year=yr_1994, end_year=yr_1994) season_9495 = mco.Seasons(start_year=yr_1994, end_year=yr_1995) session.add(season_94) session.add(season_9495) seasons_from_db = [repr(obj) for obj in session.query(mco.Seasons).all()] seasons_test = ["<Season(1994)>", "<Season(1994-1995)>"] assert set(seasons_from_db) & set(seasons_test) == set(seasons_test)
def test_season_singleyr_reference_date(session): """Season 005: Verify that reference date for season over one year is December 31.""" yr_1994 = mco.Years(yr=1994) season_94 = mco.Seasons(start_year=yr_1994, end_year=yr_1994) session.add(season_94) record = session.query( mco.Seasons).filter(mco.Seasons.start_year == yr_1994).one() assert record.reference_date == date(1994, 12, 31)
def test_season_singleyr_search(session): """Season 002: Retrieve Season record using multi-year season name.""" yr_1994 = mco.Years(yr=1994) season_94 = mco.Seasons(start_year=yr_1994, end_year=yr_1994) session.add(season_94) record = session.query( mco.Seasons).filter(mco.Seasons.name == '1994').one() assert repr(season_94) == repr(record)
def test_season_multiyr_reference_date(session): """Season 003: Verify that reference date for season across two years is June 30.""" yr_1994 = mco.Years(yr=1994) yr_1995 = mco.Years(yr=1995) season_9495 = mco.Seasons(start_year=yr_1994, end_year=yr_1995) session.add(season_9495) record = session.query( mco.Seasons).filter(mco.Seasons.start_year == yr_1994).one() assert record.reference_date == date(1995, 6, 30)
def seasons(self, data_frame): season_records = [] map_records = [] for idx, row in data_frame.iterrows(): if 'name' not in row: if row['start_year'] == row['end_year']: yr_obj = self.session.query( mco.Years).filter_by(yr=row['start_year']).one() if not self.record_exists(mco.Seasons, start_year_id=yr_obj.id, end_year_id=yr_obj.id): season_records.append( mco.Seasons(start_year=yr_obj, end_year=yr_obj)) else: start_yr_obj = self.session.query( mco.Years).filter_by(yr=row['start_year']).one() end_yr_obj = self.session.query( mco.Years).filter_by(yr=row['end_year']).one() if not self.record_exists(mco.Seasons, start_year_id=start_yr_obj.id, end_year_id=end_yr_obj.id): season_records.append( mco.Seasons(start_year=start_yr_obj, end_year=end_yr_obj)) self.session.add_all(season_records) else: if not self.record_exists(mcs.SeasonMap, remote_id=row['remote_id'], supplier_id=self.supplier_id): map_records.append( mcs.SeasonMap(id=self.get_id(mco.Seasons, name=row['name']), remote_id=row['remote_id'], supplier_id=self.supplier_id)) self.session.add_all(map_records) self.session.commit()
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) }
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]) }
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) }