def test_round_is_voting_when_all_players_have_provided_a_card(self): Play.play_for_round(self.current, self.game.storyteller, self.game.storyteller._pick_card(), 'story') players = self.game.players.all().exclude(id=self.game.storyteller.id) for player in players: Play.play_for_round(self.current, player, player._pick_card()) self.assertEqual(self.current.status, RoundStatus.VOTING)
def test_game_deals_new_player_when_round_is_providing(self): storyteller = self.game.add_player(self.user, 'storyteller') self.game.add_round() Play.play_for_round(self.game.current_round, storyteller, storyteller._pick_card(), 'story') player2 = self.game.add_player(self.user2, 'player2') self.assertEqual(player2.cards.count(), settings.GAME_HAND_SIZE)
def test_game_with_voting_round_is_ongoing(self): storyteller = self.game.add_player(self.user, 'storyteller') game_round = self.game.add_round() Play.play_for_round(game_round, storyteller, storyteller._pick_card(), 'test') player2 = self.game.add_player(self.user2, 'player2') Play.play_for_round(self.game.current_round, player2, player2._pick_card()) self.assertEqual(self.game.status, GameStatus.ONGOING)
def test_players_can_not_choose_own_card(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) with self.assertRaises(GameInvalidPlay): play2.vote_card(card2)
def test_providing_round_can_not_be_closed(self): story_card = self.current.turn._pick_card() story_play = Play.play_for_round(self.current, self.current.turn, story_card, 'test') Play.play_for_round(self.current, self.player2, self.player2._pick_card()) self.assertEqual(self.current.status, RoundStatus.PROVIDING) self.assertRaises(GameRoundIncomplete, self.current.close)
def test_game_can_not_advance_round_when_previous_is_not_complete(self): storyteller = self.game.add_player(self.user, 'storyteller') game_round = self.game.add_round() Play.play_for_round(game_round, storyteller, storyteller._pick_card(), 'test') with self.assertRaises(GameRoundIncomplete): self.game.next_round() self.assertEqual(self.game.rounds.count(), 1)
def test_round_is_providing_until_all_players_have_provided(self): story_card = self.game.storyteller._pick_card() Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') players = self.game.players.exclude(id=self.game.storyteller.id) for player in players[1:]: Play.play_for_round(self.current, player, player._pick_card()) self.assertEqual(self.current.status, RoundStatus.PROVIDING)
def test_players_can_choose_played_card(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') play2 = Play.play_for_round(self.current, self.player2, self.player2._pick_card()) play3 = Play.play_for_round(self.current, self.player3, self.player3._pick_card()) self.assertEqual(self.current.status, RoundStatus.VOTING) play2.vote_card(story_card)
def test_can_identify_cards_played_in_a_round(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.game.current_round, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.game.current_round, self.player2, card2) round_cards = {self.game.current_round.card, story_card, card2} self.assertEqual(set(Card.objects.played_for_round(self.game.current_round)), round_cards)
def test_game_does_not_deal_new_player_when_round_is_voting(self): storyteller = self.game.add_player(self.user, 'storyteller') game_round = self.game.add_round() Play.play_for_round(self.game.current_round, storyteller, storyteller._pick_card(), 'story') player2 = self.game.add_player(self.user2, 'player2') Play.play_for_round(self.game.current_round, player2, player2._pick_card()) player3 = self.game.add_player(self.user3, 'player3') self.assertEqual(player3.cards.count(), 0)
def test_players_can_not_choose_unplayed_card(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) with self.assertRaises(GameInvalidPlay): other_card = Card.objects.available_for_game(self.game)[0] play2.vote_card(other_card)
def test_started_game_without_players_is_abandoned(self): g = Game.new_game(name='test', user=self.user, player_name='storyteller') storyteller = g.current_round.turn Play.play_for_round(g.current_round, storyteller, storyteller._pick_card(), 'story') player2 = g.add_player(self.user2, 'player2') Play.play_for_round(g.current_round, player2, player2._pick_card()) g.players.all().delete() self.assertEqual(g.status, GameStatus.ABANDONED)
def test_can_identify_cards_chosen_in_a_round(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.game.current_round, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.game.current_round, self.player2, card2) # import ipdb; ipdb.set_trace() play2.vote_card(story_card) self.assertEqual(set(Card.objects.chosen_for_round(self.game.current_round)), {story_card, })
def test_round_is_complete_when_all_players_have_voted(self): story_card = self.current.turn._pick_card() Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') players = self.game.players.all().exclude(id=self.game.storyteller.id) for player in players: Play.play_for_round(self.current, player, player._pick_card()) plays = self.current.plays.all().exclude(player=self.game.storyteller) for play in plays: play.vote_card(story_card) self.assertEqual(self.current.status, RoundStatus.COMPLETE)
def test_game_deals_new_player_when_round_is_complete(self): storyteller = self.game.add_player(self.user, 'storyteller') self.game.add_round() story_card = storyteller._pick_card() Play.play_for_round(self.game.current_round, storyteller, story_card, 'story') player2 = self.game.add_player(self.user2, 'player2') player2_play = Play.play_for_round(self.game.current_round, player2, player2._pick_card()) player2_play.vote_card(story_card) player3 = self.game.add_player(self.user3, 'player3') self.assertEqual(player3.cards.count(), 0)
def test_voting_round_can_not_be_closed(self): story_card = self.current.turn._pick_card() Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') players = self.game.players.all().exclude(id=self.game.storyteller.id) for player in players: Play.play_for_round(self.current, player, player._pick_card()) plays = self.current.plays.all().exclude(player=self.game.storyteller) for play in plays[1:]: play.vote_card(story_card) self.assertEqual(self.current.status, RoundStatus.VOTING) self.assertRaises(GameRoundIncomplete, self.current.close)
def test_game_with_complete_round_is_finished(self): storyteller = self.game.add_player(self.user, 'storyteller') player2 = self.game.add_player(self.user2, 'player2') game_round = self.game.add_round() story_card = storyteller._pick_card() play1 = Play.play_for_round(game_round, storyteller, story_card, 'test') card2 = player2._pick_card() play2 = Play.play_for_round(game_round, player2, card2) play2.vote_card(story_card) self.assertEqual(self.game.status, GameStatus.FINISHED)
def test_game_can_advance_round_when_previous_is_complete(self): storyteller = self.game.add_player(self.user, 'storyteller') player2 = self.game.add_player(self.user2, 'player2') game_round = self.game.add_round() story_card = storyteller._pick_card() Play.play_for_round(game_round, storyteller, story_card, 'test') play2 = Play.play_for_round(game_round, player2, player2._pick_card()) play2.vote_card(story_card) next_round = self.game.next_round() self.assertTrue(next_round is not None) self.assertEqual(self.game.rounds.count(), 2)
def test_can_identify_cards_played_in_a_round(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.game.current_round, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.game.current_round, self.player2, card2) round_cards = {self.game.current_round.card, story_card, card2} self.assertEqual( set(Card.objects.played_for_round(self.game.current_round)), round_cards)
def test_can_identify_cards_chosen_in_a_round(self): story_card = self.game.storyteller._pick_card() story_play = Play.play_for_round(self.game.current_round, self.game.storyteller, story_card, 'story') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.game.current_round, self.player2, card2) # import ipdb; ipdb.set_trace() play2.vote_card(story_card) self.assertEqual( set(Card.objects.chosen_for_round(self.game.current_round)), { story_card, })
def test_storyteller_doesnt_score_when_all_players_guess(self): story_card = self.current.turn._pick_card() story_play = Play.play_for_round(self.current, self.current.turn, story_card, 'test') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) card3 = self.player3._pick_card() play3 = Play.play_for_round(self.current, self.player3, card3) play2.vote_card(story_card) play3.vote_card(story_card) self.current.close() self.current.turn.refresh_from_db() self.assertEqual(self.current.turn.score, 0)
def test_storyteller_scores_when_player_guessed(self): story_card = self.current.turn._pick_card() story_play = Play.play_for_round(self.current, self.current.turn, story_card, 'test') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) card3 = self.player3._pick_card() play3 = Play.play_for_round(self.current, self.player3, card3) play2.vote_card(story_card) play3.vote_card(card2) self.current.close() self.current.turn.refresh_from_db() self.assertEqual(self.current.turn.score, settings.GAME_STORY_SCORE)
def test_players_score_when_their_card_is_chosen(self): story_card = self.current.turn._pick_card() story_play = Play.play_for_round(self.current, self.current.turn, story_card, 'test') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) card3 = self.player3._pick_card() play3 = Play.play_for_round(self.current, self.player3, card3) play2.vote_card(card3) play3.vote_card(card2) self.current.close() self.player2.refresh_from_db() self.assertEqual(self.player2.score, settings.GAME_CONFUSED_GUESS_SCORE)
def test_players_score_max_bound(self): player4 = self.game.add_player(self.user4, 'player4') story_card = self.current.turn._pick_card() story_play = Play.play_for_round(self.current, self.current.turn, story_card, 'test') card2 = self.player2._pick_card() play2 = Play.play_for_round(self.current, self.player2, card2) card3 = self.player3._pick_card() play3 = Play.play_for_round(self.current, self.player3, card3) card4 = player4._pick_card() play4 = Play.play_for_round(self.current, player4, card4) play2.vote_card(story_card) play3.vote_card(card2) play4.vote_card(card2) self.current.close() self.player2.refresh_from_db() self.assertEqual(self.player2.score, settings.GAME_MAX_ROUND_SCORE)
def test_game_with_storyteller_play_is_new(self): storyteller = self.game.add_player(self.user, 'storyteller') game_round = self.game.add_round() Play.play_for_round(game_round, storyteller, storyteller._pick_card(), 'test') self.assertEqual(self.game.status, GameStatus.NEW)
def test_round_is_new_when_only_storyteller_has_played(self): story_card = self.game.storyteller._pick_card() Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') self.assertEqual(self.current.status, RoundStatus.NEW)
def test_players_can_provide_card_after_storyteller(self): Play.play_for_round(self.current, self.game.storyteller, self.game.storyteller._pick_card(), 'story') Play.play_for_round(self.current, self.player2, self.player2._pick_card()) self.assertEqual(self.current.plays.count(), 2)
def test_players_cant_provide_card_before_storyteller(self): with self.assertRaises(GameInvalidPlay): Play.play_for_round(self.current, self.player2, self.player2._pick_card())
def test_play_can_be_performed_for_round(self): story_card = self.game.storyteller._pick_card() Play.play_for_round(self.current, self.game.storyteller, story_card, 'story') self.assertEqual(self.current.plays.count(), 1)