2023-04-09 08:56:06 +08:00
|
|
|
# The Mia! Accounting Project.
|
|
|
|
# Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/9
|
|
|
|
|
|
|
|
# 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 reports.
|
|
|
|
|
|
|
|
"""
|
2023-04-26 13:17:31 +08:00
|
|
|
import datetime as dt
|
2023-04-09 08:56:06 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import httpx
|
|
|
|
from flask import Flask
|
|
|
|
|
2023-04-13 08:30:07 +08:00
|
|
|
from test_site.lib import BaseTestData
|
2023-06-10 09:35:51 +08:00
|
|
|
from testlib import create_test_app, get_client, get_csrf_token, Accounts
|
2023-04-09 08:56:06 +08:00
|
|
|
|
|
|
|
PREFIX: str = "/accounting"
|
|
|
|
"""The URL prefix for the reports."""
|
2023-04-09 12:09:52 +08:00
|
|
|
CSV_MIME: str = "text/csv; charset=utf-8"
|
|
|
|
"""The MIME type of the downloaded CSV files."""
|
2023-04-09 08:56:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ReportTestCase(unittest.TestCase):
|
|
|
|
"""The report test case."""
|
|
|
|
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""Sets up the test.
|
|
|
|
This is run once per test.
|
|
|
|
|
|
|
|
: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-04-09 08:56:06 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
with self.__app.app_context():
|
2023-04-10 23:14:04 +08:00
|
|
|
from accounting.models import JournalEntry, JournalEntryLineItem
|
2023-04-09 08:56:06 +08:00
|
|
|
JournalEntry.query.delete()
|
|
|
|
JournalEntryLineItem.query.delete()
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
self.__client: httpx.Client = get_client(self.__app, "editor")
|
2023-06-10 09:35:51 +08:00
|
|
|
"""The user client."""
|
2023-06-10 10:23:33 +08:00
|
|
|
self.__csrf_token: str = get_csrf_token(self.__client)
|
2023-06-10 09:35:51 +08:00
|
|
|
"""The CSRF token."""
|
2023-04-09 08:56:06 +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")
|
|
|
|
ReportTestData(self.__app, "editor").populate()
|
2023-04-09 08:56:06 +08:00
|
|
|
response: httpx.Response
|
|
|
|
|
|
|
|
response = client.get(PREFIX)
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
response = client.get(f"{PREFIX}/journal")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/journal?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/ledger")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/ledger?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-expenses")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-expenses?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/trial-balance")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/trial-balance?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-statement")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-statement?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/balance-sheet")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/balance-sheet?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
response = client.get(f"{PREFIX}/unapplied")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/unapplied?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-18 01:12:04 +08:00
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-18 01:12:04 +08:00
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(f"{PREFIX}/unmatched")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(f"{PREFIX}/unmatched?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 10:57:30 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=Salary")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 10:57:30 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=Salary&as=csv")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 12:07:31 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=薪水")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
def test_viewer(self) -> None:
|
|
|
|
"""Test the permission as viewer.
|
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
client: httpx.Client = get_client(self.__app, "viewer")
|
|
|
|
ReportTestData(self.__app, "editor").populate()
|
2023-04-09 08:56:06 +08:00
|
|
|
response: httpx.Response
|
|
|
|
|
|
|
|
response = client.get(PREFIX)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
response = client.get(f"{PREFIX}/journal")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/journal?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/ledger")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/ledger?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-expenses")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-expenses?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/trial-balance")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/trial-balance?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-statement")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/income-statement?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 09:14:03 +08:00
|
|
|
response = client.get(f"{PREFIX}/balance-sheet")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/balance-sheet?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
response = client.get(f"{PREFIX}/unapplied")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 09:23:55 +08:00
|
|
|
response = client.get(f"{PREFIX}/unapplied?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-18 01:12:04 +08:00
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-18 01:12:04 +08:00
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-04-18 01:12:04 +08:00
|
|
|
response = client.get(f"{PREFIX}/unmatched")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(f"{PREFIX}/unmatched?as=csv")
|
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
|
|
|
response = client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
|
2023-04-09 10:57:30 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=Salary")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-04-09 10:57:30 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=Salary&as=csv")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:28:11 +08:00
|
|
|
|
2023-04-09 12:07:31 +08:00
|
|
|
response = client.get(f"{PREFIX}/search?q=薪水")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
|
|
|
response = client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 12:07:31 +08:00
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
def test_editor(self) -> None:
|
|
|
|
"""Test the permission as editor.
|
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
2023-06-10 10:23:33 +08:00
|
|
|
ReportTestData(self.__app, "editor").populate()
|
2023-04-09 08:56:06 +08:00
|
|
|
response: httpx.Response
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(PREFIX)
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/journal")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/journal?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/ledger")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/ledger?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-expenses")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-expenses?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/trial-balance")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/trial-balance?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-statement")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-statement?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/balance-sheet")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/balance-sheet?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unapplied")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unapplied?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unmatched")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unmatched?as=csv")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 08:56:06 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=Salary")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=Salary&as=csv")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:28:11 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=薪水")
|
2023-04-09 12:07:31 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=薪水&as=csv")
|
2023-04-09 12:07:31 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 12:07:31 +08:00
|
|
|
|
2023-04-09 08:56:06 +08:00
|
|
|
def test_empty_db(self) -> None:
|
|
|
|
"""Tests the empty database.
|
|
|
|
|
|
|
|
:return: None.
|
|
|
|
"""
|
|
|
|
response: httpx.Response
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(PREFIX)
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/journal")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/journal?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/ledger")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/ledger?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-expenses")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-expenses?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/trial-balance")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/trial-balance?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-statement")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/income-statement?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/balance-sheet")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/balance-sheet?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unapplied")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unapplied?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unapplied/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unmatched")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/unmatched?as=csv")
|
2023-04-18 01:12:04 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}")
|
2023-04-09 08:56:06 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 09:23:55 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(
|
2023-04-18 09:21:42 +08:00
|
|
|
f"{PREFIX}/unmatched/USD/{Accounts.PAYABLE}?as=csv")
|
2023-04-09 09:23:55 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 09:28:11 +08:00
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=Salary")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2023-06-10 10:23:33 +08:00
|
|
|
response = self.__client.get(f"{PREFIX}/search?q=Salary&as=csv")
|
2023-04-09 09:28:11 +08:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2023-04-09 12:09:52 +08:00
|
|
|
self.assertEqual(response.headers["Content-Type"], CSV_MIME)
|
2023-04-09 10:57:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ReportTestData(BaseTestData):
|
|
|
|
"""The report test data."""
|
|
|
|
|
|
|
|
def _init_data(self) -> None:
|
2023-04-26 13:17:31 +08:00
|
|
|
today: dt.date = dt.date.today()
|
2023-04-09 10:57:30 +08:00
|
|
|
year: int = today.year - 5
|
|
|
|
month: int = today.month
|
|
|
|
while True:
|
2023-04-26 13:22:46 +08:00
|
|
|
date: dt.date = dt.date(year, month, 5)
|
|
|
|
if date > today:
|
2023-04-09 10:57:30 +08:00
|
|
|
break
|
|
|
|
self._add_simple_journal_entry(
|
2023-04-26 13:22:46 +08:00
|
|
|
(date - today).days, "USD",
|
2023-04-09 11:55:15 +08:00
|
|
|
"Salary薪水", "1200", Accounts.BANK, Accounts.SERVICE)
|
2023-04-09 10:57:30 +08:00
|
|
|
month = month + 1
|
|
|
|
if month > 12:
|
|
|
|
year = year + 1
|
|
|
|
month = 1
|
|
|
|
self._add_simple_journal_entry(
|
2023-04-09 11:55:15 +08:00
|
|
|
1, "USD", "Withdraw領錢", "1000", Accounts.CASH, Accounts.BANK)
|
2023-04-09 10:57:30 +08:00
|
|
|
self._add_simple_journal_entry(
|
2023-04-09 11:55:15 +08:00
|
|
|
0, "USD", "Dinner晚餐", "40", Accounts.MEAL, Accounts.CASH)
|