Ex 52- need some help for testing

I think I have sorted out almost all the bugs Mr. Shaw mentioned. I now need advice on how to write the tests for the app.py - I absolutely have no idea on how to test if the return values of load_room() and the name_room() functions. I tried writing one test for the game function but it didn’t work out. Below are codes.

planisphere.py

class Room(object):

    def __init__(self, name, description):
        self.name = name
        self.description = description
        self.paths = {}

    def go(self, direction):
        return self.paths.get(direction, None)

    def add_paths(self, paths):
        self.paths.update(paths)


central_corridor = Room("Central Corridor",
"""
The Gothons of Planet Percal #25 have invaded you ship and destroyed your entire
crew.  You are the last surviving member and your last mission is to get the
neutron destruct bomb from the Weapons Armory, put it in the bridge, and blow
the ship up after getting into an escape pod.

You're runnig down the central corridor to the Weapons Armory when a Gothon
jumps out, red scaly skin, dark grimy teeth, and evil clown costume flowing
around his hate filled body.  He's blocking the door to the Armory and about to
pull a weapon to blast you.
""")

laser_weapon_armory = Room("Laser Weapon Armory",
"""
Lucky for you they made you learn Gothon insults in the academy. You tell the
one Gothon joke you know: Lbhe zbhure vj fb, jura for fvgf nebhaq gur ubhfr, fur
 fvgf nebhaq qur ubhfr.  The Gothon stops, tries not to laugh, then busts out
laughing and can't move. While he's laughing you run up and shoot him square in
 the head putting him down. then jump through the Weapon Armory door.

You dive roll into the Weapon Armory, crouch and scan.  Enter the passcode to
obtain the neutro bomb. The code is 3 digits.
""")

the_bridge = Room("The Bridge",
"""
You take the nuetron bomb and run to the bridge.

There are 5 Gothons standing on the bridge. They have not pulled their weapon as
 they see the bomb under your arms and don't want to set it off.""")

escape_pod = Room("Escape Pod",
"""
You point your blaster at the bomb under your arm and the Gothons raise their
hands and start to sweat. You escape from them after placing the bomb and rush
to the escape pod. There are 5 pods which one do you take. Some of them could
 be damaged.""")

the_end_winner = Room("The End",
"""
You jump into the 2 pod and eject out of the ship. You see your ship implode and
 explode taking the Gothon Ship with it. """)

the_end_loser = Room("The End",
"""
You jump into a random pod and hit the eject button. The pod escapes out into
the void of space, then implodes as the hull rutures, crushing your body into a
jam jelly.
"""
)

shoot = Room("You Died",
"""
You shoot the gothon with you laser gun, but your shot reflected off its scaly skin.
The gothon gets angry and jumps on you.
You are smashed to death.
""")

dodge = Room("You Died",
"""
You dodge the initial attacks of the gothon like a master ninja from the old movies you have watched.
But soon you lose your balance and slip, and hit the floor hard. You pass out.
You blink awake only to fell your death plunge into your face and the gothon eats you.
""")

throw_the_bomb = Room("Gothons kill you",
"""
In panic you throw the bomb at the group of Gothons and make a leap
for the door. Right as you drop it a Gothon shoots you right in the
back killing you. As you die you see another Gothon frantically try
to disarm the bomb. You die knowing that they will probably blow up
when it goes off.
""")

wrong_pin = Room("Wrong pin",
"""
The lock closes with a sickening melting sound as the mechanism is fused
together. You decide to sit there, and finally the Gothons blow your
ship from their ship and you die.
""")


escape_pod.add_paths({
    '2': the_end_winner,
    '*': the_end_loser
})

generic_death= Room("death", "You died.")

the_bridge.add_paths({
    'throw the bomb': throw_the_bomb,
    'slowly place the bomb':escape_pod
})

laser_weapon_armory.add_paths({
    '132': the_bridge,
    '*': wrong_pin
})

central_corridor.add_paths({
    'shoot': shoot,
    'dodge': dodge,
    'tell a joke': laser_weapon_armory
})

START = 'central_corridor'

def load_room(name):
    """
    There is a potential security problem here.
    Who gets to set name? Can that expose a variable?
    """

    return globals().get(name)

def name_room(room):
    """
    Same possible security problem.  Can you trust room?
    What's a better solution than this globals lookup?
    """

    for key, value in globals().items():
        if value == room:
            return key

app.py

from flask import Flask, session, redirect, url_for, escape, request
from flask import render_template
from gothonweb import planisphere

app = Flask(__name__)

@app.route('/')
def index():
    session['room_name'] = planisphere.START
    return redirect(url_for("game"))

@app.route("/game", methods=['GET', 'POST'])
def game():
    room_name = session.get('room_name')

    if request.method == 'GET':
        if room_name:
            room = planisphere.load_room(room_name)
            return render_template("show_room.html", room=room)
        else:
            return render_template("you_died.html")
    else:
        action = request.form.get('action')

        if room_name and action:
            room = planisphere.load_room(room_name)
            next_room = room.go(action)
            print("Before checking for next_room:", room, next_room, room_name)

            if not next_room:
                if '*' in room.paths:
                    print(
                    "None in next_room - Before assigning, room_name= ",
                    session['room_name']
                    )

                    session['room_name'] = planisphere.name_room(room.go('*'))

                    print(
                    "None in next_room - After assigning, room_name= ",
                    session['room_name']
                    )

            else:
                session['room_name'] = planisphere.name_room(next_room)

    return redirect(url_for("game"))

app.secret_key = 'A0Zr98j/3yX R-XHH!jmNJLWX/,?RT'

if __name__ == "__main__":
    app.run()    

and app_tests.py

from nose.tools import *
from app import app

app.config['TESTING'] = True
web = app.test_client()

def test_index():
    rv = web.get('/', follow_redirects=True)
    assert_equal(rv.status_code, 200)

    rv = web.get('/game', follow_redirects=True)
    assert_equal(rv.status_code, 200)

def test_app():
    #this test showed Typerror saying, "__call__() missing 2 required positional 
    #arguments: 'environ' and 'start_response'" 
    assert_equal(app(), '/game')

Please feel free to point any mistakes I have made and make any suggestion to improve my code.

I think you’re pretty close. You probably need to do one of two things:

  1. Test the Map/Engine directly and assert that the room you get back == the room you expect.
  2. Do what you have here and test from the front end, but then just test that the text of the Room is found in the HTML output.

See if you can figure it out from just that advice then bug me for more clues.

I have tested the Map program as you suggested and I will test the app as you said. Thanks for the advice.