From 6a83f95c9f0726ce7d3e675b74479637df344754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 3 Feb 2023 09:45:17 +0800 Subject: [PATCH] Added the test_change_base test to the AccountTestCase test case. --- tests/test_account.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/test_account.py b/tests/test_account.py index 0067118..6d8c663 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -242,3 +242,63 @@ class AccountTestCase(unittest.TestCase): self.assertEqual(response.status_code, 302) self.assertEqual(response.headers["Location"], "/accounting/accounts") + + def test_change_base(self) -> None: + """Tests to change the base account. + + :return: None. + """ + from accounting.database import db + from accounting.models import Account + response: httpx.Response + + response = self.client.post("/accounting/accounts/store", + data={"csrf_token": self.csrf_token, + "base_code": "1111", + "title": "Title #1"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.headers["Location"], + "/accounting/accounts/1111-002") + + response = self.client.post("/accounting/accounts/store", + data={"csrf_token": self.csrf_token, + "base_code": "1111", + "title": "Title #1"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.headers["Location"], + "/accounting/accounts/1111-003") + + response = self.client.post("/accounting/accounts/store", + data={"csrf_token": self.csrf_token, + "base_code": "1112", + "title": "Title #1"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.headers["Location"], + "/accounting/accounts/1112-002") + + with self.app.app_context(): + account_1_id: int = Account.find_by_code("1111-001").id + account_2_id: int = Account.find_by_code("1111-002").id + account_3_id: int = Account.find_by_code("1111-003").id + account_4_id: int = Account.find_by_code("1112-001").id + account_5_id: int = Account.find_by_code("1112-002").id + + response = self.client.post("/accounting/accounts/1111-002/update", + data={"csrf_token": self.csrf_token, + "base_code": "1112", + "title": "Account #1"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.headers["Location"], + "/accounting/accounts/1112-003") + + with self.app.app_context(): + self.assertEqual(db.session.get(Account, account_1_id).code, + "1111-001") + self.assertEqual(db.session.get(Account, account_2_id).code, + "1112-003") + self.assertEqual(db.session.get(Account, account_3_id).code, + "1111-002") + self.assertEqual(db.session.get(Account, account_4_id).code, + "1112-001") + self.assertEqual(db.session.get(Account, account_5_id).code, + "1112-002")