def test_non_finalised_only_actions(self): self.tournament.set_in_progress() args = score_cat_args('disallowed_cat', 100, True, 1, 1) self.assertRaises(ValueError, self.tournament.update, {'score_categories': [args]}) self.assertRaises(ValueError, self.tournament.update, {'rounds': 5}) rego = Reg(self.player_1, self.name) rego.add_to_db() self.assertRaises(ValueError, self.tournament.confirm_entries)
def setUp(self): super(TournamentInProgress, self).setUp() self.name = 'test_in_progress' self.player_1 = 'p1' self.injector.inject(self.name, num_players=0) self.injector.add_player(self.name, self.player_1) self.tournament = Tournament(self.name) self.tournament.update({ 'rounds': 1, 'missions': ['mission01'], 'score_categories': [score_cat_args('cat', 100, True, 1, 1, False)] })
def test_score_entered(self): # Add a score category args = score_cat_args('per_round', 50, False, 0, 100) category_1 = ScoreCategory(tournament_id=self.tournament_1, **args) self.db.session.add(category_1) self.db.session.flush() tourn = Tournament(self.tournament_1) entry_2_id = TournamentEntry.query.filter_by( player_id='{}_player_{}'.format(self.tournament_1, 2), tournament_id=self.tournament_1).first().id entry_3_id = TournamentEntry.query.filter_by( player_id='{}_player_{}'.format(self.tournament_1, 3), tournament_id=self.tournament_1).first().id entry_4_id = TournamentEntry.query.filter_by( player_id='{}_player_{}'.format(self.tournament_1, 4), tournament_id=self.tournament_1).first().id entry_5_id = TournamentEntry.query.filter_by( player_id='{}_player_{}'.format(self.tournament_1, 5), tournament_id=self.tournament_1).first().id # A completed game game = self.get_game_by_round(entry_4_id, 1) Score(category=category_1.name, game_id=game.id, tournament=tourn, entry_id=entry_2_id, score=2).write() Score(category=category_1.name, game_id=game.id, tournament=tourn, entry_id=entry_4_id, score=4).write() entrants = [x.entrant_id for x in game.entrants.all()] self.assertTrue(entry_2_id in entrants) self.assertTrue(entry_4_id in entrants) self.assertTrue(Score.is_score_entered(game)) # A BYE will only have one entrant game = self.get_game_by_round(entry_3_id, 1) Score(category=category_1.name, game_id=game.id, tournament=tourn, entry_id=entry_3_id, score=3).write() entrants = [x.entrant_id for x in game.entrants.all()] compare(len(entrants), 1) self.assertTrue(entry_3_id in entrants) self.assertTrue(Score.is_score_entered(game)) # Ensure the rd2 game entry_4 vs. entry_5 is listed as not scored. This # will force a full check. entry_5's score hasn't been entered. game = self.get_game_by_round(entry_4_id, 2) game.score_entered = False self.db.session.add(game) self.db.session.flush() game = self.get_game_by_round(entry_4_id, 2) entrants = [x.entrant_id for x in game.entrants.all()] Score(category=category_1.name, game_id=game.id, tournament=tourn, entry_id=entry_4_id, score=4).write() self.assertTrue(entry_4_id in entrants) self.assertTrue(entry_5_id in entrants) self.assertFalse(Score.is_score_entered(game)) # Enter the final score for entry_5 tourn = Tournament(self.tournament_1) Score(category=category_1.name, game_id=game.id, tournament=tourn, entry_id=entry_5_id, score=5).write() self.assertTrue(Score.is_score_entered(game))