From bbb80fe5774b3abac6212938b46ec691cc3d63ef Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 5 Mar 2019 11:20:37 -0800 Subject: [PATCH] tests: Fix backups API test cases to work under all conditions Ensure that loaded module list is mocked instead of actually loading modules. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/backups/tests/test_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plinth/modules/backups/tests/test_api.py b/plinth/modules/backups/tests/test_api.py index 8f256c8e0..f19205a47 100644 --- a/plinth/modules/backups/tests/test_api.py +++ b/plinth/modules/backups/tests/test_api.py @@ -111,8 +111,10 @@ class TestBackupProcesses(unittest.TestCase): @staticmethod @patch('plinth.modules.backups.api._install_apps_before_restore') - def test_restore_apps(mock_install): + @patch('plinth.module_loader.loaded_modules.items') + def test_restore_apps(mock_install, modules): """Test that restore_handler is called.""" + modules.return_value = [('a', MagicMock())] restore_handler = MagicMock() api.restore_apps(restore_handler) restore_handler.assert_called_once() @@ -129,7 +131,6 @@ class TestBackupProcesses(unittest.TestCase): del apps[3][1].backup modules.return_value = apps - module_loader.load_modules() returned_apps = api.get_all_apps_for_backup() expected_apps = [ api.BackupApp('a', apps[0][1]), @@ -148,7 +149,6 @@ class TestBackupProcesses(unittest.TestCase): ] modules.return_value = apps - module_loader.load_modules() app_names = ['config', 'names'] apps = api.get_apps_in_order(app_names) assert apps[0].name == 'names'