2023-04-04 18:17:44 +08:00
|
|
|
# The Mia! Accounting Project.
|
2023-01-29 22:28:27 +08:00
|
|
|
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/26
|
|
|
|
|
|
|
|
# Copyright (c) 2023 imacat.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
"""The test for the base account management.
|
|
|
|
|
|
|
|
"""
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
from flask import Flask
|
|
|
|
|
2023-03-14 21:28:35 +08:00
|
|
|
from testlib import create_test_app, get_client
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
LIST_URI: str = "/accounting/base-accounts"
|
|
|
|
"""The list URI."""
|
|
|
|
DETAIL_URI: str = "/accounting/base-accounts/1111"
|
|
|
|
"""The detail URI."""
|
|
|
|
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-02 00:13:22 +08:00
|
|
|
class BaseAccountTestCase(unittest.TestCase):
|
|
|
|
"""The base account test case."""
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-02 00:13:22 +08:00
|
|
|
def setUp(self) -> None:
|
|
|
|
"""Sets up the test.
|
|
|
|
This is run once per test.
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-02 00:13:22 +08:00
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
self.__app: Flask = create_test_app()
|
2023-06-09 07:28:47 +08:00
|
|
|
"""The Flask application."""
|
2023-02-02 00:13:22 +08:00
|
|
|
|
|
|
|
def test_nobody(self) -> None:
|
|
|
|
"""Test the permission as nobody.
|
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
client: httpx.Client = get_client(self.__app, "nobody")
|
2023-02-02 00:13:22 +08:00
|
|
|
response: httpx.Response
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(LIST_URI)
|
2023-01-29 22:28:27 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(DETAIL_URI)
|
2023-02-02 00:13:22 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
def test_viewer(self) -> None:
|
|
|
|
"""Test the permission as viewer.
|
2023-01-29 22:28:27 +08:00
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
client: httpx.Client = get_client(self.__app, "viewer")
|
2023-02-02 00:13:22 +08:00
|
|
|
response: httpx.Response
|
2023-01-29 22:28:27 +08:00
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(LIST_URI)
|
2023-02-02 00:13:22 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(DETAIL_URI)
|
2023-02-02 00:13:22 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
def test_editor(self) -> None:
|
|
|
|
"""Test the permission as editor.
|
2023-01-29 22:28:27 +08:00
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
client: httpx.Client = get_client(self.__app, "editor")
|
2023-02-02 00:13:22 +08:00
|
|
|
response: httpx.Response
|
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(LIST_URI)
|
2023-02-02 00:13:22 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-02-27 16:36:51 +08:00
|
|
|
response = client.get(DETAIL_URI)
|
2023-02-02 00:13:22 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|