Exemple #1
0
def test_lnc_pre_01(create_lnc_pre_models):
    # todo high update tests (these tests 01, 02, 03, 04 test the mapping process. They are not source specific
    # so they must be generalized and moves to the data_sources tests
    """
    checks the case in which pre-entities exist with the same name.
    (Only the countries are checked for all mapping cases)
    """
    pre_countries, pre_competitions, test_source = create_lnc_pre_models
    assert pre_countries

    for pre_country in pre_countries:
        pre_country.map()
        assert pre_country.exists
        assert pre_country.existing_entity

    new_entities, existing_entities, to_be_remapped_entities = NameMappedEntity.describe(pre_countries)
    assert not new_entities
    assert existing_entities
    assert not to_be_remapped_entities

    countries = create_zakanda_models(pre_countries, mapping=False)
    for country in countries:
        assert country
        assert country.sources.filter(name=test_source.name)
        assert len(country.sources.all()) == 2
    assert_competitions(pre_competitions)
Exemple #2
0
def assert_competitions(pre_competitions):
    assert pre_competitions
    for pre_competition in pre_competitions:
        pre_competition.map()  # all competition exist and their gname with the same name
        assert pre_competition.exists
        assert pre_competition.existing_entity
    new_entities, existing_entities, to_be_remapped_entities = NameMappedEntity.describe(pre_competitions)
    assert not new_entities
    assert existing_entities
    assert not to_be_remapped_entities

    comp_ents = create_zakanda_models(pre_competitions, mapping=False)
    del_comps, created_comps = xmlSoccerParser.utils.process_special_leagues()
    # assert del_comps
    # assert not created_comps
    for comp_ent in comp_ents:
        competition = comp_ent[0]
        competition_seasons = comp_ent[1]
        assert isinstance(competition, games.models.Competition)
        for competition_season in competition_seasons:
            assert isinstance(competition_season, games.models.CompetitionSeason)
            competition_gname = competition_season.competition.generic_name
            if competition_gname in games.naming.four_year_leagues:
                seasons = competition_season.competition.seasons.all()
                assert len(seasons) == 1
                assert seasons[0].name == games.naming.four_year_leagues_per_season[competition_gname]
                # len(competition_season.infos.all()) == 0 if special league is not for the given season for
                # which the test is run (16/17). If it is, then it is 2
            else:
                assert len(competition_season.infos.all()) == 2
Exemple #3
0
def test_lnc_pre_02(create_lnc_pre_models, modify_existing_entities):
    """ checks the case in which a pre-entity exists with a different name and
    user gives a valid existing entity id """
    pre_countries, pre_competitions, test_source = create_lnc_pre_models
    assert pre_countries
    assert pre_competitions
    existing_ents, existing_old_names, existing_new_names = modify_existing_entities

    for pre_country in pre_countries:
        pre_country.map(define_entity_fun=lambda: '1', define_id_fun=lambda: '703')
        assert pre_country.exists
        assert pre_country.existing_entity
        if pre_country.sname == 'Germany':
            assert pre_country.existing_entity == existing_ents[0]
            assert pre_country.existing_entity.name == existing_new_names[0]

    new_entities, existing_entities, to_be_remapped_entities = NameMappedEntity.describe(pre_countries)
    assert not new_entities
    assert existing_entities
    assert not to_be_remapped_entities

    countries = create_zakanda_models(pre_countries, mapping=False)  # countries is a generator
    for country in countries:
        assert country
        new_source = country.sources.filter(name=test_source.name)
        assert new_source
        assert len(country.sources.all()) == 2
        if country == existing_ents[0]:
            assert country.id == 703
            country_info = games.models.CountryInfo.objects.get(country=country, source=new_source)
            assert country_info.sname == 'Germany'
Exemple #4
0
def realize_pre_lncs(pre_countries, pre_competitions, **kwargs):
    # xmlsoccer follows this same process but it also needs some additional actions too (processing special leagues)
    countries, competitions, competition_seasons = [], [], []
    if pre_countries:
        for pre_country in pre_countries:
            countries.append(pre_country.get_or_create(**kwargs)[0])
    if pre_competitions:
        for pre_competition in pre_competitions:
            competition, rel_competition_seasons = pre_competition.get_or_create(
                **kwargs)
            if competition:
                competitions.append(competition)
            if rel_competition_seasons:
                competition_seasons.extend(rel_competition_seasons)

    pre_models_group = [pre_countries, pre_competitions]
    for pre_models in pre_models_group:
        NameMappedEntity.exhaustive_unmapped_mapping(pre_models)
    return countries, competitions, competition_seasons
