Beispiel #1
0
 def setUp(self):
     self.api = LiarsDiceApi()
     payload = {"numPlayers": self.numPlayers, "numDice": self.numDice}
     resp = self.api.games(payload=payload)
     self.assertEqual(resp.status_code, 200)
     resp_object = resp.json()
     self.assertIsNone(resp_object.get("error", None))
     self.game_id = resp_object['_id']
Beispiel #2
0
class BaseTest(unittest.TestCase):
    numPlayers = 4
    numDice = 5

    # set up a game to work with and record it's id for later use
    def setUp(self):
        self.api = LiarsDiceApi()
        payload = {"numPlayers": self.numPlayers, "numDice": self.numDice}
        resp = self.api.games(payload=payload)
        self.assertEqual(resp.status_code, 200)
        resp_object = resp.json()
        self.assertIsNone(resp_object.get("error", None))
        self.game_id = resp_object['_id']

    # get count the number of faces and return the one with the highest count
    def _get_highest_number(self,nums):
        nmap = defaultdict(int)
        for num in nums:
            nmap[num] += 1
        top_count=0
        highest_number=0
        for key, value in nmap.items():
            if value > top_count:
                top_count = value
                highest_number = int(key)
        return highest_number, top_count
Beispiel #3
0
import unittest
from utils import LiarsDiceApi

api = LiarsDiceApi()
numPlayers = 4
numDice = 5


class Test01Games(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        resp = api.games()
        resp_object = resp.json()
        Test01Games.numExistingGames = len(resp_object)

    # numPlayers defined
    # numDice missing
    # should fail
    def test0_numDice_missing(self):
        payload = {'numPlayers': numPlayers}
        url = api.get_url("/games")
        resp = api.post(url, payload)
        self.assertEqual(resp.status_code, 200)
        resp_obj = resp.json()
        self.assertEqual(resp_obj.get("error", None),
                         "numPlayers and numDice is required")

    # numPlayers missing
    # numDice defined
    # should fail
    def test1_numPlayers_missing(self):