Пример #1
0
def load_board_db(game_id):
    """
    Loads the game board state from the database by its ID.

    :param game_id: board's ID
    :return: game board
    """
    result = {'error': False, 'reason': '', 'game_board': {}}

    try:
        game_board = db.read_game(str(game_id))
        if game_board == "nah bro idk about it":
            result['error'] = True
            result['reason'] = "Game Not Found!"
            return result

        # Serialize the JSON object
        game_board = json.loads(json_util.dumps(game_board))
        result['game_board'] = game_board

        # Remove the database entry ID from user's view
        del game_board['_id']

    except Exception as err:
        result['error'] = True
        result['reason'] = str(err)
        return result

    return result
Пример #2
0
    def test_read_correct(self):
        """ The document was read from the database """
        read_game = mongo.read_game("60afce36-085a-11eb-b6ab-acde48001122")

        self.assertEqual(
            read_game["game_id"],
            self.board["game_id"],
            msg=
            f'{BColors.FAIL}\t[-]\tGame Id returned from read board does not equal expected!\
            {BColors.ENDC}')
        print(
            f"{BColors.OKGREEN}\t[+]\tPass gameboard database read.{BColors.ENDC}"
        )
Пример #3
0
    def test_purge_new_games(self):
        """ The new document was successfully retained """
        mongo.purge_old_games()
        read_game = mongo.read_game(self.board2["game_id"])

        self.assertEqual(
            read_game,
            self.board2,
            msg=
            f'{BColors.FAIL}\t[-]\t New game not found after purge!{BColors.ENDC}'
        )
        print(
            f"{BColors.OKGREEN}\t[+]\tPass gameboard database purge, new game remains.{BColors.ENDC}"
        )
Пример #4
0
    def test_remove_old_games(self):
        """ The old document was successfully deleted """

        mongo.purge_old_games()
        read_game = mongo.read_game(self.board["game_id"])

        self.assertEqual(
            read_game,
            self.fail_phrase,
            msg=
            f'{BColors.FAIL}\t[-]\tStill found old game after purge!{BColors.ENDC}'
        )
        print(
            f"{BColors.OKGREEN}\t[+]\tPass gameboard database purge old games.{BColors.ENDC}"
        )
Пример #5
0
    def test_read_nonexist(self):
        """ The document should not be read from the database """
        read_game = mongo.read_game(
            "This name should really not exist in the database, and if it does, YEESH!"
        )

        self.assertEqual(
            read_game,
            self.fail_phrase,
            msg=
            f'{BColors.FAIL}\t[-]\tIncorrect return for non-existant game!{BColors.ENDC}'
        )
        print(
            f"{BColors.OKGREEN}\t[+]\tPass gameboard database read nonexistant.{BColors.ENDC}"
        )