def game_world(): """ Return a tuple containing game assets we can use for test purposes. """ database.OBJECTS = {} database.USERS = {} database.CONNECTIONS = {} # Make a user. user_uuid = logic.add_user("username", "description", "password", "*****@*****.**") user = database.OBJECTS[user_uuid] # Make an object. obj_uuid = logic.add_object("objectname", "object description", user) obj = database.OBJECTS[obj_uuid] # Make a room. room_uuid = logic.add_room("roomname", "room description", user) room = database.OBJECTS[room_uuid] # The user is in the room. user["_meta"]["location"] = room_uuid # The object is in the room. logic.drop(obj_uuid, user) # Create another room. other_room_uuid = logic.add_room("otherroomname", "room description", user) other_room = database.OBJECTS[other_room_uuid] # Create an exit between the current room and the other room. exit_uuid = logic.add_exit("exitname", "exit description", user, room, other_room) exit = database.OBJECTS[exit_uuid] # Provide the new user, object, room and exit for each test function. return (user, obj, room, exit)
async def test_take_not_an_object(game_world): """ Taking not-an-object results in an error. """ user, obj, room, exit = game_world obj2_id = logic.add_object("obj2", "description", user) obj2 = database.OBJECTS[obj2_id] obj2["_meta"]["alias"].append("objectname") with pytest.raises(ValueError): await parser.take(user, room, "objectname")
async def test_describe_cannot_identify_unique_object(game_world): """ If the wrong number of args for the command are encountered, raise an error. """ user, obj, room, exit = game_world other_obj_id = logic.add_object("obj2", "description", user) other_obj = database.OBJECTS[other_obj_id] other_obj["_meta"]["alias"].append("objectname") with pytest.raises(ValueError): await parser.describe(user, room, "objectname a new description")
async def test_get_objects_replace_indirect_obj_multi_matches(game_world): """ If the string of indirect_obj is the name or alias of multiple objects in the current context, raise a ValueError """ user, obj, room, exit = game_world new_obj = logic.add_object("obj2", "description", user) ob2 = database.OBJECTS[new_obj] ob2["_meta"]["alias"].append("objectname") args = 'dobj prep objectname' with pytest.raises(ValueError): await parser.get_objects(user, room, args)