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]