class StartGameTestCase(TestCase): def setUp(self): self.game = GameFactory() self.player = PlayerFactory() self.game.add_player(self.player) def test_deck_is_created_for_single_player(self): player = PlayerFactory() self.game.start() assert Deck.objects.get(game=self.game, player=self.player) with self.assertRaises(Deck.DoesNotExist): Deck.objects.get(game=self.game, player=player) def test_decks_are_created_for_players(self): player = PlayerFactory() self.game.add_player(player) self.game.start() assert Deck.objects.get(game=self.game, player=self.player) assert Deck.objects.get(game=self.game, player=player) def test_deck_size_is_set(self): self.game.start() deck = Deck.objects.get(game=self.game, player=self.player) self.assertEqual(deck.get_deck_size(), 10) def test_turn_created_for_first_player(self): self.game.start() turn = Turn.objects.get( game=self.game, turn_number=1, ) self.assertEqual(turn.actions_left, 1) self.assertEqual(turn.buys_left, 1) self.assertEqual(turn.player, self.player) def test_current_player_returns_whos_turn_it_is(self): self.game.start() current_player = self.game.current_player self.assertEqual(current_player, self.player)
class DeckTestCase(TestCase): def setUp(self): random.seed(0) self.game = GameFactory() self.player = PlayerFactory() self.game.add_player(self.player) self.game.start() self.deck = Deck.objects.get( game=self.game, player=self.player, ) def test_current_hand_is_five(self): self.assertEqual(len(self.deck.current_hand), 5) self.assertEqual(len(self.deck.deck_order), 5) def test_cards_are_cached_on_the_deck(self): with self.assertNumQueries(1): self.assertEqual(len(self.deck.cards), 10) with self.assertNumQueries(0): self.assertEqual(len(self.deck.cards), 10)