def test_get_nb_finishers_by_club_order_by_desc_nb(self): cpt = 1 while cpt <= 5: a_runner = RunnerFactory(race=self.active_race_10km, number=cpt, club=CLUB1) RankingFactory(runner=a_runner, checkin=timezone.now()) a_runner = RunnerFactory(race=self.active_race_5km, number=cpt+10, club=CLUB2) RankingFactory(runner=a_runner, checkin=timezone.now()) RunnerFactory(race=self.active_race_no_ranking, number=cpt+100, club="Club3") cpt += 1 while cpt <= 8: a_runner = RunnerFactory(race=self.active_race_10km, number=cpt, club=CLUB1) if cpt < 8: RankingFactory(runner=a_runner, checkin=timezone.now()) cpt += 1 expected_nb_of_finishers_for_club1 = 7 expected_nb_of_finishers_for_club2 = 5 data = get_nb_finishers_by_club_order_by_desc_nb() self.assertEqual(len(data), 2) self.assertEqual(data[0].get('club'), CLUB1) self.assertEqual(data[1].get('club'), CLUB2) self.assertEqual(data[0].get('nb'), expected_nb_of_finishers_for_club1) self.assertEqual(data[1].get('nb'), expected_nb_of_finishers_for_club2)
def test_find_by_number_started_race_no_result(self): self.assertIsNone(Runner.find_by_number_started_race(None)) self.assertIsNone(Runner.find_by_number_started_race(-1)) a_runner = RunnerFactory(number=None) self.assertIsNone(Runner.find_by_number_started_race(NUMBER_1000)) a_runner.number = NUMBER_1000 a_runner.save() self.assertIsNone(Runner.find_by_number_started_race(NUMBER_1000))
def test_find_all(self): self.assertCountEqual(Runner.find_all(), []) runners = [] cpt = 1 while cpt < 4: runners.append(RunnerFactory(number=cpt)) cpt = cpt + 1 self.assertCountEqual(Runner.find_all(), runners)
def test_get_first_finishers_by_race_and_category(self): cpt = 1 rankings = [] finishers_expected = [] while cpt <= 10: a_runner = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1948, 12, 31), gender=FEMALE, number=cpt) if cpt <= 3: finishers_expected.append(a_runner) rankings.append(RankingFactory(runner=a_runner, checkin=timezone.now())) cpt += 1 self.assertCountEqual(_get_first_finishers_by_race_and_category(rankings), finishers_expected)
def test_get_race_finisher_categories(self): a_runner_a3 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1948, 12, 31), gender=FEMALE, number=1) a_runner_a2 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1968, 12, 31), gender=FEMALE, number=2) a_runner_a1 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1998, 12, 31), gender=FEMALE, number=3) a_runner_v3 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1948, 12, 31), gender=MALE, number=4) a_runner_v2 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1968, 12, 31), gender=MALE, number=5) a_runner_v1 = RunnerFactory(race=self.active_race_10km, birth_date=datetime.date(1998, 12, 31), gender=MALE, number=6) self.assertCountEqual(_get_race_finisher_categories(None), []) a_ranking_a3 = RankingFactory(runner=a_runner_a3, checkin=timezone.now()) self.assertCountEqual(_get_race_finisher_categories([a_ranking_a3]), [a_runner_a3.category]) a_ranking_a2 = RankingFactory(runner=a_runner_a2, checkin=timezone.now()) a_ranking_a1 = RankingFactory(runner=a_runner_a1, checkin=timezone.now()) self.assertCountEqual(_get_race_finisher_categories([a_ranking_a3,a_ranking_a2,a_ranking_a1]), [a_runner_a3.category, a_runner_a2.category, a_runner_a1.category]) a_ranking_v3 = RankingFactory(runner=a_runner_v3, checkin=timezone.now()) self.assertCountEqual(_get_race_finisher_categories([a_ranking_a3,a_ranking_a2,a_ranking_a1, a_ranking_v3]), [a_runner_a3.category, a_runner_a2.category, a_runner_a1.category, a_runner_v3.category])
def test_duplicated(self): a_race = RaceFactory() a_runner = RunnerFactory(race=a_race) ranking_1 = RankingFactory(runner=a_runner) ranking_2 = RankingFactory(runner=a_runner)
def test_find_by_number_started_race(self): a_race = RaceFactory(accurate_race_start=timezone.now()) a_runner = RunnerFactory(number=NUMBER_1002, race=a_race) self.assertEqual(Runner.find_by_number_started_race(NUMBER_1002), a_runner)
def test_find_by_number(self): yr = timezone.now().year self.assertIsNone(Runner.find_by_number(None)) self.assertIsNone(Runner.find_by_number(-1)) a_runner = RunnerFactory(number=NUMBER_1001) self.assertEqual(Runner.find_by_number(NUMBER_1001), a_runner)
def test_find_by_id(self): self.assertIsNone(Runner.find_by_id(-1)) a_runner = RunnerFactory(number=NUMBER_1003) self.assertEqual(Runner.find_by_id(a_runner.id), a_runner)