def test_from_mongo_result_performs_mapping(self): """Test that mapping a Game object from a MonoDB result is correct""" gd = { "_id": "id", "_Game__genre": "genre", "_Game__title": "title", "_Game__platform": "platform", "_Game__num_copies": 1, "_Game__num_boxed": 2, "_Game__num_manuals": 3, "_Game__notes": "notes", "_Game__date_purchased": "2015-05-23", "_Game__approximate_date_purchased": True } g = Game.from_mongo_result(gd) expected_mappings = { "_id": g.id, "_Game__title": g.title, "_Game__genre": g.genre, "_Game__platform": g.platform, "_Game__num_copies": g.num_copies, "_Game__num_boxed": g.num_boxed, "_Game__num_manuals": g.num_manuals, "_Game__notes": g.notes, "_Game__date_purchased": g.date_purchased, "_Game__approximate_date_purchased": g.approximate_date_purchased } for k,v in expected_mappings.items(): self.assertEqual(gd[k], v)
def get_game(self, game_id, user_id): """Gets a specific game if it matches the given user. :param game_id: A string containing the uuid of the game :param user_id: A string containing the uuid of the given user :returns: An object of type Game """ try: cursor = self.__db.games.find_one({ "_id": ObjectId(game_id), "user_id": str(user_id) }) return Game.from_mongo_result(cursor) except InvalidId: raise GameNotFoundException
def __map_games_list(self, result_set): return list(map(lambda g: Game.from_mongo_result(g), result_set))