Exemple #5
0
def create_pre_lncs(pre_countries, pre_competitions):
    # returned countries and competitions are the entities that have been created or they
    # have been selected (if they already existed)
    countries, competitions, competition_seasons = [], [], []
    deleted_comp_seasons, created_comp_seasons = [], []
    if pre_countries and pre_competitions:
        for pre_country in pre_countries:
            countries.append(pre_country.get_or_create()[0])
        for pre_competition in pre_competitions:
            competition, rel_competition_seasons = pre_competition.get_or_create(
            )
            competitions.append(competition)
            competition_seasons.extend(rel_competition_seasons)

        pre_models_group = [pre_countries, pre_competitions]
        for pre_models in pre_models_group:
            NameMappedEntity.exhaustive_unmapped_mapping(pre_models)

        deleted_comp_seasons, created_comp_seasons = process_special_leagues()

        logger.debug('deleted comps: %s', len(deleted_comp_seasons))
        logger.debug('created comps: %s', len(created_comp_seasons))
        logger.debug('COMPETITIONS SEASONS INIT: %s', len(competition_seasons))
        # logger.debug('COMPETITIONS SEASONS INIT: %s',
        #              ['{} {}'.format(competition_season.competition.generic_name, competition_season.season.name)
        #               for competition_season in competition_seasons])
        for comp in deleted_comp_seasons:
            logger.debug('del comp: %s', comp)
            if comp in competition_seasons:
                logger.debug('removing')
                competition_seasons.remove(comp)
        for comp in created_comp_seasons:
            if comp not in competition_seasons:
                competition_seasons.append(comp)
        logger.debug('COMPETITION SEASONS: %s', len(competition_seasons))
        # logger.debug('COMPETITIONS SEASONS INIT: %s',
        #              ['{} {}'.format(competition_season.competition.generic_name, competition_season.season.name)
        #               for competition_season in competition_seasons])
    return countries, competitions, competition_seasons, deleted_comp_seasons, created_comp_seasons
Exemple #6
0
def test_lnc_pre_04(create_lnc_pre_models, delete_existing_entities):
    """ checks the case in which an entity doesn't exists """
    pre_countries, pre_competitions, test_source = create_lnc_pre_models
    assert pre_countries
    assert pre_competitions
    deleted_ent_name = delete_existing_entities

    for pre_country in pre_countries:
        pre_country.map(define_entity_fun=lambda: '2', define_id_fun=lambda: 'not_used')
        if pre_country.sname == 'Germany':
            assert not pre_country.exists
            assert not pre_country.existing_entity
        else:
            assert pre_country.exists
            assert pre_country.existing_entity

    new_entities, existing_entities, to_be_remapped_entities = NameMappedEntity.describe(pre_countries)
    assert new_entities
    assert existing_entities
    assert not to_be_remapped_entities
Exemple #7
0
def realize_pre_teams(pre_teams, **kwargs):
    teams = []
    for pre_team in pre_teams:
        if not pre_team:
            logger.warning('pre_team is None')
            continue
        team = pre_team.get_or_create(**kwargs)
        pre_team.team = team
        if team:
            teams.append(team)
    new_teams, existing_teams, to_be_remapped = NameMappedEntity.exhaustive_unmapped_mapping(
        pre_teams)
    # to_be_remapped must be empty after exhaustive mapping

    for existing_entity in existing_teams:
        # normally there must be no existing entity when you run this for the first time.
        # Any duplicate teams (same team with more than one ids) will be reported here
        logger.debug("existing entity: %s", existing_entity)
        team_infos = games.models.TeamInfo.objects.filter(
            team=existing_entity.team)
        for team_info in team_infos:
            logger.debug("  > existing entity team_info: %s", team_info)
    return teams
Exemple #8
0
def test_lnc_pre_03(create_lnc_pre_models, modify_existing_entities):
    """ checks the case in which an entity exists with a different name
    and user gives an invalid existing entity id """

    pre_countries, pre_competitions, test_source = create_lnc_pre_models
    assert pre_countries
    assert pre_competitions
    existing_ents, existing_old_names, existing_new_names = modify_existing_entities

    for pre_country in pre_countries:
        pre_country.map(define_entity_fun=lambda: '1', define_id_fun=lambda: '0')
        assert pre_country.exists
        if pre_country.sname == 'Germany':
            assert not pre_country.existing_entity
        else:
            assert pre_country.existing_entity
    new_entities, existing_entities, to_be_remapped_entities = NameMappedEntity.describe(pre_countries)
    assert not new_entities
    assert existing_entities
    assert to_be_remapped_entities

    countries = create_zakanda_models(pre_countries, mapping=False)  # countries is a generator
    assert None in countries