backups: tests: scheduled tests failures while running functional tests
I noticed that these fail only when run with --include-functional
.
_____ test_run_schedule[schedule_params2-archives_data2-test_now2-run_periods2-cleanups2] _____
get_instance = <MagicMock name='get_instance' id='140312755378448'>
schedule_params = [True, 10, 10, 10, 0]
archives_data = [{'periods': ['daily'], 'time': datetime.timedelta(days=-1, seconds=85800)}]
test_now = datetime.datetime(2021, 1, 23, 8, 39, 23, 492299), run_periods = [], cleanups = []
@pytest.mark.parametrize(
'schedule_params,archives_data,test_now,run_periods,cleanups', cases)
@patch('plinth.modules.backups.repository.get_instance')
def test_run_schedule(get_instance, schedule_params, archives_data, test_now,
run_periods, cleanups):
"""Test that backups are run at expected time."""
setup_helper.get_state.return_value = 'up-to-date'
repository = MagicMock()
repository.list_archives.side_effect = \
lambda: _get_archives_from_test_data(archives_data)
get_instance.return_value = repository
with patch('plinth.modules.backups.schedule.datetime') as mock_datetime, \
patch('plinth.app.App.list') as app_list:
app_list.return_value = [
_get_test_app('test-app1'),
_get_test_app('test-app2'),
_get_test_app('test-app3')
]
mock_datetime.now.return_value = test_now
mock_datetime.strptime = datetime.strptime
mock_datetime.min = datetime.min
mock_datetime.side_effect = lambda *args, **kwargs: datetime(
*args, **kwargs)
schedule = Schedule('test_uuid', schedule_params[0],
schedule_params[1], schedule_params[2],
schedule_params[3], schedule_params[4],
['test-app2'])
schedule.run_schedule()
if not run_periods:
> repository.create_archive.assert_not_called()
plinth/modules/backups/tests/test_schedule.py:463:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='get_instance().create_archive' id='140312754986576'>
def assert_not_called(self):
"""assert that the mock was never called.
"""
if self.call_count != 0:
msg = ("Expected '%s' to not have been called. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'create_archive' to not have been called. Called 1 times.
E Calls: [call('scheduled: daily, monthly, weekly: 2021-01-23:08:39', ['test-app1', 'test-app3'], archive_comment='{{"type": "scheduled", "periods": ["daily", "monthly", "weekly"]}}')].
/usr/lib/python3.9/unittest/mock.py:868: AssertionError
_____ test_run_schedule[schedule_params3-archives_data3-test_now3-run_periods3-cleanups3] _____
get_instance = <MagicMock name='get_instance' id='140312755088976'>
schedule_params = [True, 10, 10, 10, 0]
archives_data = [{'periods': ['weekly'], 'time': datetime.timedelta(days=-1, seconds=85800)}]
test_now = datetime.datetime(2021, 1, 23, 8, 39, 23, 492300), run_periods = [], cleanups = []
@pytest.mark.parametrize(
'schedule_params,archives_data,test_now,run_periods,cleanups', cases)
@patch('plinth.modules.backups.repository.get_instance')
def test_run_schedule(get_instance, schedule_params, archives_data, test_now,
run_periods, cleanups):
"""Test that backups are run at expected time."""
setup_helper.get_state.return_value = 'up-to-date'
repository = MagicMock()
repository.list_archives.side_effect = \
lambda: _get_archives_from_test_data(archives_data)
get_instance.return_value = repository
with patch('plinth.modules.backups.schedule.datetime') as mock_datetime, \
patch('plinth.app.App.list') as app_list:
app_list.return_value = [
_get_test_app('test-app1'),
_get_test_app('test-app2'),
_get_test_app('test-app3')
]
mock_datetime.now.return_value = test_now
mock_datetime.strptime = datetime.strptime
mock_datetime.min = datetime.min
mock_datetime.side_effect = lambda *args, **kwargs: datetime(
*args, **kwargs)
schedule = Schedule('test_uuid', schedule_params[0],
schedule_params[1], schedule_params[2],
schedule_params[3], schedule_params[4],
['test-app2'])
schedule.run_schedule()
if not run_periods:
> repository.create_archive.assert_not_called()
plinth/modules/backups/tests/test_schedule.py:463:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='get_instance().create_archive' id='140312755318688'>
def assert_not_called(self):
"""assert that the mock was never called.
"""
if self.call_count != 0:
msg = ("Expected '%s' to not have been called. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'create_archive' to not have been called. Called 1 times.
E Calls: [call('scheduled: daily, monthly, weekly: 2021-01-23:08:39', ['test-app1', 'test-app3'], archive_comment='{{"type": "scheduled", "periods": ["daily", "monthly", "weekly"]}}')].
/usr/lib/python3.9/unittest/mock.py:868: AssertionError
_____ test_run_schedule[schedule_params4-archives_data4-test_now4-run_periods4-cleanups4] _____
get_instance = <MagicMock name='get_instance' id='140312756674272'>
schedule_params = [True, 10, 10, 10, 0]
archives_data = [{'periods': ['monthly'], 'time': datetime.timedelta(days=-1, seconds=85800)}]
test_now = datetime.datetime(2021, 1, 23, 8, 39, 23, 492302), run_periods = [], cleanups = []
@pytest.mark.parametrize(
'schedule_params,archives_data,test_now,run_periods,cleanups', cases)
@patch('plinth.modules.backups.repository.get_instance')
def test_run_schedule(get_instance, schedule_params, archives_data, test_now,
run_periods, cleanups):
"""Test that backups are run at expected time."""
setup_helper.get_state.return_value = 'up-to-date'
repository = MagicMock()
repository.list_archives.side_effect = \
lambda: _get_archives_from_test_data(archives_data)
get_instance.return_value = repository
with patch('plinth.modules.backups.schedule.datetime') as mock_datetime, \
patch('plinth.app.App.list') as app_list:
app_list.return_value = [
_get_test_app('test-app1'),
_get_test_app('test-app2'),
_get_test_app('test-app3')
]
mock_datetime.now.return_value = test_now
mock_datetime.strptime = datetime.strptime
mock_datetime.min = datetime.min
mock_datetime.side_effect = lambda *args, **kwargs: datetime(
*args, **kwargs)
schedule = Schedule('test_uuid', schedule_params[0],
schedule_params[1], schedule_params[2],
schedule_params[3], schedule_params[4],
['test-app2'])
schedule.run_schedule()
if not run_periods:
> repository.create_archive.assert_not_called()
plinth/modules/backups/tests/test_schedule.py:463:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MagicMock name='get_instance().create_archive' id='140312755282368'>
def assert_not_called(self):
"""assert that the mock was never called.
"""
if self.call_count != 0:
msg = ("Expected '%s' to not have been called. Called %s times.%s"
% (self._mock_name or 'mock',
self.call_count,
self._calls_repr()))
> raise AssertionError(msg)
E AssertionError: Expected 'create_archive' to not have been called. Called 1 times.
E Calls: [call('scheduled: daily, monthly, weekly: 2021-01-23:08:39', ['test-app1', 'test-app3'], archive_comment='{{"type": "scheduled", "periods": ["daily", "monthly", "weekly"]}}')].
/usr/lib/python3.9/unittest/mock.py:868: AssertionError