Ex52- making test for session ['count']

Hi peeps,

I’m having trouble configuring a pytest for the session[‘count’] in ex52 i looked up how to modify the session within a test in the flask documentation but i can’t get it to work. I tested the game manually and it works but the test just keeps his own count.

My pytest for the keypad, i also tried this code out with ‘session’ instead of sess (sess is what flask doc uses for tests):

[code]

def test_key_pad():
    planisphere.START = 'laser_weapon_armory'
    with app.test_client() as c:
        with c.session_transaction() as sess:
        rv = web.get('/', follow_redirects = True)
        sess['count'] = 10
        assert sess['count'] == 10
        assert b'Laser Weapon Armory' in rv.data
        data = {'action': '1234'}
        rv = web.post('/game', follow_redirects = True, data = data)
        assert b'You died' in rv.data

my app.py code:

else:
    action = request.form.get('action')

    if room_name == 'laser_weapon_armory' and action:
        room = planisphere.load_room(room_name)
        next_room = room.go(action)
        if not next_room and session['count'] != 10:
            session['room_name'] = planisphere.name_room(room)
            session['count'] += 1
            print("count =", session['count'])
        elif not next_room and session['count'] == 10:
            session['room_name'] = 'generic_death'
        else:
            session['room_name'] = planisphere.name_room(next_room)

[code]

Whew! That’s going to be a tough one to do. My suggestion is avoid confirming the backend works (like looking inside session), and instead just work the HTML you get from the front end and confirm that you’re getting the output you expect. So, in theory if you’re posting to the session, and you are using the session in your web output, then you should be able to detect that the session is not working because it doesn’t show up in the session.

So in this case, instead of checking that session[‘count’] reaches 10, just work it 10 times like a user clicking on stuff until you die.

Does that make sense?