Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
 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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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, })
Example #13
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)
Example #14
0
    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)
Example #15
0
    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)
Example #16
0
    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)
Example #17
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)
Example #18
0
    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)
Example #19
0
    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)
Example #20
0
    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)
Example #21
0
    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)
Example #22
0
    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)
Example #23
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)
Example #24
0
    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)
Example #25
0
    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)
Example #26
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)
Example #27
0
    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,
            })
Example #28
0
    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)
Example #29
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)
Example #30
0
    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)
Example #31
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)
Example #32
0
    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)
Example #33
0
    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)
Example #34
0
    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)
Example #35
0
    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)
Example #36
0
    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)
Example #37
0
 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)
Example #38
0
 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)
Example #39
0
 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)
Example #40
0
 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())
Example #41
0
 def test_storyteller_can_provide_card(self):
     story_play = Play(game_round=self.current,
                       player=self.game.storyteller)
     story_play.provide_card(self.game.storyteller._pick_card(), 'story')
     self.assertEqual(self.current.plays.count(), 1)
Example #42
0
 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)
Example #43
0
 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)
Example #44
0
 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())
Example #45
0
 def test_storyteller_can_provide_card(self):
     story_play = Play(game_round=self.current, player=self.game.storyteller)
     story_play.provide_card(self.game.storyteller._pick_card(), 'story')
     self.assertEqual(self.current.plays.count(), 1)
Example #46
0
 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)
Example #47
0
 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)