Esempio n. 1
0
    def setUp(self):
        """ creates game data needed for tests """

        self.board = {"game_id": "oh look a new id, how novel",
        "graph": {"nodes": "node4(node2(node3)(node1))(node6(node5))",
        "node_points": {"node1": 1,"node2": 2,"node3": 3,"node4": 4,"node5": 5,"node6": 6},
        "gold_node": "node5","balanced": True},"player_ids": ["id2","id3","id4","id5"],
        "player_names": ["naomi","kulsoom","nick","ryan"],
        "player_points": {"id2": 2,"id3": 2,"id4": 3,"id5": 10},"turn": "id2",
        "cards": {"id2": ["card1","card2","card3"],"id3": ["card1","card2","card3"],
        "id4":["card1","card2","card3"],"id5": ["card1","card2","card3"]},
        "gold_node": False,"difficulty": "Medium","num_players": 4,"online": True,
        "curr_data_structure": "AVL","selected_data_structures": ["AVL","Stack"],
        "timed_game": False,"seconds_until_next_ds": 60,"time_created": "07/10/2020 00:05:47",
        "end_game": False}
        self.board2 = {"game_id": "i changed the id again",
        "graph": {"nodes": "node4(node2(node3)(node1))(node6(node5))",
        "node_points": {"node1": 1,"node2": 2,"node3": 3,"node4": 4,"node5": 5,"node6": 6},
        "gold_node": "node5","balanced": True},"player_ids": ["id2","id3","id4","id5"],
        "player_names": ["naomi","kulsoom","nick","ryan"],
        "player_points": {"id2": 2,"id3": 2,"id4": 3,"id5": 10},"turn": "id2",
        "cards": {"id2": ["card1","card2","card3"],"id3": ["card1","card2","card3"],
        "id4":["card1","card2","card3"],"id5": ["card1","card2","card3"]},
        "gold_node": False,"difficulty": "Medium","num_players": 4,"online": True,
        "curr_data_structure": "AVL","selected_data_structures": ["AVL","Stack"],
        "timed_game": False,"seconds_until_next_ds": 60,
        "time_created": dt.datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
        "end_game": False}
        self.fail_phrase = 'nah bro idk about it'

        mongo.create_game( self.board )
        mongo.create_game( self.board2 )
Esempio n. 2
0
    def setUp(self):
        """ creates game data needed for tests """

        self.board = {"game_id": "60afce36-085a-11eb-b6ab-acde48001122",
        "graph": {"nodes": "node4(node2(node3)(node1))(node6(node5))",
        "node_points": {"node1": 1,"node2": 2,"node3": 3,"node4": 4,"node5": 5,"node6": 6},
        "gold_node": "node5","balanced": True},"player_ids": ["id2","id3","id4","id5"],
        "player_names": ["naomi","kulsoom","nick","ryan"],
        "player_points": {"id2": 2,"id3": 2,"id4": 3,"id5": 10},"turn": "id2",
        "cards": {"id2": ["card1","card2","card3"],"id3": ["card1","card2","card3"],
        "id4":["card1","card2","card3"],"id5": ["card1","card2","card3"]},
        "gold_node": False,"difficulty": "Medium","num_players": 4,"online": True,
        "curr_data_structure": "AVL","selected_data_structures": ["AVL","Stack"],
        "timed_game": False,"seconds_until_next_ds": 60,"time_created": "07/10/2020 00:05:47",
        "end_game": False}

        self.board2 = {"game_id": "60afce36-085a-11eb-b6ab-acde48001122",
        "graph": {"nodes": "node4(node2(node3)(node1))(node6(node5))",
        "node_points": {"node1": 1,"node2": 2,"node3": 3,"node4": 4,"node5": 5,"node6": 6},
        "gold_node": "node5","balanced": True},"player_ids": ["changed player","id3","id4","id5"],
        "player_names": ["naomi","kulsoom","nick","ryan"],
        "player_points": {"id2": 2,"id3": 2,"id4": 3,"id5": 10},"turn": "id2",
        "cards": {"id2": ["card1","card2","card3"],"id3": ["card1","card2","card3"],
        "id4":["card1","card2","card3"],"id5": ["card1","card2","card3"]},
        "gold_node": False,"difficulty": "Medium","num_players": 4,"online": True,
        "curr_data_structure": "AVL","selected_data_structures": ["AVL","Stack"],
        "timed_game": False,"seconds_until_next_ds": 60,"time_created": "07/10/2020 00:05:47",
        "end_game": False}

        self.fail_phrase = 'nah bro idk about it'

        mongo.create_game( self.board )
Esempio n. 3
0
    def test_duplicatecreate(self):
        """ The document is a duplicate and should fail creation in the database """
        created_game = mongo.create_game( self.board )
        created_game = mongo.create_game( self.board )

        self.assertEqual( created_game, self.fail_phrase,
            msg=f'{BColors.FAIL}\t[-]\tGame was not created in the Database!{BColors.ENDC}')
        print(f"{BColors.OKGREEN}\t[+]\tPass gameboard database save duplicate.{BColors.ENDC}")
Esempio n. 4
0
def create_board_db(new_board):
    """
    Creates a new game board instance in the database.
    Returns the error information if fails, or the game board ID.
    If
    :param new_board: dictionary for that represents the game board state.
    :return result, {'error': bool, 'reason': string, 'game_id': string}:
    """
    result = {'error': False, 'reason': '', 'game_id': ''}

    try:
        game_id = db.create_game(new_board)

        if game_id == "nah bro idk about it":
            result['error'] = True
            result['reason'] = "Game Already Exist!"
            return result

        result['game_id'] = json.loads(json_util.dumps(game_id))

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

        return result

    return result
Esempio n. 5
0
    def test_create(self):
        """ The gamboard document was created in the database """
        created_game = mongo.create_game( self.board )

        self.assertEqual( created_game, "60afce36-085a-11eb-b6ab-acde48001122",
            msg=f'{BColors.FAIL}\t[-]\tGame was not created in the Database!{BColors.ENDC}')
        print(f"{BColors.OKGREEN}\t[+]\tPass gameboard database save.{BColors.ENDC}")