Added the order and sorting routes to the test_nobody, test_viewer, and test_editor tests of the AccountTestCase test case.

This commit is contained in:
依瑪貓 2023-02-03 12:41:01 +08:00
parent b5d87d2387
commit cea2a44226

View File

@ -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.