예제 #1
0
    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
            ]))
예제 #2
0
 def test_should_process_comp_series_no_comp(self):
     with pytest.raises(
             DomainError,
             match=
             "Competition must be created before competition games can be processed."
     ):
         sub_comp_config = SubCompetitionConfiguration(
             "Test", None, None, None, None, None, None, None, None)
         sub_comp = PlayoffSubCompetition("test", [], None, None, 1, 1,
                                          False, False, False, False)
         sub_comp.groups = [
             CompetitionGroup("Group 1", None, None, None, None, None),
             CompetitionGroup("Group 3", None, None, None, None, None),
             CompetitionGroup("Group 4", None, None, None, None, None),
         ]
         series = CompetitionConfigurator.process_series_configuration(
             SeriesConfiguration(
                 "Series 1", 5, sub_comp,
                 CompetitionGroupConfiguration("Group 1", sub_comp_config,
                                               None, 1, None, 1, None), 1,
                 CompetitionGroupConfiguration("Group 1", sub_comp_config,
                                               None, 1, None, 1, None), 2,
                 SeriesByGoalsRules("My Rules", 5, None, None, None), None,
                 CompetitionGroupConfiguration("Group 3", sub_comp_config,
                                               None, 1, None, 1, None),
                 CompetitionGroupConfiguration("Group 4", sub_comp_config,
                                               None, 1, None, 1, None),
                 CompetitionGroupConfiguration("Group 3", sub_comp_config,
                                               None, 1, None, 1, None),
                 CompetitionGroupConfiguration("Group 4", sub_comp_config,
                                               None, 1, None, 1, None), 1,
                 None), sub_comp)
예제 #3
0
 def test_create_sub_comp_no_comp(self):
     with pytest.raises(
             DomainError,
             match="Can't setup sub competition if competition is not setup."
     ):
         CompetitionConfigurator.create_sub_competition(
             SubCompetitionConfiguration("My Sub Comp", None, None, None, 1,
                                         None, 1, None), None)
예제 #4
0
    def test_create_sub_com_sub_comp_already_created(self):
        with pytest.raises(
                DomainError,
                match="Sub competition My Sub Comp is already setup."):
            sub_comp = SubCompetitionConfiguration("My Sub Comp", None, None,
                                                   None, 1, None, 1, None)
            competition = create_default_competition_for_testing(
                "My Comp", 5, [sub_comp])

            CompetitionConfigurator.create_sub_competition(
                sub_comp, competition)
예제 #5
0
 def test_should_get_group(self):
     sub_comp_config = SubCompetitionConfiguration("Test", None, None, None,
                                                   None, None, None, None,
                                                   None)
     result = CompetitionConfigurator.get_group_from_list(
         CompetitionGroupConfiguration("My group 3", sub_comp_config, None,
                                       None, None, None, None),
         [
             CompetitionGroup("My Group 2", None, None, None, None, None),
             CompetitionGroup("My Group", None, None, None, None, None),
             CompetitionGroup("My group 3", None, None, None, None, None),
             CompetitionGroup("My Group 2", None, None, None, None, None)
         ])
     self.assertEqual("My group 3", result.name)
예제 #6
0
 def test_should_fail_group_not_created(self):
     with pytest.raises(
             DomainError,
             match="Group Team Group 1 has not been created yet."):
         competition = create_default_competition_for_testing("My Comp")
         sub_comp_config = SubCompetitionConfiguration(
             "Test", None, None, None, None, None, None, None, None)
         comp_group_config = CompetitionGroupConfiguration(
             "Team Group 1", sub_comp_config, None, 1,
             CompetitionGroupConfiguration.RANKING_TYPE, 1, None)
         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)
예제 #7
0
 def test_should_get_group_too_many(self):
     with pytest.raises(DomainError,
                        match="My Group has multiple 2 entries."):
         sub_comp_config = SubCompetitionConfiguration(
             "Test", None, None, None, None, None, None, None, None)
         CompetitionConfigurator.get_group_from_list(
             CompetitionGroupConfiguration("My Group", sub_comp_config,
                                           None, None, None, None, None),
             [
                 CompetitionGroup("My Group 2", None, None, None, None,
                                  None),
                 CompetitionGroup("My Group", None, None, None, None, None),
                 CompetitionGroup("My Group", None, None, None, None, None),
                 CompetitionGroup("My Group 2", None, None, None, None,
                                  None)
             ])
예제 #8
0
    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
            ]))
예제 #9
0
 def test_should_get_group_no_group(self):
     with pytest.raises(
             DomainError,
             match=
             "Group My group was not found.  Need to create group before calling this."
     ):
         sub_comp_config = SubCompetitionConfiguration(
             "Test", None, None, None, None, None, None, None, None)
         CompetitionConfigurator.get_group_from_list(
             CompetitionGroupConfiguration("My group", sub_comp_config,
                                           None, None, None, None, None),
             [
                 CompetitionGroup("My Group 2", None, None, None, None,
                                  None),
                 CompetitionGroup("My Group", None, None, None, None, None),
                 CompetitionGroup("My Group", None, None, None, None, None),
                 CompetitionGroup("My Group 2", None, None, None, None,
                                  None)
             ])
