Compare commits

..

2 Commits

3 changed files with 75 additions and 71 deletions

View File

@ -62,7 +62,7 @@ stock: AccountData = AccountData("1121", 1, "Stock")
loan: AccountData = AccountData("2112", 1, "Loan") loan: AccountData = AccountData("2112", 1, "Loan")
"""The loan account.""" """The loan account."""
PREFIX: str = "/accounting/accounts" PREFIX: str = "/accounting/accounts"
"""The URL prefix of the currency management.""" """The URL prefix for the account management."""
class AccountCommandTestCase(unittest.TestCase): class AccountCommandTestCase(unittest.TestCase):
@ -409,9 +409,9 @@ class AccountTestCase(unittest.TestCase):
f"{stock.base_code}-002", f"{stock.base_code}-002",
f"{stock.base_code}-003"}) f"{stock.base_code}-003"})
stock_account: Account = Account.find_by_code(stock.code) account: Account = Account.find_by_code(stock.code)
self.assertEqual(stock_account.base_code, stock.base_code) self.assertEqual(account.base_code, stock.base_code)
self.assertEqual(stock_account.title_l10n, stock.title) self.assertEqual(account.title_l10n, stock.title)
def test_basic_update(self) -> None: def test_basic_update(self) -> None:
"""Tests the basic rules to update a user. """Tests the basic rules to update a user.
@ -434,9 +434,9 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account: Account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.base_code, cash.base_code) self.assertEqual(account.base_code, cash.base_code)
self.assertEqual(cash_account.title_l10n, f"{cash.title}-1") self.assertEqual(account.title_l10n, f"{cash.title}-1")
# Empty base account code # Empty base account code
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -492,7 +492,7 @@ class AccountTestCase(unittest.TestCase):
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"
cash_account: Account account: Account
response: httpx.Response response: httpx.Response
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -503,11 +503,11 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertIsNotNone(cash_account) self.assertIsNotNone(account)
cash_account.created_at \ account.created_at \
= cash_account.created_at - timedelta(seconds=5) = account.created_at - timedelta(seconds=5)
cash_account.updated_at = cash_account.created_at account.updated_at = account.created_at
db.session.commit() db.session.commit()
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -518,10 +518,10 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertIsNotNone(cash_account) self.assertIsNotNone(account)
self.assertLess(cash_account.created_at, self.assertLess(account.created_at,
cash_account.updated_at) account.updated_at)
def test_created_updated_by(self) -> None: def test_created_updated_by(self) -> None:
"""Tests the created-by and updated-by record. """Tests the created-by and updated-by record.
@ -533,12 +533,13 @@ class AccountTestCase(unittest.TestCase):
client, csrf_token = get_client(self.app, editor2_username) client, csrf_token = get_client(self.app, editor2_username)
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"
account: Account
response: httpx.Response response: httpx.Response
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.created_by.username, editor_username) self.assertEqual(account.created_by.username, editor_username)
self.assertEqual(cash_account.updated_by.username, editor_username) self.assertEqual(account.updated_by.username, editor_username)
response = client.post(update_uri, response = client.post(update_uri,
data={"csrf_token": csrf_token, data={"csrf_token": csrf_token,
@ -548,10 +549,10 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.created_by.username, self.assertEqual(account.created_by.username,
editor_username) editor_username)
self.assertEqual(cash_account.updated_by.username, self.assertEqual(account.updated_by.username,
editor2_username) editor2_username)
def test_l10n(self) -> None: def test_l10n(self) -> None:
@ -562,12 +563,13 @@ class AccountTestCase(unittest.TestCase):
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"
account: Account
response: httpx.Response response: httpx.Response
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.title_l10n, cash.title) self.assertEqual(account.title_l10n, cash.title)
self.assertEqual(cash_account.l10n, []) self.assertEqual(account.l10n, [])
set_locale(self.client, self.csrf_token, "zh_Hant") set_locale(self.client, self.csrf_token, "zh_Hant")
@ -579,9 +581,9 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.title_l10n, cash.title) self.assertEqual(account.title_l10n, cash.title)
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n}, self.assertEqual({(x.locale, x.title) for x in account.l10n},
{("zh_Hant", f"{cash.title}-zh_Hant")}) {("zh_Hant", f"{cash.title}-zh_Hant")})
set_locale(self.client, self.csrf_token, "en") set_locale(self.client, self.csrf_token, "en")
@ -594,9 +596,9 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.title_l10n, f"{cash.title}-2") self.assertEqual(account.title_l10n, f"{cash.title}-2")
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n}, self.assertEqual({(x.locale, x.title) for x in account.l10n},
{("zh_Hant", f"{cash.title}-zh_Hant")}) {("zh_Hant", f"{cash.title}-zh_Hant")})
set_locale(self.client, self.csrf_token, "zh_Hant") set_locale(self.client, self.csrf_token, "zh_Hant")
@ -609,9 +611,9 @@ class AccountTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
cash_account: Account = Account.find_by_code(cash.code) account = Account.find_by_code(cash.code)
self.assertEqual(cash_account.title_l10n, f"{cash.title}-2") self.assertEqual(account.title_l10n, f"{cash.title}-2")
self.assertEqual({(x.locale, x.title) for x in cash_account.l10n}, self.assertEqual({(x.locale, x.title) for x in account.l10n},
{("zh_Hant", f"{cash.title}-zh_Hant-2")}) {("zh_Hant", f"{cash.title}-zh_Hant-2")})
def test_delete(self) -> None: def test_delete(self) -> None:

