Exemple #1
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)
    }
Exemple #2
0
def test_club_name_overflow(session):
    too_long_name = "blahblah" * 8
    too_long_club = mc.Clubs(name=too_long_name,
                             country=mco.Countries(
                                 name=u"foo",
                                 confederation=enums.ConfederationType.fifa))
    with pytest.raises(DataError):
        session.add(too_long_club)
        session.commit()
Exemple #3
0
def test_country_code_error(session):
    too_long_code = "BOGUS"
    country = mco.Countries(
        name=unicode("Fredonia"),
        code=too_long_code,
        confederation=enums.ConfederationType.south_america)
    with pytest.raises(DataError):
        session.add(country)
        session.commit()
Exemple #4
0
def test_country_name_overflow_error(session):
    """Country 003: Verify error if country name exceeds field length."""
    too_long_name = "blahblah" * 8
    too_long_country = mco.Countries(
        name=unicode(too_long_name),
        confederation=enums.ConfederationType.north_america)
    with pytest.raises(DataError):
        session.add(too_long_country)
        session.commit()
Exemple #5
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)
    }
Exemple #6
0
def test_club_insert(session):
    club = mc.Clubs(name=u"Arsenal",
                    country=mco.Countries(
                        name=u"England",
                        confederation=enums.ConfederationType.europe))
    session.add(club)

    result = session.query(mc.Clubs).one()
    assert result.name == u"Arsenal"
    assert repr(result) == "<Club(name=Arsenal, country=England)>"
Exemple #7
0
def test_country_unicode_insert(session):
    """Country 002: Insert a single record with Unicode characters into Countries table and verify data."""
    ivory_coast = mco.Countries(name=u"Côte d'Ivoire",
                                confederation=enums.ConfederationType.africa)
    session.add(ivory_coast)

    country = session.query(mco.Countries).filter_by(
        confederation=enums.ConfederationType.africa).one()

    assert country.name == u"Côte d'Ivoire"
    assert country.confederation.value == 'CAF'
Exemple #8
0
def test_club_unicode_insert(session):
    club = mc.Clubs(name=u"Фк Спартак Москва",
                    country=mco.Countries(
                        name=u"Russia",
                        confederation=enums.ConfederationType.europe))
    session.add(club)

    result = session.query(mc.Clubs).join(
        mco.Countries).filter(mco.Countries.name == u"Russia").one()

    assert result.name == u"Фк Спартак Москва"
    assert unicode(result) == u"<Club(name=Фк Спартак Москва, country=Russia)>"
Exemple #9
0
def venue_data():
    england = mco.Countries(name=u"England",
                            confederation=enums.ConfederationType.europe)
    tz_london = mco.Timezones(name=u"Europe/London",
                              offset=0.0,
                              confederation=enums.ConfederationType.europe)
    return {
        "name": u"Emirates Stadium",
        "city": u"London",
        "country": england,
        "timezone": tz_london,
        "latitude": 51.555000,
        "longitude": -0.108611,
        "altitude": 41
    }
Exemple #10
0
def test_country_insert(session):
    """Country 001: Insert a single record into Countries table and verify data."""
    england = mco.Countries(name=u'England',
                            code="ENG",
                            confederation=enums.ConfederationType.europe)
    session.add(england)

    country = session.query(mco.Countries).all()

    assert country[0].name == u'England'
    assert country[0].code == "ENG"
    assert country[0].confederation.value == 'UEFA'
    assert repr(
        country[0]
    ) == "<Country(id={0}, name=England, trigram=ENG, confed=UEFA)>".format(
        country[0].id)
Exemple #11
0
def comp_data():
    return {
        'domestic': {
            'name':
            u"English Premier League",
            'level':
            1,
            'country':
            mco.Countries(name=u"England",
                          confederation=enums.ConfederationType.europe)
        },
        'international': {
            'name': u"FIFA Club World Cup",
            'level': 1,
            'confederation': enums.ConfederationType.europe
        }
    }
