def __init__(self, table_sub_competition): competition = CompetitionDTO.get_dto(table_sub_competition.compettiion) groups = [ CompetitionGroupDTO.get_dto(g) for g in table_sub_competition.groups ] records = [TableRecordDTO(r) for r in table_sub_competition.records] TableSubCompetition.__init__( self, table_sub_competition.name, records, competition, groups, table_sub_competition.order, table_sub_competition.setup, table_sub_competition.started, table_sub_competition.finished, table_sub_competition.post_processed, table_sub_competition.oid)
def test_should_add_team_multiple_parents(self): competition = create_default_competition_for_testing("My Comp", 3) sub_comp = TableSubCompetition("My Sub Comp", None, competition, [], 1, False, False, False, False) competition.sub_competitions.append(sub_comp) parent_comp_group_config = CompetitionGroupConfiguration( "Parent Group 1", sub_comp, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group_config = CompetitionGroupConfiguration( "Team Group 1", sub_comp, parent_comp_group_config, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) self.assertEqual(2, len(competition.get_all_groups())) team = Team("My Team", 5, True) competition_team_configuration = CompetitionTeamConfiguration( team, None, comp_group_config, 1, None) comp_team = CompetitionTeam(competition, team) competition.teams = [comp_team] CompetitionConfigurator.process_competition_team_configuration( competition_team_configuration, competition) self.assertEqual(1, len(competition.teams)) self.assertEqual(1, len(comp_group.rankings)) self.assertEqual(1, len(comp_group.parent_group.rankings)) self.assertEqual(comp_team.oid, comp_group.rankings[0].team.oid) self.assertEqual(comp_team.oid, comp_group.parent_group.rankings[0].team.oid)
def test_should_create_group_group_already_setup(self): sub_comp_config = SubCompetitionConfiguration( "My Sub Comp", None, None, None, 1, SubCompetitionConfiguration.TABLE_TYPE, 1, None) comp_group_config = CompetitionGroupConfiguration( "Group 1 Config", sub_comp_config, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) # current_groups = [] competition = create_default_competition_for_testing("My Comp") sub_comp = TableSubCompetition("My Sub Comp", [], competition, [], 1, False, False, False, False) competition.sub_competitions.append(sub_comp) group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) # try it again group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) self.assertEqual("Group 1 Config", group.name) self.assertIsNone(group.parent_group) self.assertEqual(group.sub_competition.oid, sub_comp.oid) self.assertEqual(group.group_type, CompetitionGroupConfiguration.RANKING_TYPE) self.assertEqual(0, len(group.rankings)) self.assertEqual(1, len(competition.get_all_groups())) self.assertEqual( 1, len([ g for g in competition.get_all_groups() if g.oid == group.oid ]))
def get_add_record(self): return TableSubCompetitionDTO( TableSubCompetition( "Table Comp", None, CompetitionDTO( Competition("My Comp", 1, None, None, 1, False, False, False, False)), None, 3, True, True, False, False))
def test_should_process_series_game_not_playoff_sub_comp(self): competition = create_default_competition_for_testing("My Comp", 1) with pytest.raises( DomainError, match= "Sub Competition Table Comp is not a playoff sub competition." ): CompetitionConfigurator.process_series_configuration( None, TableSubCompetition("Table Comp", None, competition, [], None, None, None, None, None))
def print_group(group_name, table_to_print, description): group = competition.get_group_by_name(group_name) recs = TableSubCompetition.get_records_by_group(group, table_to_print.records) recs.sort(key=lambda rec: rec.rank) print(description) print(RecordView.get_table_header()) for r in recs: print(RecordView.get_table_row(RecordService.get_view_from_model(r)))
def create_table_sub_competition(sub_competition_config, competition): sub_comp = TableSubCompetition(sub_competition_config.name, [], competition, [], sub_competition_config.order, False, False, False, False) competition.sub_competitions.append(sub_comp) CompetitionConfigurator.create_sub_competition_groups( sub_competition_config, competition) return sub_comp
def get_updated_record(self, original_record): original_record.day = 10 original_record.year = 20 original_record.home_team = TeamDTO(Team("New Home TEam", 249, False)) original_record.away_team = TeamDTO(Team("New Away TEam", 244, True)) original_record.home_score = 30 original_record.away_score = 30 original_record.complete = True original_record.processed = False original_record.rules = GameRulesDTO(GameRules("Rules Name 2", False)) original_record.competition = CompetitionDTO(Competition("Test 2", 5, None, None, 1, False, True, True, False)) original_record.sub_competition = TableSubCompetitionDTO(TableSubCompetition("Sub Comp", None, original_record.competition, None, 1, True, True, False, False)) return original_record
def test_get_dictionary_of_team_records(self): comp_records = [ helpers.new_table_record(None, "Team 1", 5), helpers.new_table_record(None, "Team 2", 5), helpers.new_table_record(None, "Team 3", 5), helpers.new_table_record(None, "Team 4", 5), helpers.new_table_record(None, "Team 5", 5), helpers.new_table_record(None, "Team 6", 5), helpers.new_table_record(None, "Team 7", 5), ] team_map = TableSubCompetition.get_dictionary_of_team_records(comp_records) self.assertEqual(7, len(team_map)) self.assertTrue(comp_records[0].team.oid in team_map)
def test_should_fail_too_many_groups(self): with pytest.raises(DomainError, match="Group Team Group 1 has multiple groups 2."): competition = create_default_competition_for_testing("My Comp") sub_comp = TableSubCompetition("My Sub Comp", None, competition, [], 1, False, False, False, False) competition.sub_competitions.append(sub_comp) comp_group_config = CompetitionGroupConfiguration( "Team Group 1", sub_comp, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) sub_comp.groups.append(comp_group) team = Team("My Team", 5, True) competition_team_configuration = CompetitionTeamConfiguration( team, None, comp_group_config, 1, None) CompetitionConfigurator.process_competition_team_configuration( competition_team_configuration, competition)
def test_should_create_group_top_parent_exists_middle_does_not(self): sub_comp_config = SubCompetitionConfiguration( "My Sub Comp", None, None, None, 1, SubCompetitionConfiguration.TABLE_TYPE, 1, None) comp_parent_group_config2 = CompetitionGroupConfiguration( "Parent 2 Config", sub_comp_config, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_parent_group_config = CompetitionGroupConfiguration( "Parent 1 Config", sub_comp_config, comp_parent_group_config2, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group_config = CompetitionGroupConfiguration( "Group 1 Config", sub_comp_config, comp_parent_group_config, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) competition = create_default_competition_for_testing("My Comp") sub_comp = TableSubCompetition("My Sub Comp", [], competition, [], 1, False, False, False, False) competition.sub_competitions.append(sub_comp) parent_parent = CompetitionConfigurator.create_competition_group( comp_parent_group_config2, competition) group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) parent = group.parent_group self.assertIsNotNone(parent.parent_group) self.assertEqual(parent_parent.oid, parent.parent_group.oid) self.assertEqual(3, len(competition.get_all_groups())) self.assertEqual( 1, len([ g for g in competition.get_all_groups() if g.oid == group.oid ])) self.assertEqual( 1, len([ g for g in competition.get_all_groups() if g.oid == parent.oid ])) self.assertEqual( 1, len([ g for g in competition.get_all_groups() if g.oid == parent_parent.oid ]))
def test_should_add_team_team_does_not_exist(self): competition = create_default_competition_for_testing("My Comp") sub_comp = TableSubCompetition("My Sub Comp", [], competition, [], 1, False, False, False, False) competition.sub_competitions.append(sub_comp) comp_group_config = CompetitionGroupConfiguration( "Team Group 1", sub_comp, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group = CompetitionConfigurator.create_competition_group( comp_group_config, competition) team = Team("My Team", 5, True) competition_team_configuration = CompetitionTeamConfiguration( team, sub_comp, comp_group_config, 1, None) CompetitionConfigurator.process_competition_team_configuration( competition_team_configuration, competition) self.assertEqual(1, len(competition.teams)) self.assertEqual(1, len(comp_group.rankings)) self.assertEqual(team.oid, comp_group.rankings[0].team.parent_team.oid)
def test_should_not_create_group_competition_not_there(self): with pytest.raises( DomainError, match="Competition has to exist before the groups can be setup." ): competition = create_default_competition_for_testing("My Comp") competition.sub_competitions = [ TableSubCompetition("My Sub Comp", None, competition, [], None, None, None, None, None) ] sub_comp_config = SubCompetitionConfiguration( "My Sub Comp", None, [], None, 1, SubCompetitionConfiguration.TABLE_TYPE, 1, None) comp_parent_group_config = CompetitionGroupConfiguration( "Parent 1 Config", sub_comp_config, None, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) comp_group_config = CompetitionGroupConfiguration( "Group 1 Config", sub_comp_config, comp_parent_group_config, 1, CompetitionGroupConfiguration.RANKING_TYPE, 1, None) group = CompetitionConfigurator.create_competition_group( comp_group_config, None)
def test_sort_rankings(self): competition = create_default_competition_for_testing("My Comp") table = TableSubCompetition("My Table", [], None, None, 1, False, False, False, False) competition.sub_competitions.append(table) teams = [ helpers.new_comp_team(competition, "Team 1", 5), helpers.new_comp_team(competition, "Team 2", 5), helpers.new_comp_team(competition, "Team 3", 5), helpers.new_comp_team(competition, "Team 4", 5), helpers.new_comp_team(competition, "Team 5", 5), helpers.new_comp_team(competition, "Team 6", 5), helpers.new_comp_team(competition, "Team 7", 5), helpers.new_comp_team(competition, "Team 8", 5) ] records = [ TableRecord(table, -1, teams[0], 255, 10, 0, 0, 0, 0, 0, ""), TableRecord(table, -1, teams[1], 255, 9, 0, 2, 0, 0, 0, ""), TableRecord(table, -1, teams[2], 255, 6, 2, 2, 0, 0, 0, ""), TableRecord(table, -1, teams[3], 255, 7, 3, 0, 0, 0, 0, ""), TableRecord(table, -1, teams[4], 255, 0, 0, 4, 12, 12, 0, ""), TableRecord(table, -1, teams[5], 255, 0, 0, 4, 6, 12, 0, ""), TableRecord(table, -1, teams[6], 255, 0, 0, 4, 12, 6, 0, ""), TableRecord(table, -1, teams[7], 255, 0, 10, 0, 12, 6, 0, "") ] table.records = records group1 = CompetitionGroup("League", None, table, 1, [], CompetitionGroupConfiguration.RANKING_TYPE) group2 = CompetitionGroup("East", None, table, 1, [], CompetitionGroupConfiguration.RANKING_TYPE) group3 = CompetitionGroup("West", None, table, 1, [], CompetitionGroupConfiguration.RANKING_TYPE) [group1.add_team_to_group(t) for t in teams] for i in range(len(records)): if i % 2 == 0: group2.add_team_to_group(teams[i]) else: group3.add_team_to_group(teams[i]) self.assertEqual(8, len(group1.rankings)) self.assertEqual(4, len(group2.rankings)) self.assertEqual(4, len(group3.rankings)) rankings = [] rankings.extend(group1.rankings) rankings.extend(group2.rankings) rankings.extend(group3.rankings) table.sort_rankings(rankings, records) self.assertEqual("Team 1", records[0].team.name) self.assertEqual("Team 2", records[1].team.name) self.assertEqual("Team 4", records[2].team.name) self.assertEqual("Team 3", records[3].team.name) self.assertEqual("Team 7", records[4].team.name) self.assertEqual("Team 5", records[5].team.name) self.assertEqual("Team 6", records[6].team.name) self.assertEqual("Team 8", records[7].team.name) self.assertEqual("Team 1", group1.get_team_by_rank(1).name) self.assertEqual("Team 2", group1.get_team_by_rank(2).name) self.assertEqual("Team 4", group1.get_team_by_rank(3).name) self.assertEqual("Team 3", group1.get_team_by_rank(4).name) self.assertEqual("Team 7", group1.get_team_by_rank(5).name) self.assertEqual("Team 5", group1.get_team_by_rank(6).name) self.assertEqual("Team 6", group1.get_team_by_rank(7).name) self.assertEqual("Team 8", group1.get_team_by_rank(8).name) self.assertEqual("Team 1", group2.get_team_by_rank(1).name) self.assertEqual("Team 3", group2.get_team_by_rank(2).name) self.assertEqual("Team 7", group2.get_team_by_rank(3).name) self.assertEqual("Team 5", group2.get_team_by_rank(4).name) self.assertEqual("Team 2", group3.get_team_by_rank(1).name) self.assertEqual("Team 4", group3.get_team_by_rank(2).name) self.assertEqual("Team 6", group3.get_team_by_rank(3).name) self.assertEqual("Team 8", group3.get_team_by_rank(4).name)