def test_season_multiyr_search(session): """Season 002: Retrieve Season record using multi-year season name.""" 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.name == '1994-1995').one() assert repr(season_9495) == 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 test_year_duplicate_error(session): """Year 002: Verify error if year is inserted twice in Years table.""" for yr in range(1992, 1995): record = mco.Years(yr=yr) session.add(record) duplicate = mco.Years(yr=1994) with pytest.raises(IntegrityError): session.add(duplicate) session.commit()
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 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 years(self, data_frame): year_records = [ mco.Years(**data_row) for idx, data_row in data_frame.iterrows() if not self.record_exists(mco.Years, yr=data_row['yr']) ] self.session.add_all(year_records) self.session.commit()
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 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) }
def test_year_insert(session): """Year 001: Insert multiple years into Years table and verify data.""" years_list = range(1990, 1994) for yr in years_list: record = mco.Years(yr=yr) session.add(record) years = session.query(mco.Years.yr).all() years_from_db = [x[0] for x in years] assert set(years_from_db) & set(years_list) == set(years_list)
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]) }