Esempio n. 1
0
    def test_players_db(self):
        """ Testing player functions
        player.insert_player_into_db
        player.get_players_from_db
        player.get_player_from_db_by_name
        player.update_player_by_name
        """ 
        clear_tables(self.db)

        # test empty players
        test_players = player.get_players_from_db(GAME_ID1, self.db)
        assert (test_players == [])
        test_names = player.get_player_names_from_db(GAME_ID1, self.db)
        assert (test_names == [])

        # insert player
        test_player = player.Player (*TEST_PLAYER_VALUES1)
        player.insert_player_into_db(test_player, self.db)
        db_player = player.get_players_from_db(test_player.game_id, self.db)[0]
        assert db_player == test_player
        # get player
        db_player2 = player.get_player_from_db_by_name(db_player.name, db_player.game_id, self.db)
        assert(db_player2 == db_player)
        # update player
        cur_id = db_player.id_num
        db_player.id_num = cur_id + 1
        player.update_player_by_name(db_player, self.db)
        # get player
        new_db_player = player.get_player_from_db_by_name(
            db_player.name, db_player.game_id, self.db)
        assert(new_db_player.id_num == db_player.id_num)
Esempio n. 2
0
 def test_clear(self):
     test_dice = dice.initialize_dice(3,'0')
     dice.insert_dice_into_db(test_dice, self.db)
     test_player = player.Player (*TEST_PLAYER_VALUES1)
     player.insert_player_into_db(test_player, self.db)
     assert len(player.get_players_from_db(test_player.game_id, self.db)) > 0
     assert len(dice.get_dice_from_db(test_dice.game_id, self.db).dice_dic) > 0
     clear_tables(self.db)
     assert len(player.get_players_from_db(test_player.game_id, self.db)) == 0
     assert dice.get_dice_from_db(test_dice.game_id, self.db) == None
Esempio n. 3
0
def initialize_game(game_id, db):
    """ input: game_id String, db Database
    """
    # initialize players
    players = player.get_players_from_db(game_id, db)
    random.seed(2)
    random.shuffle(players)
    for i, p in enumerate(players):
        p.id_num = i
        p.p_left_name = _get_left_item(players,i).name
        p.p_right_name = _get_right_item(players,i).name
        player.update_player_by_name(p, db)
    # initialize dice
    dice.insert_dice_into_db(dice.initialize_dice(len(players), game_id), db)
    status.set_round_in_db(0, game_id, db)
Esempio n. 4
0
 def playerjoin():
     name = request.form['data']
     if not name in player.get_players_from_db(GAME_ID, get_db()):
         player.insert_player_into_db(player.Player(name=name, game_id=GAME_ID), db=get_db())
     session['player'] = name
     return ''