Reordered the code in the test cases.

This commit is contained in:
依瑪貓 2022-11-23 23:36:41 +11:00
parent bf15bcf1f1
commit 292d0aaf09
2 changed files with 19 additions and 18 deletions

View File

@ -40,6 +40,13 @@ class AuthenticationTestCase(TestCase):
:return: The Flask application. :return: The Flask application.
""" """
app: Flask = Flask(__name__)
app.config.from_mapping({
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
})
app.test_client_class = Client
auth: DigestAuth = DigestAuth(realm=_REALM) auth: DigestAuth = DigestAuth(realm=_REALM)
user_db: t.Dict[str, str] \ user_db: t.Dict[str, str] \
= {_USERNAME: make_password_hash(_REALM, _USERNAME, _PASSWORD)} = {_USERNAME: make_password_hash(_REALM, _USERNAME, _PASSWORD)}
@ -63,13 +70,6 @@ class AuthenticationTestCase(TestCase):
return SimpleNamespace(username=username) if username in user_db \ return SimpleNamespace(username=username) if username in user_db \
else None else None
app: Flask = Flask(__name__)
app.config.from_mapping({
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
})
app.test_client_class = Client
@app.get("/login-required-1/auth", endpoint="auth-1") @app.get("/login-required-1/auth", endpoint="auth-1")
@auth.login_required @auth.login_required
def login_required_1() -> str: def login_required_1() -> str:

View File

@ -58,8 +58,19 @@ class FlaskLoginTestCase(TestCase):
:return: The Flask application. :return: The Flask application.
""" """
auth: DigestAuth = DigestAuth(realm=_REALM) app: Flask = Flask(__name__)
app.config.from_mapping({
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
})
app.test_client_class = Client
login_manager: LoginManager = LoginManager() login_manager: LoginManager = LoginManager()
login_manager.init_app(app)
auth: DigestAuth = DigestAuth(realm=_REALM)
init_login_manager(auth, login_manager)
user_db: t.Dict[str, str] \ user_db: t.Dict[str, str] \
= {_USERNAME: make_password_hash(_REALM, _USERNAME, _PASSWORD)} = {_USERNAME: make_password_hash(_REALM, _USERNAME, _PASSWORD)}
@ -72,16 +83,6 @@ class FlaskLoginTestCase(TestCase):
""" """
return user_db[username] if username in user_db else None return user_db[username] if username in user_db else None
app: Flask = Flask(__name__)
app.config.from_mapping({
"SECRET_KEY": token_urlsafe(32),
"TESTING": True
})
app.test_client_class = Client
login_manager.init_app(app)
init_login_manager(auth, login_manager)
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id: str) -> t.Optional[User]: def load_user(user_id: str) -> t.Optional[User]:
"""Loads a user. """Loads a user.