From 3255a7e658ac2e355ca3acc18474ea8292b3e880 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 26 Jan 2021 16:22:59 -0800 Subject: [PATCH] backups: schedule: tests: Fix failures due to long test run Closes: #2023. When importing the test module, datetime.now() is executed and value is kept. If a test suite runs for a long time, the time deltas are being calculated much later when the test case runs. This creates an difference in expected different between the two values. Fix this by completely removing all uses of time relative to current date time. Only use absolute date time values. This should not reduce the effectiveness of the test cases. Tests performed: - Rerun unit tests for backups module. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/tests/test_schedule.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plinth/modules/backups/tests/test_schedule.py b/plinth/modules/backups/tests/test_schedule.py index be553f0a5..9fb87b476 100644 --- a/plinth/modules/backups/tests/test_schedule.py +++ b/plinth/modules/backups/tests/test_schedule.py @@ -83,9 +83,7 @@ def _get_archives_from_test_data(data): archives = [] for index, item in enumerate(data): archive_time = item['time'] - if isinstance(archive_time, timedelta): - archive_time = datetime.now() + archive_time - elif isinstance(archive_time, str): + if isinstance(archive_time, str): archive_time = datetime.strptime(archive_time, '%Y-%m-%d %H:%M:%S+0000') archive = { @@ -114,7 +112,7 @@ cases = [ [ [False, 10, 10, 10, 0], [], - datetime.now(), + datetime(2021, 1, 1), [], [], ], @@ -122,7 +120,7 @@ cases = [ [ [True, 10, 10, 10, 0], [], - datetime.now(), + datetime(2021, 1, 1), ['daily', 'weekly', 'monthly'], [], ], @@ -131,9 +129,9 @@ cases = [ [True, 10, 10, 10, 0], [{ 'periods': ['daily'], - 'time': timedelta(seconds=-600) + 'time': datetime(2021, 1, 1) - timedelta(seconds=600) }], - datetime.now(), + datetime(2021, 1, 1), [], [], ], @@ -142,9 +140,9 @@ cases = [ [True, 10, 10, 10, 0], [{ 'periods': ['weekly'], - 'time': timedelta(seconds=-600) + 'time': datetime(2021, 1, 1) - timedelta(seconds=600) }], - datetime.now(), + datetime(2021, 1, 1), [], [], ], @@ -153,9 +151,9 @@ cases = [ [True, 10, 10, 10, 0], [{ 'periods': ['monthly'], - 'time': timedelta(seconds=-600) + 'time': datetime(2021, 1, 1) - timedelta(seconds=600) }], - datetime.now(), + datetime(2021, 1, 1), [], [], ],