コード例 #1
0
    def test_put(self):
        # create some cards and discard them
        client = Client()
        cards = [{'rank': "Ace", 'suit': "Spades"},
                 {'rank': 2, 'suit': "Diamonds"}]
        url = reverse('api:deck_discard', args=(self.id,))
        response = client.put(url, data=json.dumps(cards),
                              content_type='application/json')

        self.assertEqual(response.status_code, 200)

        deck = Deck.get(self.id)
        decoded_cards = [Card("Ace", "Spades"), Card(2, "Diamonds")]

        for card in decoded_cards:
            self.assertIn(card, deck.pile.piles['discard'])

        # make sure data gets put into the endpoint
        url = reverse('api:deck_discard', args=(self.id,))
        response = client.put(url, content_type='application/json')

        self.assertEqual(response.status_code, 409)

        # make sure data that IS put it is valid
        url = reverse('api:deck_discard', args=(self.id,))
        data = [{'foo': 42, 'bar': 'baz'}]
        response = client.put(url, data=json.dumps(data),
                              content_type='application/json')
        self.assertEqual(response.status_code, 409)
        deck = Deck.get(self.id)
コード例 #2
0
    def test_put_with_named_pile(self):
        # create some cards and discard them
        client = Client()
        cards = [{'rank': "Ace", 'suit': "Spades"},
                 {'rank': 2, 'suit': "Diamonds"}]
        url = reverse('api:deck_discard', args=(self.id,)) + '?into=my+pile'
        response = client.put(url, data=json.dumps(cards),
                              content_type='application/json')

        self.assertEqual(response.status_code, 200)

        deck = Deck.get(self.id)
        decoded_cards = [Card("Ace", "Spades"), Card(2, "Diamonds")]

        for card in decoded_cards:
            self.assertIn(card, deck.pile.piles['my pile'])
コード例 #3
0
    def test_post_with_shuffle(self):
        client = Client()

        # if the deck is not shuffled, we should expect a Queen of Spades
        url = reverse('api:deck_create') + '?shuffle=False'
        response = client.post(url)

        self.assertEqual(response.status_code, 201)

        id = json.loads(response.content).get('id')
        deck = Deck.get(id)
        card = deck.draw()

        self.assertEqual(card, Card("Queen", "Spades"))

        # if the shuffle param is not "true" or "false", return an error
        url = reverse('api:deck_create') + '?shuffle=42'
        response = client.post(url)

        self.assertEqual(response.status_code, 409)