From cea2a44226f01c11ed35d0432b8334bbb6c5f572 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 12:41:01 +0800 Subject: [PATCH] Added the order and sorting routes to the test_nobody, test_viewer, and test_editor tests of the AccountTestCase test case. --- tests/test_account.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/test_account.py b/tests/test_account.py index 3382e7f..513eea9 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -135,6 +135,7 @@ class AccountTestCase(unittest.TestCase): :return: None. """ + from accounting.models import Account response: httpx.Response nobody: UserClient = get_user_client(self, self.app, "nobody") @@ -166,11 +167,24 @@ class AccountTestCase(unittest.TestCase): data={"csrf_token": nobody.csrf_token}) self.assertEqual(response.status_code, 403) + response = nobody.client.get("/accounting/accounts/bases/1111") + self.assertEqual(response.status_code, 403) + + with self.app.app_context(): + account_id: int = Account.find_by_code("1112-001").id + + response = nobody.client.post("/accounting/accounts/bases/1112", + data={"csrf_token": nobody.csrf_token, + "next": "/next", + f"{account_id}-no": "5"}) + self.assertEqual(response.status_code, 403) + def test_viewer(self) -> None: """Test the permission as viewer. :return: None. """ + from accounting.models import Account response: httpx.Response viewer: UserClient = get_user_client(self, self.app, "viewer") @@ -202,11 +216,24 @@ class AccountTestCase(unittest.TestCase): data={"csrf_token": viewer.csrf_token}) self.assertEqual(response.status_code, 403) + response = viewer.client.get("/accounting/accounts/bases/1111") + self.assertEqual(response.status_code, 200) + + with self.app.app_context(): + account_id: int = Account.find_by_code("1112-001").id + + response = viewer.client.post("/accounting/accounts/bases/1112", + data={"csrf_token": viewer.csrf_token, + "next": "/next", + f"{account_id}-no": "5"}) + self.assertEqual(response.status_code, 403) + def test_editor(self) -> None: """Test the permission as editor. :return: None. """ + from accounting.models import Account response: httpx.Response response = self.client.get("/accounting/accounts") @@ -243,6 +270,19 @@ class AccountTestCase(unittest.TestCase): self.assertEqual(response.headers["Location"], "/accounting/accounts") + response = self.client.get("/accounting/accounts/bases/1111") + self.assertEqual(response.status_code, 200) + + with self.app.app_context(): + account_id: int = Account.find_by_code("1112-001").id + + response = self.client.post("/accounting/accounts/bases/1112", + data={"csrf_token": self.csrf_token, + "next": "/next", + f"{account_id}-no": "5"}) + self.assertEqual(response.status_code, 302) + self.assertEqual(response.headers["Location"], "/next") + def test_change_base(self) -> None: """Tests to change the base account.