diff --git a/tests/test_account.py b/tests/test_account.py index 14174cf..478451d 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -105,6 +105,15 @@ class AccountTestCase(unittest.TestCase): self.assertEqual(response.headers["Location"], f"{PREFIX}/{BANK.code}") + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_base_account.py b/tests/test_base_account.py index e31c7e6..9a27dec 100644 --- a/tests/test_base_account.py +++ b/tests/test_base_account.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/1/26 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import unittest import httpx from flask import Flask +from test_site import db from testlib import create_test_app, get_client LIST_URI: str = "/accounting/base-accounts" @@ -42,6 +43,15 @@ class BaseAccountTestCase(unittest.TestCase): self.__app: Flask = create_test_app() """The Flask application.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_commands.py b/tests/test_commands.py index 811ec09..0ea8601 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/10 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -45,6 +45,15 @@ class ConsoleCommandTestCase(unittest.TestCase): self.__app: Flask = create_test_app() """The Flask application.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_init_db(self) -> None: """Tests the "accounting-init-db" console command. diff --git a/tests/test_currency.py b/tests/test_currency.py index 5109a97..ea5d771 100644 --- a/tests/test_currency.py +++ b/tests/test_currency.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/1 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -94,6 +94,15 @@ class CurrencyTestCase(unittest.TestCase): self.assertEqual(response.status_code, 302) self.assertEqual(response.headers["Location"], f"{PREFIX}/{EUR.code}") + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_description_editor.py b/tests/test_description_editor.py index 890f284..d91428a 100644 --- a/tests/test_description_editor.py +++ b/tests/test_description_editor.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/28 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import httpx from flask import Flask from accounting.utils.next_uri import encode_next +from test_site import db from testlib import NEXT_URI, Accounts, create_test_app, get_client, \ get_csrf_token, add_journal_entry @@ -52,6 +53,15 @@ class DescriptionEditorTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_description_editor(self) -> None: """Test the description editor. diff --git a/tests/test_journal_entry.py b/tests/test_journal_entry.py index 2d99499..ae4af0a 100644 --- a/tests/test_journal_entry.py +++ b/tests/test_journal_entry.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/24 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -63,6 +63,15 @@ class CashReceiptJournalEntryTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. @@ -688,6 +697,15 @@ class CashDisbursementJournalEntryTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. @@ -1289,6 +1307,15 @@ class TransferJournalEntryTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. @@ -2169,6 +2196,15 @@ class JournalEntryReorderTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_change_date(self) -> None: """Tests to change the date of a journal entry. diff --git a/tests/test_offset.py b/tests/test_offset.py index 1d36471..e303041 100644 --- a/tests/test_offset.py +++ b/tests/test_offset.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/11 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -63,6 +63,15 @@ class OffsetTestCase(unittest.TestCase): """The offset test data.""" self.__data.populate() + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_add_receivable_offset(self) -> None: """Tests to add the receivable offset. diff --git a/tests/test_option.py b/tests/test_option.py index c3e6e94..58e3d6f 100644 --- a/tests/test_option.py +++ b/tests/test_option.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/22 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -55,6 +55,15 @@ class OptionTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_report.py b/tests/test_report.py index ebb9253..0dd1d73 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/9 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import unittest import httpx from flask import Flask +from test_site import db from test_site.lib import BaseTestData from testlib import create_test_app, get_client, get_csrf_token, Accounts @@ -54,6 +55,15 @@ class ReportTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_unmatched_offset.py b/tests/test_unmatched_offset.py index cc83b60..643ffc1 100644 --- a/tests/test_unmatched_offset.py +++ b/tests/test_unmatched_offset.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/4/8 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -57,6 +57,15 @@ class UnmatchedOffsetTestCase(unittest.TestCase): self.__csrf_token: str = get_csrf_token(self.__client) """The CSRF token.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_nobody(self) -> None: """Test the permission as nobody. diff --git a/tests/test_utils.py b/tests/test_utils.py index 4027e59..76b2715 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,7 @@ # The Mia! Accounting Project. # Author: imacat@mail.imacat.idv.tw (imacat), 2023/2/3 -# Copyright (c) 2023 imacat. +# Copyright (c) 2023-2026 imacat. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ from accounting.utils.next_uri import append_next, inherit_next, or_next, \ encode_next, decode_next from accounting.utils.pagination import Pagination, DEFAULT_PAGE_SIZE from accounting.utils.query import parse_query_keywords +from test_site import db from testlib import TEST_SERVER, create_test_app, get_csrf_token, NEXT_URI @@ -43,6 +44,15 @@ class NextUriTestCase(unittest.TestCase): self.__app: Flask = create_test_app() """The Flask application.""" + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def test_next_uri(self) -> None: """Tests the next URI utilities with the next URI. @@ -236,6 +246,15 @@ class PaginationTestCase(unittest.TestCase): """The user client.""" self.__client.headers["Referer"] = TEST_SERVER + def tearDown(self) -> None: + """Tears down the test. + This is run once per test. + + :return: None. + """ + with self.__app.app_context(): + db.engine.dispose() + def __test_success(self, query: str, items: range, result: range, is_paged: bool = True, is_reversed: bool | None = None) -> None: