예제 #1
0
    def setUp(self):
        setup_test_app_db()
        db.create_all()
        self.client = app.test_client()

        self.boys8 = Division(gender="M", grade="8")
        self.girls6 = Division(gender="F", grade="6")
        db.session.add_all([self.boys8, self.girls6])
        db.session.commit()
예제 #2
0
    def test_generate_grade_gender_divisions(self):

        Division.generate_grade_gender_divisions(grade_list=GRADES,
                                                 gender_list=GENDERS)

        num_divisions = Division.query.count()
        self.assertEqual(num_divisions, len(GRADES) * len(GENDERS))

        num_divs_for_males = Division.query.filter_by(gender="M").count()
        self.assertEqual(num_divs_for_males, len(GRADES))

        num_divs_for_grade = Division.query.filter_by(grade="7").count()
        self.assertEqual(num_divs_for_grade, len(GENDERS))
예제 #3
0
    def parseLeague(self):
        sh = self.wb.sheet_by_name(LEAGUE)
        self.teamSrv = ObjSrv()
        header = self.getRow(sh, 0, True)
        unifGrpIdL = header[3:]
        print(unifGrpIdL)
        divD = {}
        for i in range(1, sh.nrows):
            valL = self.getRow(sh, i, True)
            try:
                div = int(valL[0])
            except ValueError:
                div = str(valL[0])

            pool = valL[1]
            team = self.parseTeam(valL[2])
            team.rank = i
            countL = [int(e) for e in valL[3:]]
            team.unifCountD = dict(zip(unifGrpIdL, countL))
            if div not in divD:
                divD[div] = []
            divD[div].append((pool, team))

        divL = []
        for divId, valL in iteritems(divD):
            poolL, teamL = zip(*valL)
            poolS = set(poolL)
            if len(poolS) == 1:
                division = Division('division-%s' % str(divId), teamL)
            elif len(poolS) == 2:
                pool1, pool2 = list(poolS)
                teamL1 = [team for pool, team in valL if pool == pool1]
                teamL2 = [team for pool, team in valL if pool == pool2]
                division = DivisionHalf('division-%s' % str(divId), teamL1,
                                        teamL2)
            else:
                raise Exception(
                    "Can't have more than two pools in the same division (%s)."
                    % (', '.join(map(str, poolS))))

            for team in teamL:
                team.division = division
            divL.append(division)

        self.league = League(divL)
        self.loadLeague(self.league)
예제 #4
0
 def update(self, division: model.Division):
     """Обновить/создать документ в БД"""
     self.update_one(self._make_filter(division.tvd_name, division.name),
                     _update_request_body(division.to_dict()))
예제 #5
0
 def test_div_without_grade(self):
     div = Division(gender="F", adult_child="child")
     self.assertEqual(div.name, "Girls")
     self.assertEqual(div.code, "F")
     db.session.add(div)
     db.session.commit()
예제 #6
0
 def test_create_division_illegal_grade_letters(self):
     with self.assertRaises(TmsError):
         boys_senior = Division(gender="M", grade="Senior")
예제 #7
0
 def test_create_division_illegal_grade_num(self):
     with self.assertRaises(TmsError):
         boys_gr3 = Division(gender="M", grade="3")
예제 #8
0
 def test_create_division_illegal_gender(self):
     with self.assertRaises(TmsError):
         mixed_gr8 = Division(gender="X", grade="8")