From f878ba55353db4099b6e3701a9b9ef2d9c26bd9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sat, 25 Feb 2023 17:58:55 +0800 Subject: [PATCH] Revised to rewind the time in the test_update_not_modified tests of the AccountTestCase and CurrencyTestCase test cases, so that the test cases don't have to wait for the time to be different. --- tests/test_account.py | 9 ++++++--- tests/test_currency.py | 8 +++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/test_account.py b/tests/test_account.py index 789f6f2..8f4f095 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -17,8 +17,8 @@ """The test for the account management. """ -import time import unittest +from datetime import timedelta import httpx import sqlalchemy as sa @@ -489,12 +489,12 @@ class AccountTestCase(unittest.TestCase): :return: None. """ + from accounting import db from accounting.models import Account detail_uri: str = f"{PREFIX}/{cash.code}" update_uri: str = f"{PREFIX}/{cash.code}/update" cash_account: Account response: httpx.Response - time.sleep(1) response = self.client.post(update_uri, data={"csrf_token": self.csrf_token, @@ -506,7 +506,10 @@ class AccountTestCase(unittest.TestCase): with self.app.app_context(): cash_account = Account.find_by_code(cash.code) self.assertIsNotNone(cash_account) - self.assertEqual(cash_account.created_at, cash_account.updated_at) + cash_account.created_at \ + = cash_account.created_at - timedelta(seconds=5) + cash_account.updated_at = cash_account.created_at + db.session.commit() response = self.client.post(update_uri, data={"csrf_token": self.csrf_token, diff --git a/tests/test_currency.py b/tests/test_currency.py index 6708540..30009c1 100644 --- a/tests/test_currency.py +++ b/tests/test_currency.py @@ -18,9 +18,9 @@ """ import csv -import time import typing as t import unittest +from datetime import timedelta import httpx from click.testing import Result @@ -440,7 +440,6 @@ class CurrencyTestCase(unittest.TestCase): update_uri: str = f"{PREFIX}/{zza.code}/update" zza_currency: Currency response: httpx.Response - time.sleep(1) response = self.client.post(update_uri, data={"csrf_token": self.csrf_token, @@ -452,7 +451,10 @@ class CurrencyTestCase(unittest.TestCase): with self.app.app_context(): zza_currency = db.session.get(Currency, zza.code) self.assertIsNotNone(zza_currency) - self.assertEqual(zza_currency.created_at, zza_currency.updated_at) + zza_currency.created_at \ + = zza_currency.created_at - timedelta(seconds=5) + zza_currency.updated_at = zza_currency.created_at + db.session.commit() response = self.client.post(update_uri, data={"csrf_token": self.csrf_token,