Refactoring
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
"""
|
||||
This file (test_helper_functions.py) contains the unit tests for the helper_functions.py file.
|
||||
"""
|
||||
import datetime
|
||||
|
||||
import jwt
|
||||
from app.auth import *
|
||||
|
||||
|
||||
|
@@ -1,9 +1,6 @@
|
||||
"""
|
||||
This file (test_helper_functions.py) contains the unit tests for the helper_functions.py file.
|
||||
"""
|
||||
import datetime
|
||||
|
||||
import jwt
|
||||
from app.helper_functions import *
|
||||
|
||||
|
||||
@@ -21,47 +18,3 @@ def test_check_password():
|
||||
hashed = hash_password("password")
|
||||
assert check_password(hashed, "password".encode("utf-8")) is True
|
||||
assert check_password(hashed, "password1".encode("utf-8")) is False
|
||||
|
||||
|
||||
def test_get_email_from_token_data(test_client, init_database):
|
||||
"""
|
||||
Test get_email_from_token_data function
|
||||
"""
|
||||
|
||||
# Invalid token
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer XXXXX'})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") is None
|
||||
#
|
||||
# # empty token
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer'})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") is None
|
||||
#
|
||||
# # valid token
|
||||
# exp = datetime.datetime.utcnow() + datetime.timedelta(days=365)
|
||||
# token = jwt.encode({'email': "user@example.com", 'exp': exp}, "SECRET_KEY", "HS256")
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer ' + token})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") == "user@example.com"
|
||||
#
|
||||
# # expired token
|
||||
# exp = datetime.datetime.utcnow() + datetime.timedelta(days=-1)
|
||||
# token = jwt.encode({'email': "user@example.com", 'exp': exp}, "SECRET_KEY", "HS256")
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer ' + token})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") is None
|
||||
#
|
||||
# # bot token (includes ":") but user doesn't exist
|
||||
# exp = datetime.datetime.utcnow() + datetime.timedelta(days=365)
|
||||
# token = jwt.encode({'email': "bot@example.com", 'exp': exp}, "SECRET_KEY", "HS256")
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer ' + token + ':12345'})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") is None
|
||||
|
||||
# # bot token (includes ":") user exists
|
||||
# exp = datetime.datetime.utcnow() + datetime.timedelta(days=365)
|
||||
# token = jwt.encode({'email': "bot@example.com", 'exp': exp}, "SECRET_KEY", "HS256")
|
||||
# request_ctx = test_client.test_request_context(headers={'Authorization': 'Bearer ' + token + ':12345'})
|
||||
# request_ctx.push()
|
||||
# assert get_email_from_token_data("SECRET_KEY") is None
|
Reference in New Issue
Block a user