Replaced the import for the db object from the accounting model with the test site in test_account.py and test_currency.py. They are the same object, and the db object from the test site is safe at the compile time.

This commit is contained in:
依瑪貓 2023-02-25 18:03:25 +08:00
parent f878ba5535
commit 5a6e4f5b5e
2 changed files with 2 additions and 15 deletions

View File

@ -26,7 +26,7 @@ from click.testing import Result
from flask import Flask from flask import Flask
from flask.testing import FlaskCliRunner from flask.testing import FlaskCliRunner
from test_site import create_app from test_site import create_app, db
from testlib import get_client, set_locale from testlib import get_client, set_locale
@ -75,7 +75,6 @@ class AccountCommandTestCase(unittest.TestCase):
runner: FlaskCliRunner = self.app.test_cli_runner() runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context(): with self.app.app_context():
from accounting import db
from accounting.models import BaseAccount, Account, AccountL10n from accounting.models import BaseAccount, Account, AccountL10n
result: Result result: Result
result = runner.invoke(args="init-db") result = runner.invoke(args="init-db")
@ -129,7 +128,6 @@ class AccountTestCase(unittest.TestCase):
runner: FlaskCliRunner = self.app.test_cli_runner() runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context(): with self.app.app_context():
from accounting import db
from accounting.models import BaseAccount, Account, AccountL10n from accounting.models import BaseAccount, Account, AccountL10n
result: Result result: Result
result = runner.invoke(args="init-db") result = runner.invoke(args="init-db")
@ -316,7 +314,6 @@ class AccountTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting import db
from accounting.models import Account from accounting.models import Account
create_uri: str = f"{PREFIX}/create" create_uri: str = f"{PREFIX}/create"
store_uri: str = f"{PREFIX}/store" store_uri: str = f"{PREFIX}/store"
@ -489,7 +486,6 @@ class AccountTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting import db
from accounting.models import Account from accounting.models import Account
detail_uri: str = f"{PREFIX}/{cash.code}" detail_uri: str = f"{PREFIX}/{cash.code}"
update_uri: str = f"{PREFIX}/{cash.code}/update" update_uri: str = f"{PREFIX}/{cash.code}/update"
@ -652,7 +648,6 @@ class AccountTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting import db
from accounting.models import Account from accounting.models import Account
response: httpx.Response response: httpx.Response
@ -704,7 +699,6 @@ class AccountTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting import db
from accounting.models import Account from accounting.models import Account
response: httpx.Response response: httpx.Response

View File

@ -27,7 +27,7 @@ from click.testing import Result
from flask import Flask from flask import Flask
from flask.testing import FlaskCliRunner from flask.testing import FlaskCliRunner
from test_site import create_app from test_site import create_app, db
from testlib import get_client, set_locale from testlib import get_client, set_locale
@ -71,7 +71,6 @@ class CurrencyCommandTestCase(unittest.TestCase):
runner: FlaskCliRunner = self.app.test_cli_runner() runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context(): with self.app.app_context():
from accounting import db
from accounting.models import Currency, CurrencyL10n from accounting.models import Currency, CurrencyL10n
result: Result result: Result
result = runner.invoke(args="init-db") result = runner.invoke(args="init-db")
@ -128,7 +127,6 @@ class CurrencyTestCase(unittest.TestCase):
runner: FlaskCliRunner = self.app.test_cli_runner() runner: FlaskCliRunner = self.app.test_cli_runner()
with self.app.app_context(): with self.app.app_context():
from accounting import db
from accounting.models import Currency, CurrencyL10n from accounting.models import Currency, CurrencyL10n
result: Result result: Result
result = runner.invoke(args="init-db") result = runner.invoke(args="init-db")
@ -270,7 +268,6 @@ class CurrencyTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting.models import Currency from accounting.models import Currency
from test_site import db
create_uri: str = f"{PREFIX}/create" create_uri: str = f"{PREFIX}/create"
store_uri: str = f"{PREFIX}/store" store_uri: str = f"{PREFIX}/store"
detail_uri: str = f"{PREFIX}/{zzc.code}" detail_uri: str = f"{PREFIX}/{zzc.code}"
@ -355,7 +352,6 @@ class CurrencyTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting.models import Currency from accounting.models import Currency
from test_site import db
detail_uri: str = f"{PREFIX}/{zza.code}" detail_uri: str = f"{PREFIX}/{zza.code}"
edit_uri: str = f"{PREFIX}/{zza.code}/edit" edit_uri: str = f"{PREFIX}/{zza.code}/edit"
update_uri: str = f"{PREFIX}/{zza.code}/update" update_uri: str = f"{PREFIX}/{zza.code}/update"
@ -435,7 +431,6 @@ class CurrencyTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting.models import Currency from accounting.models import Currency
from test_site import db
detail_uri: str = f"{PREFIX}/{zza.code}" detail_uri: str = f"{PREFIX}/{zza.code}"
update_uri: str = f"{PREFIX}/{zza.code}/update" update_uri: str = f"{PREFIX}/{zza.code}/update"
zza_currency: Currency zza_currency: Currency
@ -475,7 +470,6 @@ class CurrencyTestCase(unittest.TestCase):
:return: None. :return: None.
""" """
from accounting.models import Currency from accounting.models import Currency
from test_site import db
editor_username, editor2_username = "editor", "editor2" editor_username, editor2_username = "editor", "editor2"
client, csrf_token = get_client(self.app, editor2_username) client, csrf_token = get_client(self.app, editor2_username)
detail_uri: str = f"{PREFIX}/{zza.code}" detail_uri: str = f"{PREFIX}/{zza.code}"
@ -526,7 +520,6 @@ class CurrencyTestCase(unittest.TestCase):
:return: None :return: None
""" """
from accounting.models import Currency from accounting.models import Currency
from test_site import db
detail_uri: str = f"{PREFIX}/{zza.code}" detail_uri: str = f"{PREFIX}/{zza.code}"
update_uri: str = f"{PREFIX}/{zza.code}/update" update_uri: str = f"{PREFIX}/{zza.code}/update"
response: httpx.Response response: httpx.Response