Beispiel #1
0
    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,
        )
Beispiel #2
0
class CreateCardInstanesTestCase(TestCase):
    def setUp(self):
        self.game = GameFactory()

    def test_one_query_per_card(self):
        # The query to get the list of cards.
        num_queries = Card.objects.count() + 1
        with self.assertNumQueries(num_queries):
            self.game.create_card_instances()

    def test_number_of_card_instances_created(self):
        self.game.create_card_instances()
        card_count = sum(Card.objects.values_list('count', flat=True))
        self.assertEqual(self.game.cardinstance_set.count(), card_count)
Beispiel #3
0
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)
Beispiel #4
0
 def setUp(self):
     self.game = GameFactory()
     self.player = PlayerFactory()
     self.game.add_player(self.player)
Beispiel #5
0
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)
Beispiel #6
0
 def setUp(self):
     self.game = GameFactory()