Added the "create_test_app" function in testlib.py to replace "create_app" to prevent common mistakes. Added a get_csrf_token_view route to the application, and changed the get_csrf_token function to retrieve the CSRF token with the route without parsing the HTML for the CSRF token.

This commit is contained in:
2023-03-14 21:28:35 +08:00
parent 5d31eb9172
commit d9ecf51c6d
7 changed files with 54 additions and 68 deletions

View File

@@ -26,8 +26,7 @@ from click.testing import Result
from flask import Flask
from flask.testing import FlaskCliRunner
from test_site import create_app
from testlib import get_client
from testlib import create_test_app, get_client
LIST_URI: str = "/accounting/base-accounts"
"""The list URI."""
@@ -45,7 +44,7 @@ class BaseAccountCommandTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import BaseAccount, BaseAccountL10n
self.app: Flask = create_app(is_testing=True)
self.app: Flask = create_test_app()
runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context():
@@ -98,7 +97,7 @@ class BaseAccountTestCase(unittest.TestCase):
:return: None.
"""
from accounting.models import BaseAccount
self.app: Flask = create_app(is_testing=True)
self.app: Flask = create_test_app()
runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context():