View File

@ -55,7 +55,7 @@ zzc: CurrencyData = CurrencyData("ZZC", "Testing Dollar #C")
zzd: CurrencyData = CurrencyData("ZZD", "Testing Dollar #D") zzd: CurrencyData = CurrencyData("ZZD", "Testing Dollar #D")
"""The fourth test currency.""" """The fourth test currency."""
PREFIX: str = "/accounting/currencies" PREFIX: str = "/accounting/currencies"
"""The URL prefix of the currency management.""" """The URL prefix for the currency management."""
class CurrencyCommandTestCase(unittest.TestCase): class CurrencyCommandTestCase(unittest.TestCase):
@ -342,9 +342,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual({x.code for x in Currency.query.all()}, self.assertEqual({x.code for x in Currency.query.all()},
{zza.code, zzb.code, zzc.code}) {zza.code, zzb.code, zzc.code})
zzc_currency: Currency = db.session.get(Currency, zzc.code) currency: Currency = db.session.get(Currency, zzc.code)
self.assertEqual(zzc_currency.code, zzc.code) self.assertEqual(currency.code, zzc.code)
self.assertEqual(zzc_currency.name_l10n, zzc.name) self.assertEqual(currency.name_l10n, zzc.name)
def test_basic_update(self) -> None: def test_basic_update(self) -> None:
"""Tests the basic rules to update a user. """Tests the basic rules to update a user.
@ -367,9 +367,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency: Currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.code, zza.code) self.assertEqual(currency.code, zza.code)
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-1") self.assertEqual(currency.name_l10n, f"{zza.name}-1")
# Empty code # Empty code
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -433,7 +433,7 @@ class CurrencyTestCase(unittest.TestCase):
from accounting.models import Currency from accounting.models import Currency
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 currency: Currency | None
response: httpx.Response response: httpx.Response
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -444,11 +444,11 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertIsNotNone(zza_currency) self.assertIsNotNone(currency)
zza_currency.created_at \ currency.created_at \
= zza_currency.created_at - timedelta(seconds=5) = currency.created_at - timedelta(seconds=5)
zza_currency.updated_at = zza_currency.created_at currency.updated_at = currency.created_at
db.session.commit() db.session.commit()
response = self.client.post(update_uri, response = self.client.post(update_uri,
@ -459,10 +459,10 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertIsNotNone(zza_currency) self.assertIsNotNone(currency)
self.assertLess(zza_currency.created_at, self.assertLess(currency.created_at,
zza_currency.updated_at) currency.updated_at)
def test_created_updated_by(self) -> None: def test_created_updated_by(self) -> None:
"""Tests the created-by and updated-by record. """Tests the created-by and updated-by record.
@ -474,12 +474,13 @@ class CurrencyTestCase(unittest.TestCase):
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}"
update_uri: str = f"{PREFIX}/{zza.code}/update" update_uri: str = f"{PREFIX}/{zza.code}/update"
currency: Currency
response: httpx.Response response: httpx.Response
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.created_by.username, editor_username) self.assertEqual(currency.created_by.username, editor_username)
self.assertEqual(zza_currency.updated_by.username, editor_username) self.assertEqual(currency.updated_by.username, editor_username)
response = client.post(update_uri, response = client.post(update_uri,
data={"csrf_token": csrf_token, data={"csrf_token": csrf_token,
@ -489,9 +490,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.created_by.username, editor_username) self.assertEqual(currency.created_by.username, editor_username)
self.assertEqual(zza_currency.updated_by.username, editor2_username) self.assertEqual(currency.updated_by.username, editor2_username)
def test_api_exists(self) -> None: def test_api_exists(self) -> None:
"""Tests the API to check if a code exists. """Tests the API to check if a code exists.
@ -522,12 +523,13 @@ class CurrencyTestCase(unittest.TestCase):
from accounting.models import Currency from accounting.models import Currency
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"
currency: Currency
response: httpx.Response response: httpx.Response
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.name_l10n, zza.name) self.assertEqual(currency.name_l10n, zza.name)
self.assertEqual(zza_currency.l10n, []) self.assertEqual(currency.l10n, [])
set_locale(self.client, self.csrf_token, "zh_Hant") set_locale(self.client, self.csrf_token, "zh_Hant")
@ -539,9 +541,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.name_l10n, zza.name) self.assertEqual(currency.name_l10n, zza.name)
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n}, self.assertEqual({(x.locale, x.name) for x in currency.l10n},
{("zh_Hant", f"{zza.name}-zh_Hant")}) {("zh_Hant", f"{zza.name}-zh_Hant")})
set_locale(self.client, self.csrf_token, "en") set_locale(self.client, self.csrf_token, "en")
@ -554,9 +556,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-2") self.assertEqual(currency.name_l10n, f"{zza.name}-2")
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n}, self.assertEqual({(x.locale, x.name) for x in currency.l10n},
{("zh_Hant", f"{zza.name}-zh_Hant")}) {("zh_Hant", f"{zza.name}-zh_Hant")})
set_locale(self.client, self.csrf_token, "zh_Hant") set_locale(self.client, self.csrf_token, "zh_Hant")
@ -569,9 +571,9 @@ class CurrencyTestCase(unittest.TestCase):
self.assertEqual(response.headers["Location"], detail_uri) self.assertEqual(response.headers["Location"], detail_uri)
with self.app.app_context(): with self.app.app_context():
zza_currency: Currency = db.session.get(Currency, zza.code) currency = db.session.get(Currency, zza.code)
self.assertEqual(zza_currency.name_l10n, f"{zza.name}-2") self.assertEqual(currency.name_l10n, f"{zza.name}-2")
self.assertEqual({(x.locale, x.name) for x in zza_currency.l10n}, self.assertEqual({(x.locale, x.name) for x in currency.l10n},
{("zh_Hant", f"{zza.name}-zh_Hant-2")}) {("zh_Hant", f"{zza.name}-zh_Hant-2")})
def test_delete(self) -> None: def test_delete(self) -> None:

View File

@ -34,7 +34,7 @@ from testlib_txn import Accounts, get_add_form, get_unchanged_update_form, \
NON_EMPTY_NOTE, EMPTY_NOTE, add_txn NON_EMPTY_NOTE, EMPTY_NOTE, add_txn
PREFIX: str = "/accounting/transactions" PREFIX: str = "/accounting/transactions"
"""The URL prefix of the transaction management.""" """The URL prefix for the transaction management."""
class CashIncomeTransactionTestCase(unittest.TestCase): class CashIncomeTransactionTestCase(unittest.TestCase):