예제 #1
0
    def test_playing_card_with_images(self):
        card = PlayingCardWithImages(rank='ACE',
                                     suit='SPADES',
                                     front_image='whatever/ACE-SPADES.png',
                                     back_image='whatever/back.png')
        self.assertEqual(card.rank, 'ACE')
        self.assertEqual(card.suit, 'SPADES')
        self.assertEqual(card.front_image, 'whatever/ACE-SPADES.png')
        self.assertEqual(card.back_image, 'whatever/back.png')

        r = card.__repr__()
        self.assertEqual(r, '<PlayingCardWithImages: ACE of SPADES>')

        card_dict = card.to_dict()
        self.assertEqual(card_dict['rank'], 'ACE')
        self.assertEqual(card_dict['suit'], 'SPADES')
        self.assertEqual(card_dict['front_image'], 'whatever/ACE-SPADES.png')
        self.assertEqual(card_dict['back_image'], 'whatever/back.png')
예제 #2
0
 def test_generate_playing_cards_with_images(self):
     config = {
         'cards': ('ACE_SPADES', '2_SPADES', '3_SPADES', ),
         'image_path': 'whatever'
     }
     cards = PlayingCardWithImages.generate_cards(config=config)
     for card in cards:
         self.assertTrue(isinstance(card, PlayingCardWithImages))
         self.assertIn('whatever', card.front_image)
         self.assertIn('whatever', card.back_image)
예제 #3
0
    def test_playing_card_with_images(self):
        card = PlayingCardWithImages(
            rank='ACE',
            suit='SPADES',
            front_image='whatever/ACE-SPADES.png',
            back_image='whatever/back.png')
        self.assertEqual(card.rank, 'ACE')
        self.assertEqual(card.suit, 'SPADES')
        self.assertEqual(card.front_image, 'whatever/ACE-SPADES.png')
        self.assertEqual(card.back_image, 'whatever/back.png')

        r = card.__repr__()
        self.assertEqual(r, '<PlayingCardWithImages: ACE of SPADES>')

        card_dict = card.to_dict()
        self.assertEqual(card_dict['rank'], 'ACE')
        self.assertEqual(card_dict['suit'], 'SPADES')
        self.assertEqual(card_dict['front_image'], 'whatever/ACE-SPADES.png')
        self.assertEqual(card_dict['back_image'], 'whatever/back.png')
예제 #4
0
 def test_generate_playing_cards_with_images(self):
     config = {
         'cards': (
             'ACE_SPADES',
             '2_SPADES',
             '3_SPADES',
         ),
         'image_path': 'whatever'
     }
     cards = PlayingCardWithImages.generate_cards(config=config)
     for card in cards:
         self.assertTrue(isinstance(card, PlayingCardWithImages))
         self.assertIn('whatever', card.front_image)
         self.assertIn('whatever', card.back_image)
예제 #5
0
    def on_post(self, req, res):
        count = req.context["data"]["count"]
        api_key = req.context["api_key"]

        cards = list(PlayingCardWithImages.generate_cards(config=DEFAULT_CARDS_CONFIG))
        deck = BaseDeck(cards=cards, count=count)
        deck.shuffle()

        sql_params = [api_key, deck.to_json()]
        self.cursor.callproc("sp_app_deck_insert", sql_params)
        result = self.cursor.fetchone()

        req.context["result"] = to_deck_response(id=result[0]["id"], deck=deck)
        res.status = falcon.HTTP_201