Skip to content

Commit

Permalink
test: modify tests to work with hash based session
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaVls committed Sep 25, 2021
1 parent 895cca2 commit 4287e3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/tests/functional/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def test_login(self, test_client, login_response):
"""
GIVEN the '/auth/login' is posted to (POST)
WHEN using valid credencials username: 'test', password: 'test'
THEN check we get redirected to '/', and player_uid is saved in 'g' and session
THEN check we get redirected to '/', and player is saved in 'g'
"""
assert login_response.status_code == 200
assert b"Typefight!" in login_response.data # route redirects to index.html if data is correct
assert session["player_uid"] == "bff618f7-9aaa-43a5-9e1a-1b151bd5882f"
assert session["session_hash"]

# making sure we're logged in
new_response = test_client.get("/")
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_logout(self, login_response, test_client):

assert b"Typefight!" in logout_response.data
assert logout_response.status_code == 200
assert not "player_uid" in session
assert not "session_hash" in session

# making sure we're logged out
home_response = test_client.get("/")
Expand Down
24 changes: 22 additions & 2 deletions src/tests/functional/game_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,22 @@ def test_set_new_score(self, test_client, login_response):

with g.db as db:
cur = db.cursor()

cur.execute(
"""
SELECT player_uid
FROM players
WHERE player_name = %s;
""", (g.user["player_name"], )
)
player_uid = cur.fetchone()

cur.execute(
"""
DELETE FROM scores
WHERE player_uid = %s
AND quote_uid = %s;
""", (session["player_uid"], session["quote"]["quote_id"])
""", (player_uid, session["quote"]["quote_id"])
)
cur.close()

Expand All @@ -146,12 +156,22 @@ def test_update_score(self, test_client, login_response):
# resetting the score
with g.db as db:
cur = db.cursor()

cur.execute(
"""
SELECT player_uid
FROM players
WHERE player_name = %s;
""", (g.user["player_name"], )
)
player_uid = cur.fetchone()

cur.execute(
"""
UPDATE scores
SET score = 13.37
WHERE player_uid = %s;
""", (session["player_uid"], )
""", (player_uid, )
)
db.commit()
cur.close()
Expand Down

0 comments on commit 4287e3f

Please sign in to comment.