Simplified the logic in the add_txn function in testlib_txn.py.

This commit is contained in:
依瑪貓 2023-03-01 00:27:39 +08:00
parent f049b5d7ee
commit 1402a12f04

View File

@ -393,10 +393,11 @@ def add_txn(client: httpx.Client, form: dict[str, str]) -> int:
:return: The newly-added transaction ID. :return: The newly-added transaction ID.
""" """
prefix: str = "/accounting/transactions" prefix: str = "/accounting/transactions"
txn_type: str \ txn_type: str = "transfer"
= "income" if len({x for x in form if "-debit-" in x}) == 0 else\ if len({x for x in form if "-debit-" in x}) == 0:
("expense" if len({x for x in form if "-credit-" in x}) == 0 else txn_type = "income"
"transfer") elif len({x for x in form if "-credit-" in x}) == 0:
txn_type = "expense"
store_uri = f"{prefix}/store/{txn_type}" store_uri = f"{prefix}/store/{txn_type}"
response: httpx.Response = client.post(store_uri, data=form) response: httpx.Response = client.post(store_uri, data=form)
assert response.status_code == 302 assert response.status_code == 302