예제 #10
0
    def test_should_not_create_group_sub_competition_does_not_exist(self):
        with pytest.raises(
                DomainError,
                match="You are setting up groups before sub competitions."):
            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)

            current_groups = []

            competition = create_default_competition_for_testing("My Comp")

            group = CompetitionConfigurator.create_competition_group(
                comp_group_config, competition)
예제 #11
0
    def test_create_table_sub_comp(self):
        sub_competition_config = SubCompetitionConfiguration(
            "Table Sub", None, [], [], 3,
            SubCompetitionConfiguration.TABLE_TYPE, 1, None)

        competition = create_default_competition_for_testing("My Comp", 5)

        sub_comp = CompetitionConfigurator.create_sub_competition(
            sub_competition_config, competition)

        self.assertEqual(sub_competition_config.name, sub_comp.name)
        self.assertEqual(0, len(sub_comp.records))
        self.assertEqual(competition.oid, sub_comp.competition.oid)
        self.assertEqual(sub_competition_config.order, sub_comp.order)
        self.assertFalse(sub_comp.setup)
        self.assertFalse(sub_comp.started)
        self.assertFalse(sub_comp.finished)
        self.assertFalse(sub_comp.post_processed)
        self.assertEqual(1, len(competition.sub_competitions), "Sub Comps")
        self.assertEqual(sub_competition_config.name,
                         competition.sub_competitions[0].name)
예제 #12
0
    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)
예제 #13
0
    def test_should_process_by_wins_method(self):
        competition = create_default_competition_for_testing("Test", 1)
        sub_comp = PlayoffSubCompetition("Test", [], competition, [], 1, 1,
                                         False, False, False, False)
        competition.sub_competitions.append(sub_comp)

        sub_comp_config = SubCompetitionConfiguration("Test", None, None, None,
                                                      None, None, None, None,
                                                      None)
        group1 = CompetitionGroupConfiguration("Group 1", sub_comp_config,
                                               None, 1, None, 1, None)
        group3 = CompetitionGroupConfiguration("Group 3", sub_comp_config,
                                               None, 1, None, 1, None)
        group4 = CompetitionGroupConfiguration("Group 4", sub_comp_config,
                                               None, 1, None, 1, None)

        sub_comp.groups = [
            CompetitionConfigurator.create_competition_group(
                group1, competition),
            CompetitionConfigurator.create_competition_group(
                group3, competition),
            CompetitionConfigurator.create_competition_group(
                group4, competition)
        ]
        series = CompetitionConfigurator.processes_series_by_wins_configuration(
            SeriesConfiguration(
                "Series 1", 5, None, group1, 1, group1, 2,
                SeriesByWinsRules("My Rules", 4, None, None, None), group3,
                group4, group3, group4, 1, None), sub_comp)

        self.assertEqual("Series 1", series.name)
        self.assertEqual("Group 1", series.home_team_from_group.name)
        self.assertEqual("Group 1", series.away_team_from_group.name)
        self.assertEqual("Group 3", series.winner_to_group.name)
        self.assertEqual("Group 3", series.loser_to_group.name)
        self.assertEqual("Group 4", series.winner_rank_from.name)
        self.assertEqual("Group 4", series.loser_rank_from.name)
예제 #14
0
    def test_should_process_by_goals_method(self):
        sub_comp_config = SubCompetitionConfiguration("Test", None, None, None,
                                                      None, None, None, None,
                                                      None)
        group1 = CompetitionGroupConfiguration("Group 1", sub_comp_config,
                                               None, 1, None, 1, None)
        group3 = CompetitionGroupConfiguration("Group 3", sub_comp_config,
                                               None, 1, None, 1, None)
        group4 = CompetitionGroupConfiguration("Group 4", sub_comp_config,
                                               None, 1, None, 1, None)
        series = CompetitionConfigurator.process_series_by_goals_configuration(
            SeriesConfiguration(
                "Series 1", 5, None, group1, 1, group1, 2,
                SeriesByGoalsRules("My Rules", 5, None, None, None), group3,
                group4, group3, group4, 1, None), [group1, group3, group4],
            None)

        self.assertEqual("Series 1", series.name)
        self.assertEqual("Group 1", series.home_team_from_group.name)
        self.assertEqual("Group 1", series.away_team_from_group.name)
        self.assertEqual("Group 3", series.winner_to_group.name)
        self.assertEqual("Group 3", series.loser_to_group.name)
        self.assertEqual("Group 4", series.winner_rank_from.name)
        self.assertEqual("Group 4", series.loser_rank_from.name)