def test_isNicknameAvailable(self): """ Test players.isNicknameAvailable """ # test that the new player is actually added both in memory and in DB vbar() print("Test players.isNicknameAvailable") vbar() vprint( "We register players and check that their nickname are not available anymore." ) # empty the database playersColl = getPlayersColl() playersColl.drop() # setup the test data players = Players() for pp in refPlayers(): # test that the nickname is available vprint(" > " + pp['nickname'] + ":") answer = players.isNicknameAvailable(pp['nickname']) self.assertEqual(answer['status'], "ok") vprint(" * nickname is available") # register the player and test that the nickname is not available anymore. players.register(pp['nickname'], pp['passwordHash']) vprint(" * register " + pp['nickname']) answer = players.isNicknameAvailable(pp['nickname']) self.assertEqual(answer['status'], "ko") vprint(" * nickname is not available anymore")
def test_getGameFinished(self): """ Test game.getGameFinished """ vbar() print("Test game.isGameFinished") vbar() # retrieve gameFinished at the beginning and at the end of the game, # for both Game 0 and Game 1. for test_data_index in range(0, 2): # test at the beginning of the game partie = self.setup(test_data_index) # get the test flag test_gameFinished = partie.getGameFinished() # get the reference flag as a string, and convert it as a boolean ref_gameFinished = (refGameHeader_start()[test_data_index] ['gameFinished'] == 'True') result = (ref_gameFinished == test_gameFinished) self.assertTrue(result) vprint(" > Cardset " + str(test_data_index) + ": game started: " + str(result)) # test at the end of the game partie = self.setupAndProgress(test_data_index, 30) # get the test flag test_gameFinished = partie.getGameFinished() # get the reference flag as a string, and convert it as a boolean ref_gameFinished = (refGameHeader_Finished()[test_data_index] ['gameFinished'] == 'True') result = (ref_gameFinished == test_gameFinished) self.assertTrue(result) vprint(" > Cardset " + str(test_data_index) + ": game ended : " + str(result))
def test_getHistory(self): """ Test backend.getHistory """ vbar() print("Test backend.getHistory") vbar() # initialize test data, launch a game with 5 players backend = self.setUp() vprint("We register the reference test players:") backend.ForTestOnly_RegisterRefPlayers() pp_test = refPlayers(True) list_pid = [{'playerID': pp_test[0]['playerID']}, {'playerID': pp_test[1]['playerID']}, {'playerID': pp_test[2]['playerID']}, {'playerID': pp_test[3]['playerID']}, {'playerID': pp_test[4]['playerID']}] result = backend.enlistTeam(list_pid) gID = result['gameID'] # identify the right game and overwrite it with a reference game # (cardset 0, refGame 0, finished, 25 turns) vprint("We load the reference game 0 (full and finished).") for j in range(0, len(backend.games)): if str(backend.games[j].getGameID()) == str(gID): i = j break backend.games[i].deserialize(refGames_Dict()[0]) # First we collect the history of the full game vprint("We ask for the full history:") result = backend.getHistory(ObjectId('57b9bec5124e9b2d2503b72b')) status = result['status'] vprint(" - status: " + status) valid = gameRef_compliant(backend.games[i], 0, " ") vprint(" - game compliant: " + str(valid))
def test_getPlayerLoginDetail(self): """ Test backend.getPlayerLoginDetail """ vbar() print("test backend.getPlayerLoginDetail") vbar() # initiate a backend backend = self.setUp() # There is no player registered yet: test that it is impossible to # retrieve the players' details. vprint("Initiate a backend with no players registered: check that we cant retrieve") vprint("the players' details:") for pp in refPlayers(True): # try to retrieve the player's details answer = backend.getPlayerLoginDetails(pp['nickname']) self.assertEqual(answer['status'], "ko") self.assertEqual(answer['reason'], "unknown nickname") vprint(" > " + pp['nickname'] + ": unknown nickname") # register the reference players and then retrieve their details vprint("Register the reference test players, and retrieve their details:") backend.ForTestOnly_RegisterRefPlayers() for pp in refPlayers(True): # try to retrieve the player's details answer = backend.getPlayerLoginDetails(pp['nickname']) self.assertEqual(answer['status'], "ok") self.assertEqual(answer['playerID'], str(pp['playerID'])) self.assertEqual(answer['nickname'], str(pp['nickname'])) self.assertEqual(answer['passwordHash'], str(pp['passwordHash'])) vprint(" > " + pp['nickname'] + ": player is recognized and compliant")
def test_getHash(self): """ Test players.getHash """ # setup the test data self.setUp() players = Players() vbar() print("Test players.getHash") vbar() vprint("We collect the hash of the players in the DB and compare with") vprint("the reference test data:") # test valid players for pp in refPlayers(): playerID = pp['playerID'] hash_ref = pp['passwordHash'] result = players.getHash(playerID) valid = (result['status'] == "ok") and (result['passwordHash'] == hash_ref) vprint(" " + pp['nickname'] + ": result = " + str(result)) self.assertTrue(valid) # test unknown player result = players.getHash(ObjectId()) valid = (result['status'] == "ko") and (result['reason'] == "unknown playerID") vprint(" Unknown player: result = " + str(result)) self.assertTrue(valid) # test invalid playerID result = players.getHash("invalid") valid = (result['status'] == "ko") and (result['reason'] == "invalid playerID") vprint(" Invalid playerID: result = " + str(result)) self.assertTrue(valid) # end of the test self.teardown(players)
def test_encryptPassword(self): vbar() print("Test shared_crypto.encryptPassword") vbar() # produce a hash for all reference players and check the verification is ok vprint("We create a new hash for all reference players and check the outcome:") for pp in refPlayers_Dict(): new_hash = encryptPassword(pp['password']) self.assertTrue(checkPassword(pp['password'], new_hash)) vprint(" > " + pp['nickname'] + "'s new hash is recognized")
def setUp(self): """ Sets up the test data and create a backend """ # reset the DB data vprint("We clean the test databases.") getPlayersColl().drop() getGamesColl().drop() # initialize a backend return Backend()
def test_getPlayerID(self): """ Test players.getPlayerID """ # setup the test data self.setUp() players = Players() vbar() print("Test players.getPlayerID") vbar() vprint( "We collect the playerID of the players in the DB and compare with" ) vprint("the reference test data:") # test valid players for pp in refPlayers(): playerID_ref = pp['playerID'] result = players.getPlayerID(pp['nickname']) valid = (result['status'] == "ok") and (result['playerID'] == playerID_ref) vprint(" " + pp['nickname'] + ": result = " + str(result)) self.assertTrue(valid) # test invalid players nickname = "inexistantplayer" result = players.getPlayerID(nickname) valid = (result['status'] == "ko") and (result['reason'] == "unknown nickname") vprint(" " + nickname + ": result = " + str(result)) self.assertTrue(valid) # end of the test self.teardown(players)
def test_proposeSet(self): """ Test backend.proposeSet """ vbar() print("Test backend.proposeSet") vbar() # initialize test data, launch a game with 5 players vprint("We reconstitute the reference game 0 at turn 0, and we will play the") vprint("whole game according to the reference path. We then check that the") vprint("resulting history is compliant.") backend = self.setUp() backend.ForTestOnly_EnlistRefPlayers() backend.ForTestOnly_LoadRefGame(0) # rewind the game back to turn 0 # we know - since the backend was reseted, that the new game is # backend.game[0] => we set the games index i at 0 i = 0 backend.ForTestOnly_GetBackToTurn(0, 0) # the game is now ready for the test case j = 0 while (backend.games[i].getGameFinished() == False): pID = ObjectId(refGames_Dict()[0]['steps'][j]['playerID']) pnn = refGames_Dict()[0]['steps'][j]['nickname'] setlist = refGames_Dict()[0]['steps'][j]['set'] for k in range(0,3): setlist[k] = int(setlist[k]) result = backend.proposeSet(pID, setlist) vprint(" - turn " + str(backend.games[i].turnCounter).zfill(2) + ": " + pnn + " propose " + str(setlist) + " => " + result['status']) self.assertEqual(result['status'], "ok") j += 1 self.assertTrue(backend.games[i].gameFinished) self.assertTrue(gameRef_compliant(backend.games[i], 0, " "))
def test_delistPlayer(self): """ Test backend.delistPlayer """ vbar() print("test backend.delistPlayer") vbar() # initiate a backend and register reference players backend = self.setUp() vprint("We register the reference test players:") backend.ForTestOnly_RegisterRefPlayers() pp_test = refPlayers(True) # enlist a team of 5 players: it should succeed list_pid = [{'playerID': pp_test[0]['playerID']}, {'playerID': pp_test[1]['playerID']}, {'playerID': pp_test[2]['playerID']}, {'playerID': pp_test[3]['playerID']}, {'playerID': pp_test[4]['playerID']}] result = backend.enlistTeam(list_pid) vprint("Enlist 5 players: " + str(result['status']) + " (" + str(result['gameID']) + ")") # delist all players one after the other playersColl = getPlayersColl() vprint("Now, we delist the players one after the other:") for pp in pp_test: backend.delistPlayer(pp['playerID']) # check that the player is still registered in the database result = playersColl.find_one({'_id': pp['playerID']}) self.assertEqual(pp['playerID'], result['_id']) self.assertEqual(pp['nickname'], result['nickname']) # check that the player is not anymore listed in the game result = backend.games[0].getPlayer(pp['playerID']) self.assertEqual(result['status'], "ko") vprint(" > " + pp['nickname'] + ": was delisted but is still registered")
def test_registerPlayer(self): """ Test backend.registerPlayer """ vbar() print("test backend.registerPlayer") vbar() # initiate a backend backend = self.setUp() # register reference players vprint("Initiate a backend and register reference players:") for pp in refPlayers(True): result = backend.registerPlayer(pp['nickname'], pp['passwordHash']) self.assertEqual(result['status'], "ok") vprint(" - register " + pp['nickname'] + ": " + str(result['playerID'])) pp_db = getPlayersColl().find_one({'nickname': pp['nickname']}) self.assertEqual(result['playerID'], str(pp_db['_id'])) # re-register the same players => should fail vprint("Re-register the same players: it should fail") for pp in refPlayers(True): result = backend.registerPlayer(pp['nickname'], pp['passwordHash']) vprint(" - register " + pp['nickname'] + ": " + result['status'] + " - " + result['reason']) self.assertEqual(result['status'], "ko") self.assertEqual(result['reason'], "invalid nickname")
def test_delistPlayer(self): """ Test game.getPoints """ vbar() print("Test game.delistPlayer") vbar() # load the reference data Donald = refPlayers()[0] for test_data_index in range(0, 2): # load the reference game partie = self.setup(test_data_index) vprint("We load the reference game " + str(test_data_index) + ": Donald is enlisted") # delist Donad and check the result answer = partie.delistPlayer(Donald['playerID']) self.assertEqual(answer['status'], "ok") vprint(" > we delist Donald") for pp in partie.players: self.assertFalse(pp['playerID'] == Donald['playerID']) vprint(" > Donald is not in the players' list anymore") # we try delisting an unknown player answer = partie.delistPlayer(ObjectId()) self.assertEqual(answer['status'], "ko") vprint(" > we delist an unkown player: it fails")
def test_isPlayerIDValid(self): """ Test shared.isPlayerIDValid """ # setup the test data players = self.setUp() vbar() print("Test shared.isPlayerIDValid") vbar() vprint("We test the validity of several playerIDs and compare the result with") vprint("the reference test data:") # test with the valid IDs in the DB for pp in refPlayers(): playerID_ref = pp['playerID'] # test if the 'reference' playerID are recognized result = isPlayerIDValid(playerID_ref) vprint(" " + pp['nickname'] + ": playerID = " + str(playerID_ref) + " is considered valid : " + str(result)) self.assertTrue(result) # now test with wrong IDs invalid_IDs = [ {'playerID': '57b9a303124e9b13e6759bda'}, {'playerID': '57b9a003124e9b13e6751bdb'}, {'playerID': '57b9a003124e9b13e6757bdc'}, {'playerID': '57b9fffb124e9b2e056a765c'}, {'playerID': '57b9bffb124e9b2eb56a765d'}, {'playerID': '5748529a124e9b6187cf6c2a'} ] for pID in invalid_IDs: result = isPlayerIDValid(pID['playerID']) vprint(" playerID " + str(pID['playerID']) + " is considered invalid : " + str(result)) self.assertFalse(result) # end of the test self.teardown(players)
def test_getPlayers(self): """ Test players.getPlayers """ # setup the test data self.setUp() players = Players() vbar() print("Test players.getPlayers") vbar() vprint( "We collect the players from the DB structure, and compare with the" ) vprint("reference test data:") test_players = players.getPlayers() ref_players = refPlayers(True) # check that there are the same number of players on DB and reference lref = len(ref_players) ltest = len(test_players) result = (lref == ltest) vprint(" - there are " + str(ltest) + " players in the DB: " + str(result)) self.assertTrue(result) # check that the DB is the same as the reference for pp_ref in ref_players: result = (pp_ref in test_players) vprint(" " + pp_ref['nickname'] + ": " + str(result)) self.assertTrue(result) # end of the test self.teardown(players)
def test_deserialize(self): """ Test players.deserialize """ # setup the test data self.setUp() players = Players() # We copy in 'target' the reference players (as in 'refPlayersDict') # without the password target = {'__class__': 'SetPlayers', 'players': []} for pp in refPlayers_Dict(): target['players'].append({ 'playerID': pp['playerID'], 'nickname': pp['nickname'], 'passwordHash': pp['passwordHash'], 'totalScore': pp['totalScore'], 'gameID': pp['gameID'] }) players.deserialize(target) # runs the test vbar() print("Test players.deserialize") vbar() vprint( "We erase and rebuilt the DB thanks to the 'deserialize' method, and we" ) vprint( "then compare the 'serialized' image of this new DB with the target," ) vprint("which is:") vprint(target) result = players.serialize() self.assertTrue(playersDict_equality(target, result)) # end of the test self.teardown(players)
def test_getGameID(self): """ Test game.getGameID """ vbar() print("Test game.getGameID") vbar() # retrieve gameID (as a string) and check compliance' test_data_index = 0 partie = self.setup(test_data_index) test_gameID_str = str( partie.getGameID()) # the result must be a string ref_gameID_str = refGameHeader_start()[test_data_index]['gameID'] result = (ref_gameID_str == test_gameID_str) self.assertTrue(result) vprint(" > returned gameID is compliant: " + str(result))
def test_ForTestOnly_LoadRefGame(self): """ Test backend.ForTestOnly_LoadRefGame """ vbar() print("Test backend.ForTestOnly_LoadRefGame") vbar() # initiate a backend and register reference players for test_data_index in (0,1): backend = self.setUp() backend.ForTestOnly_LoadRefGame(test_data_index) # compare the backend with the reference test data self.assertEqual(backend.nextGameID, None) self.assertEqual(backend.playersWaitingList, []) result = gameRef_compliant(backend.games[0], test_data_index) vprint(" > Index " + str(test_data_index) + ": " + str(result)) self.assertTrue(result)
def test_ForTestOnly_EnlistRefPlayers(self): """ Test backend.ForTestOnly_EnlistRefPlayers """ vbar() print("Test backend.ForTestOnly_EnlistRefPlayers") vbar() # initiate a backend adn register reference players backend = self.setUp() backend.ForTestOnly_RegisterRefPlayers() # enlist reference players and check the result. result = backend.ForTestOnly_EnlistRefPlayers() gameID = result['gameID'] vprint("Game initiated with gameID = " + str(gameID)) self.assertEqual(result['status'], "ok") for pp in backend.players.getPlayers(): self.assertEqual(pp['gameID'], gameID) vprint(" - enlisted successfully " + pp['nickname'])
def test__init__(self): """ Test Step.__init__ """ # setup the test data vbar() vprint("We build test data for testing the class Step") step_test = Step() # run the test vbar() print("Test Step.__init__") vbar() vprint("We build a new Step and check that all fields are empty.") self.assertEqual(step_test.turnCounter, 0) self.assertEqual(step_test.playerID, None) self.assertEqual(step_test.nickname, "") self.assertEqual(step_test.pick, []) self.assertEqual(step_test.table, []) self.assertEqual(step_test.used, []) self.assertEqual(step_test.set, [])
def test_checkPassword(self): vbar() print("Test shared_crypto.checkPassword") vbar() vprint("We check that all reference test player's (password + hash) is ok") for pp in refPlayers_Dict(): self.assertTrue(checkPassword(pp['password'], pp['passwordHash'])) vprint(" > " + pp['nickname'] + ": couple (password + hash) is ok") vprint("We now check that other couples are not ok:") for pp in refPlayers_Dict(): for yy in refPlayers(): if pp['nickname'] != yy['nickname']: self.assertFalse(checkPassword(pp['password'], yy['passwordHash'])) vprint(" > " + pp['nickname']+ "'s password and " + yy['nickname'] + "'s hash do not correspond")
def test_updateTotalScore(self): """ Test players.updateTotalScore """ # setup the test data self.setUp() players = Players() # runs the test vbar() print("Test players.updateTotalScore") vbar() vprint( "We check that we can properly update the 'totalScore' with more points" ) vprint("(typically updating the 'totalScore' after a game ended).") # self.list_test_players(players.playersColl) pid = players.getPlayerID("Daisy")['playerID'] self.assertTrue(players.updateTotalScore(pid, 5)) self.assertEqual( players.playersColl.find_one({'nickname': "Daisy"})['totalScore'], 50) for pp in players.playersColl.find({}): vprint(" " + pp['nickname'] + " - totalScore: " + str(pp['totalScore'])) # end of the test self.teardown(players)
def test_ForTestOnly_RegisterRefPlayers(self): """ Test backend.ForTestOnly_RegisterRefPlayers """ vbar() print("Test backend.ForTestOnly_RegisterRefPlayers") vbar() # initiate a backend backend = self.setUp() # register reference players vprint("Initiate a backend and register reference players:") backend.ForTestOnly_RegisterRefPlayers() # compare the registered players with the reference test data for pp_ref in refPlayers(True): pp_test = backend.players.getPlayer(pp_ref['playerID']) self.assertEqual(pp_test['status'], "ok") self.assertEqual(pp_test['playerID'], pp_ref['playerID']) self.assertEqual(pp_test['nickname'], pp_ref['nickname']) self.assertEqual(pp_test['passwordHash'], pp_ref['passwordHash']) self.assertEqual(pp_test['totalScore'], 0) self.assertEqual(pp_test['gameID'], None) vprint(" - registered successfully " + pp_ref['nickname'])
def test_ForTestOnly_GetBackToTurn(self): """ Test backend.ForTestOnly_GetBackToTurn """ vbar() print("Test backend.ForTestOnly_GetBackToTurn") vbar() # initiate a backend and load a reference game for test_data_index in (0,1): # build the test data backend = self.setUp() backend.ForTestOnly_RegisterRefPlayers() backend.ForTestOnly_LoadRefGame(test_data_index) backend.ForTestOnly_GetBackToTurn(test_data_index,9) # build the reference data game_ref = gameSetupAndProgress(test_data_index, 9) # compare the test and reference test data result = game_compliant(backend.games[0], game_ref) self.assertEqual(backend.nextGameID, None) self.assertEqual(backend.playersWaitingList, []) vprint(" > Index " + str(test_data_index) + ": " + str(result)) self.assertTrue(result)
def test_serialize(self): """ Test players.serialize """ # build the reference data (without the passwrds) target = {'__class__': 'SetPlayers', 'players': []} for pp in refPlayers_Dict(): target['players'].append({ 'playerID': pp['playerID'], 'nickname': pp['nickname'], 'passwordHash': pp['passwordHash'], 'totalScore': pp['totalScore'], 'gameID': pp['gameID'] }) # setup the test data self.setUp() players = Players() gameID1 = ObjectId('57bf224df9a2f36dd206845a') gameID2 = ObjectId('57bf224df9a2f36dd206845b') players.enlist(players.getPlayerID("Daisy")['playerID'], gameID1) players.enlist(players.getPlayerID("Donald")['playerID'], gameID1) players.enlist(players.getPlayerID("Riri")['playerID'], gameID2) players.enlist(players.getPlayerID("Fifi")['playerID'], gameID2) players.enlist(players.getPlayerID("Loulou")['playerID'], gameID2) # runs the test vbar() print("Test players.serialize") vbar() vprint( "We compare the result of the 'serialize' method with the target which is:" ) vprint(target) # check that the class is equal result = players.serialize() self.assertTrue(playersDict_equality(target, result)) # end of the test self.teardown(players)
def test_changeHash(self): """ Test players.changeHash """ # setup the test data vbar() print("Test players.changeHash") vbar() vprint( "We change the hash of the players in the DB and compare the result with" ) vprint("the expected test data:") # test valid players self.setUp() players = Players() new_hash = "lEyycZ2UYZV0bX6ChdtSA5MGCmN3BrF1xoZG4TMRzEmwmpp" for pp in refPlayers(): playerID = pp['playerID'] result = players.changeHash(playerID, new_hash) valid = (result['status'] == "ok") and (result['passwordHash'] == new_hash) vprint(" " + pp['nickname'] + ": result = " + str(result)) self.assertTrue(valid) # test unknown player result = players.getHash(ObjectId()) valid = (result['status'] == "ko") and (result['reason'] == "unknown playerID") vprint(" Unknown player: result = " + str(result)) self.assertTrue(valid) # test invalid playerID result = players.getHash("invalid") valid = (result['status'] == "ko") and (result['reason'] == "invalid playerID") vprint(" Invalid playerID: result = " + str(result)) self.assertTrue(valid) # end of the test self.teardown(players)
def test_isNicknameAvailable(self): """ Test backend.isNicknameAvailable """ vbar() print("test backend.isNicknameAvailable") vbar() # initiate a backend backend = self.setUp() # check availability of nicknames before and after registering players vprint("Initiate a backend with no players registered, and check nickname availaiblity") vprint("before and after registering reference players:") for pp in refPlayers(True): # check the nickname is available before the player is registered answer = backend.isNicknameAvailable(pp['nickname']) self.assertEqual(answer['status'], "ok") vprint(" > " + pp['nickname'] + " is available") # register the player result = backend.registerPlayer(pp['nickname'], pp['passwordHash']) vprint(" - register " + pp['nickname'] + ": " + str(result['playerID'])) # check the nickname is not available after the player is registered answer = backend.isNicknameAvailable(pp['nickname']) self.assertEqual(answer['status'], "ko") vprint(" > " + pp['nickname'] + " is not available anymore")
def test_serialize(self): """ Test the serialize method """ # setup the test data cards_ref = self.setup() # runs the test vbar() vprint("Test cardset.serialize", True) vbar() dict_test_0 = cards_ref[0].serialize() dict_test_1 = cards_ref[1].serialize() vprint( "We compare the reference cardset dictionary with the one produced by serialize method:" ) vprint(" Cardset 0: " + str(dict_test_0)) vprint(" Cardset 1: " + str(dict_test_1)) self.assertEqual(refGames_Dict()[0]['cardset'], dict_test_0) self.assertEqual(refGames_Dict()[1]['cardset'], dict_test_1) # end of the test self.teardown()
def test_register(self): """ Test players.register """ # test that the new player is actually added both in memory and in DB vbar() print("Test players.register") vbar() vprint( "We add a player and check that it is properly registered to the DB." ) vprint( "We also check that duplicate registering a player will not work.") # setup the test data self.setUp() players = Players() new_hash = "lEyycZ2UYZV0bX6ChdtSA5MGCmN3BrF1xoZG4TMRzEmwmpp" playerID = players.register("Dingo", new_hash)['playerID'] read_id = players.playersColl.find_one({'nickname': "Dingo"})['_id'] self.assertEqual(playerID, read_id) # replaced 'count' (deprecated) with 'count_documents' self.assertEqual(players.playersColl.count_documents({}), 7) # check the various fields of registered players pp = players.playersColl.find_one({'nickname': "Dingo"}) self.assertEqual(pp['_id'], playerID) self.assertEqual(pp['passwordHash'], new_hash) # check that it is impossible to register a duplicate nickname result = players.register("Daisy", new_hash) self.assertEqual(result['status'], "ko") self.assertEqual(result['reason'], "invalid nickname") # replaced 'count' (deprecated) with 'count_documents' self.assertEqual(players.playersColl.count_documents({}), 7) # summarize vprint(" We now have 7 players in the DB:") for pp in players.playersColl.find(): vprint(" " + pp['nickname']) # end of the test self.teardown(players)
def test_deRegister(self): """ Test players.deRegister """ # setup the test data self.setUp() players = Players() # removes a player vbar() print("Test players.deRegister") vbar() vprint("We first register all 6 reference test players.") pp = players.playersColl.find_one({'nickname': "Donald"}) self.assertTrue(players.deRegister(pp['_id'])) # replaced 'count' (deprecated) with 'count_documents' self.assertEqual(players.playersColl.count_documents({}), 5) pp = players.playersColl.find_one({'nickname': "Donald"}) self.assertEqual(pp, None) vprint("We removed Donald and check that we have 5 players left.") for pp in players.playersColl.find(): vprint(" " + pp['nickname']) # end of the test self.teardown(players)
def test_deserialize(self): """ Test Step.deserialize """ # setup the test data dictStart_ref = self.refStepStarts_Dict() [cardsets_ref, stepStarts_ref] = self.setup() dictStartBis_ref0 = refGames_Dict()[0]['steps'][0] dictStartBis_ref1 = refGames_Dict()[1]['steps'][0] stepStartBis_ref = refSteps() step_test = Step() # run the test vbar() print("Test Step.deserialize") vbar() vprint( "We compare the steps produced with the deserialize method with") vprint("reference steps, and check the output is correct") # test with the first series of Steps vprint() step_test.deserialize(dictStart_ref[0]) vprint(" > Cardets 0 - Step 0 - stepStart:") vprint(" Target: " + stepStarts_ref[0].toString(cardsets_ref[0], " ")) vprint(" Result: " + step_test.toString(cardsets_ref[0], " ")) self.assertTrue(step_equality(step_test, stepStarts_ref[0])) vprint() step_test.deserialize(dictStartBis_ref0) vprint(" > Cardets 0 - Step 0 - stepStartBis:") vprint(" Target: " + stepStartBis_ref[0][0].toString(cardsets_ref[0], " ")) vprint(" Result: " + step_test.toString(cardsets_ref[0], " ")) self.assertTrue(step_equality(step_test, stepStartBis_ref[0][0]))