Exemple #12
0
def test_domestic_competition_insert(session):
    """Domestic Competition 001: Insert domestic competition record and verify data."""
    comp_name = u"English Premier League"
    comp_country = u"England"
    comp_level = 1
    record = mco.DomesticCompetitions(
        name=comp_name,
        level=comp_level,
        country=mco.Countries(name=comp_country,
                              confederation=enums.ConfederationType.europe))
    session.add(record)

    competition = session.query(mco.DomesticCompetitions).one()

    assert repr(
        competition
    ) == "<DomesticCompetition(name={0}, country={1}, level={2})>".format(
        comp_name, comp_country, comp_level)
    assert competition.name == comp_name
    assert competition.level == comp_level
    assert competition.country.name == comp_country
Exemple #13
0
 def countries(self, data_frame):
     remote_ids = []
     country_records = []
     fields = ['name', 'code', 'confederation']
     for idx, row in data_frame.iterrows():
         country_dict = {
             field: row[field]
             for field in fields if row[field]
         }
         if not self.record_exists(mco.Countries, name=row['name']):
             country_records.append(mco.Countries(**country_dict))
             remote_ids.append(row['remote_id'])
     self.session.add_all(country_records)
     self.session.commit()
     map_records = [
         mcs.CountryMap(id=country_record.id,
                        remote_id=remote_id,
                        supplier_id=self.supplier_id)
         for remote_id, country_record in zip(remote_ids, country_records)
         if remote_id
     ]
     self.session.add_all(map_records)
     self.session.commit()
Exemple #14
0
def person_data():
    return {
        'generic': {
            'first_name':
            u"John",
            'last_name':
            u"Doe",
            'birth_date':
            date(1980, 1, 1),
            'country':
            mco.Countries(name=u"Portlandia",
                          confederation=enums.ConfederationType.north_america)
        },
        'manager': [{
            'first_name':
            u"Arsène",
            'last_name':
            u"Wenger",
            'birth_date':
            date(1949, 10, 22),
            'country':
            mco.Countries(name=u"France",
                          confederation=enums.ConfederationType.europe)
        }, {
            'first_name':
            u"Arthur",
            'middle_name':
            u"Antunes",
            'last_name':
            u"Coimbra",
            'nick_name':
            u"Zico",
            'birth_date':
            date(1953, 3, 3),
            'country':
            mco.Countries(name=u"Brazil",
                          confederation=enums.ConfederationType.south_america)
        }],
        'player': [{
            'first_name':
            u'Miguel',
            'middle_name':
            u'Ángel',
            'last_name':
            u'Ponce',
            'second_last_name':
            u'Briseño',
            'birth_date':
            date(1989, 4, 12),
            'country':
            mco.Countries(name=u"Mexico",
                          confederation=enums.ConfederationType.north_america),
            'order':
            enums.NameOrderType.middle
        }, {
            'first_name':
            u"Cristiano",
            'middle_name':
            u"Ronaldo",
            'last_name':
            u"Aveiro",
            'second_last_name':
            u"dos Santos",
            'nick_name':
            u"Cristiano Ronaldo",
            'birth_date':
            date(1985, 2, 5),
            'country':
            mco.Countries(name=u"Portugal",
                          confederation=enums.ConfederationType.europe),
            'order':
            enums.NameOrderType.western
        }, {
            'first_name':
            u'Heung-Min',
            'last_name':
            u'Son',
            'birth_date':
            date(1992, 7, 8),
            'country':
            mco.Countries(name=u"Korea Republic",
                          confederation=enums.ConfederationType.asia),
            'order':
            enums.NameOrderType.eastern
        }],
        'referee': [{
            'first_name':
            u"Christopher",
            'middle_name':
            u"J",
            'last_name':
            u"Foy",
            'birth_date':
            date(1962, 11, 20),
            'country':
            mco.Countries(name=u"England",
                          confederation=enums.ConfederationType.europe)
        }, {
            'first_name':
            u"Cüneyt",
            'last_name':
            u"Çakır",
            'birth_date':
            date(1976, 11, 23),
            'country':
            mco.Countries(name=u"Turkey",
                          confederation=enums.ConfederationType.europe)
        }]
    }