Revised the User class in the AuthenticationTestCase and FlaskLoginTestCase test classes to accept the clear-text password instead of the password hash, to simplify the code.

This commit is contained in:
依瑪貓 2022-12-03 14:30:22 +08:00
parent 7e71115844
commit 2028cb1362
2 changed files with 10 additions and 10 deletions

View File

@ -35,14 +35,15 @@ _PASSWORD: str = "Circle Of Life"
class User:
"""A dummy user"""
def __init__(self, username: str, password_hash: str):
def __init__(self, username: str, password: str):
"""Constructs a dummy user.
:param username: The username.
:param password_hash: The password hash.
:param password: The clear-text password.
"""
self.username: str = username
self.password_hash: str = password_hash
self.password_hash: str = make_password_hash(
_REALM, username, password)
self.visits: int = 0
@ -63,8 +64,7 @@ class AuthenticationTestCase(TestCase):
auth: DigestAuth = DigestAuth(realm=_REALM)
auth.init_app(app)
self.user: User = User(
_USERNAME, make_password_hash(_REALM, _USERNAME, _PASSWORD))
self.user: User = User(_USERNAME, _PASSWORD)
user_db: t.Dict[str, User] = {_USERNAME: self.user}
@auth.register_get_password

View File

@ -35,14 +35,15 @@ _PASSWORD: str = "Circle Of Life"
class User:
"""A dummy user."""
def __init__(self, username: str, password_hash: str):
def __init__(self, username: str, password: str):
"""Constructs a dummy user.
:param username: The username.
:param password_hash: The password hash.
:param password: The clear-text password.
"""
self.username: str = username
self.password_hash: str = password_hash
self.password_hash: str = make_password_hash(
_REALM, username, password)
self.visits: int = 0
self.is_authenticated: bool = True
self.is_active: bool = True
@ -85,8 +86,7 @@ class FlaskLoginTestCase(TestCase):
auth: DigestAuth = DigestAuth(realm=_REALM)
auth.init_app(app)
self.user: User = User(
_USERNAME, make_password_hash(_REALM, _USERNAME, _PASSWORD))
self.user: User = User(_USERNAME, _PASSWORD)
user_db: t.Dict[str, User] = {_USERNAME: self.user}
@auth.register_get_password