diff --git a/bin/freedombox-change-password b/bin/freedombox-change-password index d9e2f9dac..7fd943ec0 100755 --- a/bin/freedombox-change-password +++ b/bin/freedombox-change-password @@ -11,14 +11,14 @@ import argparse import getpass import sys -import plinth.web_framework -from plinth.modules.users import privileged +import freedombox.web_framework +from freedombox.modules.users import privileged def main(): """Ask for new password, setup Django and update a user's password.""" try: - plinth.web_framework.init() + freedombox.web_framework.init() except Exception: _print('Error initializing Django.') return diff --git a/bin/freedombox-cmd b/bin/freedombox-cmd index ce9c06093..b62b93a49 100755 --- a/bin/freedombox-cmd +++ b/bin/freedombox-cmd @@ -1,6 +1,6 @@ #!/usr/bin/python3 # SPDX-License-Identifier: AGPL-3.0-or-later -import plinth.privileged_daemon +import freedombox.privileged_daemon -plinth.privileged_daemon.client_main() +freedombox.privileged_daemon.client_main() diff --git a/bin/freedombox-privileged b/bin/freedombox-privileged index 6c487ef0a..ad8c9809a 100755 --- a/bin/freedombox-privileged +++ b/bin/freedombox-privileged @@ -1,6 +1,6 @@ #!/usr/bin/python3 # SPDX-License-Identifier: AGPL-3.0-or-later -import plinth.privileged_daemon +import freedombox.privileged_daemon -plinth.privileged_daemon.main() +freedombox.privileged_daemon.main() diff --git a/bin/plinth b/bin/plinth index e81afab03..0ddc34b9f 100755 --- a/bin/plinth +++ b/bin/plinth @@ -1,6 +1,6 @@ #!/usr/bin/python3 # SPDX-License-Identifier: AGPL-3.0-or-later -import plinth.__main__ +import freedombox.__main__ -plinth.__main__.main() +freedombox.__main__.main() diff --git a/freedombox/actions.py b/freedombox/actions.py index cce710fa4..8a1f82672 100644 --- a/freedombox/actions.py +++ b/freedombox/actions.py @@ -463,8 +463,8 @@ def _privileged_call(module_name, action_name, arguments, log_error=True): raise SyntaxError('Invalid module name') cfg.read() - if module_name == 'plinth': - import_path = 'plinth' + if module_name == 'freedombox': + import_path = 'freedombox' else: try: import_path = module_loader.get_module_import_path(module_name) diff --git a/freedombox/conftest.py b/freedombox/conftest.py index 949f3c62c..9675763f6 100644 --- a/freedombox/conftest.py +++ b/freedombox/conftest.py @@ -73,7 +73,7 @@ def fixture_load_cfg(): saved_state[key] = getattr(cfg, key) root_dir = pathlib.Path(__file__).resolve().parent - cfg_file = root_dir / 'plinth' / 'develop.config' + cfg_file = root_dir / 'freedombox' / 'develop.config' cfg.read_file(str(cfg_file)) yield cfg @@ -190,7 +190,7 @@ def fixture_mock_run_as_user(): from freedombox import action_utils return action_utils.run(*args, **kwargs) - with patch('plinth.action_utils.run_as_user') as mock: + with patch('freedombox.action_utils.run_as_user') as mock: mock.side_effect = _bypass_runuser yield diff --git a/freedombox/container.py b/freedombox/container.py index ccb523951..03f533cc1 100644 --- a/freedombox/container.py +++ b/freedombox/container.py @@ -8,7 +8,7 @@ from django.utils.translation import gettext_noop from freedombox import app, log, privileged from freedombox.daemon import diagnose_port_listening from freedombox.diagnostic_check import (DiagnosticCheck, - DiagnosticCheckParameters, Result) + DiagnosticCheckParameters, Result) class Container(app.LeaderComponent, log.LogEmitter): diff --git a/freedombox/daemon.py b/freedombox/daemon.py index 71e16eea9..ec1b5f45d 100644 --- a/freedombox/daemon.py +++ b/freedombox/daemon.py @@ -10,7 +10,7 @@ from django.utils.translation import gettext_noop from freedombox import action_utils, app, log from freedombox.diagnostic_check import (DiagnosticCheck, - DiagnosticCheckParameters, Result) + DiagnosticCheckParameters, Result) class Daemon(app.LeaderComponent, log.LogEmitter): diff --git a/freedombox/forms.py b/freedombox/forms.py index 6d5752b9d..7af72f959 100644 --- a/freedombox/forms.py +++ b/freedombox/forms.py @@ -11,12 +11,12 @@ from django.utils import translation from django.utils.translation import get_language_info from django.utils.translation import gettext_lazy as _ -import plinth +import freedombox def _get_repository_choices(): """Return the list of available repositories.""" - import plinth.modules.backups.repository as repository_module + import freedombox.modules.backups.repository as repository_module choices = [(repository.uuid, repository.name) for repository in repository_module.get_repositories() if repository.is_usable()] @@ -109,9 +109,9 @@ class LanguageSelectionFormMixin: for language_code, language_name in settings.LANGUAGES: locale_code = translation.to_locale(language_code) - plinth_dir = os.path.dirname(plinth.__file__) + freedombox_dir = os.path.dirname(freedombox.__file__) if language_code == 'en' or os.path.exists( - os.path.join(plinth_dir, 'locale', locale_code)): + os.path.join(freedombox_dir, 'locale', locale_code)): supported_languages.append( (language_code, _get_local_name(language_code, language_name))) diff --git a/freedombox/log.py b/freedombox/log.py index 414b2a591..f1040d9bd 100644 --- a/freedombox/log.py +++ b/freedombox/log.py @@ -133,7 +133,7 @@ def get_configuration(syslog_identifier='freedombox'): 'disable_existing_loggers': False, 'formatters': { 'color': { - '()': 'plinth.log.ColoredFormatter', + '()': 'freedombox.log.ColoredFormatter', 'format': '{colored_levelname} {colored_name} {message}', 'style': '{' } diff --git a/freedombox/modules/apache/components.py b/freedombox/modules/apache/components.py index c5b6788d9..35ae91deb 100644 --- a/freedombox/modules/apache/components.py +++ b/freedombox/modules/apache/components.py @@ -8,7 +8,7 @@ from django.utils.translation import gettext_noop from freedombox import action_utils, app, kvstore from freedombox.diagnostic_check import (DiagnosticCheck, - DiagnosticCheckParameters, Result) + DiagnosticCheckParameters, Result) from freedombox.privileged import service as service_privileged from . import privileged diff --git a/freedombox/modules/apache/tests/test_components.py b/freedombox/modules/apache/tests/test_components.py index bd1778e28..eed8faace 100644 --- a/freedombox/modules/apache/tests/test_components.py +++ b/freedombox/modules/apache/tests/test_components.py @@ -11,8 +11,8 @@ import pytest from freedombox import app, kvstore from freedombox.diagnostic_check import DiagnosticCheck, Result from freedombox.modules.apache.components import (Webserver, WebserverRoot, - check_url, diagnose_url, - diagnose_url_on_all) + check_url, diagnose_url, + diagnose_url_on_all) def test_webserver_init(): @@ -34,7 +34,7 @@ def test_webserver_init(): assert not webserver.expect_redirects -@patch('plinth.action_utils.webserver_is_enabled') +@patch('freedombox.action_utils.webserver_is_enabled') def test_webserver_is_enabled(webserver_is_enabled): """Test that checking webserver configuration enabled works.""" webserver = Webserver('test-webserver', 'test-config', kind='module') @@ -49,7 +49,7 @@ def test_webserver_is_enabled(webserver_is_enabled): webserver_is_enabled.assert_has_calls([call('test-config', kind='module')]) -@patch('plinth.modules.apache.privileged.enable') +@patch('freedombox.modules.apache.privileged.enable') def test_webserver_enable(enable): """Test that enabling webserver configuration works.""" webserver = Webserver('test-webserver', 'test-config', kind='module') @@ -58,7 +58,7 @@ def test_webserver_enable(enable): enable.assert_has_calls([call('test-config', 'module')]) -@patch('plinth.modules.apache.privileged.disable') +@patch('freedombox.modules.apache.privileged.disable') def test_webserver_disable(disable): """Test that disabling webserver configuration works.""" webserver = Webserver('test-webserver', 'test-config', kind='module') @@ -67,8 +67,8 @@ def test_webserver_disable(disable): disable.assert_has_calls([call('test-config', 'module')]) -@patch('plinth.modules.apache.components.diagnose_url') -@patch('plinth.modules.apache.components.diagnose_url_on_all') +@patch('freedombox.modules.apache.components.diagnose_url') +@patch('freedombox.modules.apache.components.diagnose_url_on_all') def test_webserver_diagnose(diagnose_url_on_all, diagnose_url): """Test running diagnostics.""" @@ -111,8 +111,8 @@ def test_webserver_diagnose(diagnose_url_on_all, diagnose_url): ]) -@patch('plinth.privileged.service.restart') -@patch('plinth.privileged.service.reload') +@patch('freedombox.privileged.service.restart') +@patch('freedombox.privileged.service.reload') def test_webserver_setup(service_reload, service_restart): """Test that component restart/reloads web server during app upgrades.""" @@ -181,12 +181,12 @@ def test_webserver_root_init(): assert webserver.last_updated_version == 0 -@patch('plinth.modules.apache.privileged.link_root') +@patch('freedombox.modules.apache.privileged.link_root') def test_webserver_root_enable(link_root): """Test that enabling webserver root works.""" webserver = WebserverRoot('test-webserver', 'test-config') - with patch('plinth.modules.apache.components.WebserverRoot.domain_get' + with patch('freedombox.modules.apache.components.WebserverRoot.domain_get' ) as get: get.return_value = None webserver.enable() @@ -197,12 +197,12 @@ def test_webserver_root_enable(link_root): link_root.assert_has_calls([call('x-domain', 'test-config')]) -@patch('plinth.modules.apache.privileged.unlink_root') +@patch('freedombox.modules.apache.privileged.unlink_root') def test_webserver_root_disable(unlink_root): """Test that disabling webserver root works.""" webserver = WebserverRoot('test-webserver', 'test-config') - with patch('plinth.modules.apache.components.WebserverRoot.domain_get' + with patch('freedombox.modules.apache.components.WebserverRoot.domain_get' ) as get: get.return_value = None webserver.disable() @@ -224,9 +224,9 @@ def test_webserver_root_domain_get(): @pytest.mark.django_db -@patch('plinth.modules.apache.privileged.unlink_root') -@patch('plinth.modules.apache.privileged.link_root') -@patch('plinth.app.Component.app', new_callable=PropertyMock) +@patch('freedombox.modules.apache.privileged.unlink_root') +@patch('freedombox.modules.apache.privileged.link_root') +@patch('freedombox.app.Component.app', new_callable=PropertyMock) def test_webserver_root_domain_set(component_app, link_root, unlink_root): """Test setting webserver root's domain.""" webserver = WebserverRoot('test-webserver', 'test-config') @@ -253,10 +253,10 @@ def test_webserver_root_domain_set(component_app, link_root, unlink_root): @pytest.mark.django_db -@patch('plinth.modules.apache.components.WebserverRoot.disable') -@patch('plinth.modules.apache.components.WebserverRoot.enable') -@patch('plinth.modules.apache.components.diagnose_url') -@patch('plinth.app.Component.app', new_callable=PropertyMock) +@patch('freedombox.modules.apache.components.WebserverRoot.disable') +@patch('freedombox.modules.apache.components.WebserverRoot.enable') +@patch('freedombox.modules.apache.components.diagnose_url') +@patch('freedombox.app.Component.app', new_callable=PropertyMock) def test_webserver_root_diagnose(component_app, diagnose_url, enable, disable): """Test running diagnostics on webserver root component.""" webserver = WebserverRoot('test-webserver', 'test-config') @@ -269,7 +269,7 @@ def test_webserver_root_diagnose(component_app, diagnose_url, enable, disable): assert webserver.diagnose() == [result] -@patch('plinth.privileged.service.reload') +@patch('freedombox.privileged.service.reload') def test_webserver_root_setup(service_reload): """Test that component reloads web server during app upgrades.""" @@ -311,9 +311,9 @@ def test_webserver_root_setup(service_reload): @pytest.mark.django_db -@patch('plinth.modules.apache.components.WebserverRoot.disable') -@patch('plinth.modules.apache.components.WebserverRoot.enable') -@patch('plinth.app.Component.app', new_callable=PropertyMock) +@patch('freedombox.modules.apache.components.WebserverRoot.disable') +@patch('freedombox.modules.apache.components.WebserverRoot.enable') +@patch('freedombox.app.Component.app', new_callable=PropertyMock) def test_webserver_root_uninstall(component_app, enable, disable): """Test that component removes the DB key during uninstall.""" webserver = WebserverRoot('test-webserver', 'test-config') @@ -326,8 +326,8 @@ def test_webserver_root_uninstall(component_app, enable, disable): assert kvstore.get_default('test-webserver_domain', 'x-value') == 'x-value' -@patch('plinth.modules.apache.components.check_url') -@patch('plinth.action_utils.get_addresses') +@patch('freedombox.modules.apache.components.check_url') +@patch('freedombox.action_utils.get_addresses') def test_diagnose_url(get_addresses, check): """Test diagnosing a URL.""" args = { diff --git a/freedombox/modules/backups/tests/test_api.py b/freedombox/modules/backups/tests/test_api.py index 37a0fce4a..c74c30f4c 100644 --- a/freedombox/modules/backups/tests/test_api.py +++ b/freedombox/modules/backups/tests/test_api.py @@ -93,7 +93,7 @@ class TestBackupProcesses: backup_handler.assert_called_once() @staticmethod - @patch('plinth.modules.backups.api._install_apps_before_restore') + @patch('freedombox.modules.backups.api._install_apps_before_restore') def test_restore_apps(mock_install): """Test that restore_handler is called.""" restore_handler = MagicMock() @@ -101,8 +101,8 @@ class TestBackupProcesses: restore_handler.assert_called_once() @staticmethod - @patch('plinth.app.App.get_setup_state') - @patch('plinth.app.App.list') + @patch('freedombox.app.App.get_setup_state') + @patch('freedombox.app.App.list') def test_get_all_components_for_backup(apps_list, get_setup_state): """Test listing components supporting backup and needing backup.""" get_setup_state.side_effect = [ @@ -121,7 +121,7 @@ class TestBackupProcesses: assert returned_components == expected_components @staticmethod - @patch('plinth.app.App.list') + @patch('freedombox.app.App.list') def test_get_components_in_order(apps_list): """Test that components are listed in correct dependency order.""" apps = [ @@ -155,10 +155,10 @@ class TestBackupProcesses: assert not apps[1].locked @staticmethod - @patch('plinth.action_utils.webserver_is_enabled') - @patch('plinth.action_utils.service_is_running') - @patch('plinth.privileged.service.stop') - @patch('plinth.modules.apache.privileged.disable') + @patch('freedombox.action_utils.webserver_is_enabled') + @patch('freedombox.action_utils.service_is_running') + @patch('freedombox.privileged.service.stop') + @patch('freedombox.modules.apache.privileged.disable') def test__shutdown_services(apache_disable, service_stop, service_is_running, webserver_is_enabled): """Test that services are stopped in correct order.""" @@ -188,8 +188,8 @@ class TestBackupProcesses: service_stop.assert_has_calls([call('b'), call('a')]) @staticmethod - @patch('plinth.privileged.service.start') - @patch('plinth.modules.apache.privileged.enable') + @patch('freedombox.privileged.service.start') + @patch('freedombox.modules.apache.privileged.enable') def test__restore_services(apache_enable, service_start): """Test that services are restored in correct order.""" original_state = [ diff --git a/freedombox/modules/backups/tests/test_backups.py b/freedombox/modules/backups/tests/test_backups.py index 2c675384e..433a7fd0e 100644 --- a/freedombox/modules/backups/tests/test_backups.py +++ b/freedombox/modules/backups/tests/test_backups.py @@ -12,13 +12,14 @@ import pytest from freedombox.modules import backups from freedombox.modules.backups import privileged -from freedombox.modules.backups.repository import BorgRepository, SshBorgRepository +from freedombox.modules.backups.repository import (BorgRepository, + SshBorgRepository) from freedombox.tests import config as test_config pytestmark = pytest.mark.usefixtures('needs_root', 'needs_borg', 'load_cfg', 'mock_privileged') -privileged_modules_to_mock = ['plinth.modules.backups.privileged'] +privileged_modules_to_mock = ['freedombox.modules.backups.privileged'] # try to access a non-existing url and a URL that exists but does not # grant access diff --git a/freedombox/modules/backups/tests/test_components.py b/freedombox/modules/backups/tests/test_components.py index e8759a8e6..8e894620d 100644 --- a/freedombox/modules/backups/tests/test_components.py +++ b/freedombox/modules/backups/tests/test_components.py @@ -245,7 +245,7 @@ def test_backup_restore_hooks(backup_restore): @pytest.mark.django_db -@patch('plinth.modules.backups.privileged.dump_settings') +@patch('freedombox.modules.backups.privileged.dump_settings') def test_backup_restore_backup_pre(dump_settings, backup_restore): """Test running backup-pre hook.""" packet = None @@ -260,7 +260,7 @@ def test_backup_restore_backup_pre(dump_settings, backup_restore): dump_settings.assert_has_calls([call('testapp', {'setting-1': 'value-1'})]) -@patch('plinth.modules.backups.privileged.delete_before_restore') +@patch('freedombox.modules.backups.privileged.delete_before_restore') def test_backup_restore_restore_pre(delete_before_restore, backup_restore): """Test running restore-pre hook.""" packet = None @@ -275,7 +275,7 @@ def test_backup_restore_restore_pre(delete_before_restore, backup_restore): @pytest.mark.django_db -@patch('plinth.modules.backups.privileged.load_settings') +@patch('freedombox.modules.backups.privileged.load_settings') def test_backup_restore_restore_post(load_settings, backup_restore): """Test running restore-post hook.""" packet = None diff --git a/freedombox/modules/backups/tests/test_schedule.py b/freedombox/modules/backups/tests/test_schedule.py index 4a8c64642..d246ccf72 100644 --- a/freedombox/modules/backups/tests/test_schedule.py +++ b/freedombox/modules/backups/tests/test_schedule.py @@ -9,7 +9,7 @@ from unittest.mock import MagicMock, call, patch import pytest -import plinth.modules.backups.repository as repository_module +import freedombox.modules.backups.repository as repository_module from freedombox.app import App from ..components import BackupRestore @@ -420,8 +420,8 @@ cases = [ @pytest.mark.parametrize( 'schedule_params,archives_data,test_now,run_periods,cleanups', cases) -@patch('plinth.app.App.get_setup_state') -@patch('plinth.modules.backups.repository.get_instance') +@patch('freedombox.app.App.get_setup_state') +@patch('freedombox.modules.backups.repository.get_instance') def test_run_schedule(get_instance, get_setup_state, schedule_params, archives_data, test_now, run_periods, cleanups): """Test that backups are run at expected time.""" @@ -434,9 +434,10 @@ def test_run_schedule(get_instance, get_setup_state, schedule_params, repository.generate_archive_name = lambda: \ repository_module.BaseBorgRepository.generate_archive_name(None) - with patch('plinth.modules.backups.schedule.datetime') as mock_datetime, \ - patch('plinth.modules.backups.repository.datetime') \ - as repo_datetime, patch('plinth.app.App.list') as app_list: + with patch('freedombox.modules.backups.schedule.datetime') as \ + mock_datetime, \ + patch('freedombox.modules.backups.repository.datetime') \ + as repo_datetime, patch('freedombox.app.App.list') as app_list: app_list.return_value = [ _get_test_app('test-app1'), _get_test_app('test-app2'), diff --git a/freedombox/modules/calibre/tests/test_privileged.py b/freedombox/modules/calibre/tests/test_privileged.py index ed9e5a865..d3b802bf7 100644 --- a/freedombox/modules/calibre/tests/test_privileged.py +++ b/freedombox/modules/calibre/tests/test_privileged.py @@ -9,7 +9,7 @@ import pytest from freedombox.modules.calibre import privileged pytestmark = pytest.mark.usefixtures('mock_privileged') -privileged_modules_to_mock = ['plinth.modules.calibre.privileged'] +privileged_modules_to_mock = ['freedombox.modules.calibre.privileged'] @pytest.fixture(autouse=True) diff --git a/freedombox/modules/calibre/tests/test_views.py b/freedombox/modules/calibre/tests/test_views.py index 13ff4c46b..9d6853316 100644 --- a/freedombox/modules/calibre/tests/test_views.py +++ b/freedombox/modules/calibre/tests/test_views.py @@ -13,16 +13,16 @@ from django.http.response import Http404 from freedombox import module_loader from freedombox.modules.calibre import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') @pytest.fixture(autouse=True, scope='module') def fixture_calibre_urls(): - """Make sure calibre app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.calibre') + """Make sure calibre app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.calibre') module_loader.include_urls() yield @@ -30,7 +30,7 @@ def fixture_calibre_urls(): @pytest.fixture(autouse=True) def calibre_patch(): """Patch calibre methods.""" - with patch('plinth.modules.calibre.privileged.list_libraries' + with patch('freedombox.modules.calibre.privileged.list_libraries' ) as list_libraries: list_libraries.return_value = ['TestExistingLibrary'] @@ -47,7 +47,7 @@ def make_request(request, view, **kwargs): return response, messages -@patch('plinth.modules.calibre.privileged.create_library') +@patch('freedombox.modules.calibre.privileged.create_library') def test_create_library(create_library, rf): """Test that create library view works.""" form_data = {'calibre-name': 'TestLibrary'} @@ -61,7 +61,7 @@ def test_create_library(create_library, rf): create_library.assert_has_calls([call('TestLibrary')]) -@patch('plinth.modules.calibre.privileged.create_library') +@patch('freedombox.modules.calibre.privileged.create_library') def test_create_library_failed(create_library, rf): """Test that create library fails as expected.""" create_library.side_effect = RuntimeError('TestError') @@ -100,7 +100,7 @@ def test_create_library_invalid_name(rf): assert response.status_code == 200 -@patch('plinth.app.App.get') +@patch('freedombox.app.App.get') def test_delete_library_confirmation_view(_app, rf): """Test that deleting library confirmation shows correct name.""" response, _ = make_request(rf.get(''), views.delete_library, @@ -109,8 +109,8 @@ def test_delete_library_confirmation_view(_app, rf): assert response.context_data['name'] == 'TestExistingLibrary' -@patch('plinth.modules.calibre.privileged.delete_library') -@patch('plinth.app.App.get') +@patch('freedombox.modules.calibre.privileged.delete_library') +@patch('freedombox.app.App.get') def test_delete_library(_app, delete_library, rf): """Test that deleting a library works.""" response, messages = make_request(rf.post(''), views.delete_library, @@ -121,7 +121,7 @@ def test_delete_library(_app, delete_library, rf): delete_library.assert_has_calls([call('TestExistingLibrary')]) -@patch('plinth.modules.calibre.privileged.delete_library') +@patch('freedombox.modules.calibre.privileged.delete_library') def test_delete_library_error(delete_library, rf): """Test that deleting a library shows error when operation fails.""" delete_library.side_effect = ValueError('TestError') diff --git a/freedombox/modules/config/tests/test_config.py b/freedombox/modules/config/tests/test_config.py index 9037d8396..6ae4943d2 100644 --- a/freedombox/modules/config/tests/test_config.py +++ b/freedombox/modules/config/tests/test_config.py @@ -13,7 +13,7 @@ from freedombox import __main__ as plinth_main from freedombox import utils from freedombox.modules.apache import uws_directory_of_user, uws_url_of_user from freedombox.modules.config import (_home_page_scid2url, change_home_page, - get_home_page, home_page_url2scid) + get_home_page, home_page_url2scid) def test_homepage_mapping(): @@ -70,7 +70,7 @@ def test_homepage_mapping_skip_ci(): @patch( - 'plinth.frontpage.Shortcut.list', + 'freedombox.frontpage.Shortcut.list', Mock(return_value=[ Mock(url='url/for/' + id, component_id=id) for id in ('a', 'b') ])) diff --git a/freedombox/modules/coturn/tests/test_components.py b/freedombox/modules/coturn/tests/test_components.py index b12ef53db..50acde1b9 100644 --- a/freedombox/modules/coturn/tests/test_components.py +++ b/freedombox/modules/coturn/tests/test_components.py @@ -104,7 +104,7 @@ def test_component_init_and_list(): assert [component1, component2, component3] == list(TurnConsumer.list()) -@patch('plinth.modules.coturn.get_config') +@patch('freedombox.modules.coturn.get_config') def test_notify_on_configuration_changed(get_config, turn_configuration): """Test configuration change notifications.""" component = TurnConsumer('component') @@ -114,7 +114,7 @@ def test_notify_on_configuration_changed(get_config, turn_configuration): mock_method.assert_has_calls([call(turn_configuration)]) -@patch('plinth.modules.coturn.get_config') +@patch('freedombox.modules.coturn.get_config') def test_get_configuration(get_config, turn_configuration): """Test coturn configuration retrieval using component.""" get_config.return_value = turn_configuration @@ -122,7 +122,7 @@ def test_get_configuration(get_config, turn_configuration): assert component.get_configuration() == turn_configuration -@patch('plinth.modules.coturn.get_config') +@patch('freedombox.modules.coturn.get_config') def test_get_user_configuration(get_config, turn_configuration): """Test coturn user configuration retrieval using component.""" get_config.return_value = turn_configuration diff --git a/freedombox/modules/coturn/views.py b/freedombox/modules/coturn/views.py index 4c44230c5..f8fb7c393 100644 --- a/freedombox/modules/coturn/views.py +++ b/freedombox/modules/coturn/views.py @@ -4,7 +4,7 @@ from django.contrib import messages from django.utils.translation import gettext_lazy as _ -import plinth.modules.coturn as coturn +import freedombox.modules.coturn as coturn from freedombox import app as app_module from freedombox import views diff --git a/freedombox/modules/diagnostics/tests/test_diagnostics.py b/freedombox/modules/diagnostics/tests/test_diagnostics.py index 51107c782..493e0f893 100644 --- a/freedombox/modules/diagnostics/tests/test_diagnostics.py +++ b/freedombox/modules/diagnostics/tests/test_diagnostics.py @@ -20,7 +20,7 @@ class AppTest(App): def test_get_results(): """Test getting the diagnostics results.""" - var = 'plinth.modules.diagnostics.current_results' + var = 'freedombox.modules.diagnostics.current_results' with patch(var, {}): assert get_results() == {'progress_percentage': 100, 'results': {}} diff --git a/freedombox/modules/dynamicdns/tests/test_gnudip.py b/freedombox/modules/dynamicdns/tests/test_gnudip.py index 6cc2bbe09..0f387209e 100644 --- a/freedombox/modules/dynamicdns/tests/test_gnudip.py +++ b/freedombox/modules/dynamicdns/tests/test_gnudip.py @@ -71,7 +71,7 @@ def test_update_success(): update_resp = Mock() update_resp.text = response_to_update_request - with patch('plinth.modules.dynamicdns.gnudip.requests.get', + with patch('freedombox.modules.dynamicdns.gnudip.requests.get', side_effect=[salt_resp, update_resp]) as mock_get: addr = gnudip.update(server='http://www.2mbit.com:80', ip_type='ipv4', domain='gnudip.dyn.mpis.net', username='gnudip', diff --git a/freedombox/modules/ejabberd/tests/test_turn_config.py b/freedombox/modules/ejabberd/tests/test_turn_config.py index 5a709d355..220ad15c9 100644 --- a/freedombox/modules/ejabberd/tests/test_turn_config.py +++ b/freedombox/modules/ejabberd/tests/test_turn_config.py @@ -23,7 +23,7 @@ overridden_configuration = TurnConfiguration( pytestmark = pytest.mark.usefixtures('mock_privileged') current_directory = pathlib.Path(__file__).parent -privileged_modules_to_mock = ['plinth.modules.ejabberd.privileged'] +privileged_modules_to_mock = ['freedombox.modules.ejabberd.privileged'] @pytest.fixture(name='conf_file') @@ -58,7 +58,7 @@ def fixture_test_configuration(conf_file): The module state is patched to be 'up-to-date'. """ - with patch('plinth.app.App.get') as app_get: + with patch('freedombox.app.App.get') as app_get: app = Mock() app_get.return_value = app app.needs_setup.return_value = False @@ -66,7 +66,8 @@ def fixture_test_configuration(conf_file): def _set_turn_configuration(config=managed_configuration, managed=True): - with patch('plinth.action_utils.service_is_running', return_value=False): + with patch('freedombox.action_utils.service_is_running', + return_value=False): ejabberd.update_turn_configuration(config, managed=managed) diff --git a/freedombox/modules/email/__init__.py b/freedombox/modules/email/__init__.py index 95ea57d89..7007b769e 100644 --- a/freedombox/modules/email/__init__.py +++ b/freedombox/modules/email/__init__.py @@ -6,14 +6,14 @@ import logging from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ -import plinth.app +import freedombox.app from freedombox import cfg, frontpage, menu from freedombox.config import DropinConfigs from freedombox.daemon import Daemon from freedombox.modules.apache.components import Webserver from freedombox.modules.backups.components import BackupRestore from freedombox.modules.firewall.components import (Firewall, - FirewallLocalProtection) + FirewallLocalProtection) from freedombox.modules.letsencrypt.components import LetsEncrypt from freedombox.package import Packages from freedombox.privileged import service as service_privileged @@ -47,7 +47,7 @@ _description = [ logger = logging.getLogger(__name__) -class EmailApp(plinth.app.App): +class EmailApp(freedombox.app.App): """FreedomBox app for an email server.""" app_id = 'email' @@ -58,12 +58,12 @@ class EmailApp(plinth.app.App): """Initialize the email app.""" super().__init__() - info = plinth.app.Info(app_id=self.app_id, version=self._version, - name=_('Postfix/Dovecot'), - icon_filename='email', description=_description, - manual_page='Email', clients=manifest.clients, - tags=manifest.tags, - donation_url='https://rspamd.com/support.html') + info = freedombox.app.Info( + app_id=self.app_id, version=self._version, + name=_('Postfix/Dovecot'), icon_filename='email', + description=_description, manual_page='Email', + clients=manifest.clients, tags=manifest.tags, + donation_url='https://rspamd.com/support.html') self.add(info) menu_item = menu.Menu('menu-email', info.name, info.icon_filename, @@ -260,7 +260,7 @@ def _get_first_admin(): def on_domain_added(sender, domain_type, name, description='', services=None, **kwargs): """Handle addition of a new domain.""" - app = plinth.app.App.get('email') + app = freedombox.app.App.get('email') if app.needs_setup(): return @@ -269,7 +269,7 @@ def on_domain_added(sender, domain_type, name, description='', services=None, def on_domain_removed(sender, domain_type, name='', **kwargs): """Handle removal of a domain.""" - app = plinth.app.App.get('email') + app = freedombox.app.App.get('email') if app.needs_setup(): return diff --git a/freedombox/modules/firewall/components.py b/freedombox/modules/firewall/components.py index 349c309af..7399486c4 100644 --- a/freedombox/modules/firewall/components.py +++ b/freedombox/modules/firewall/components.py @@ -11,7 +11,7 @@ from django.utils.translation import gettext_noop from freedombox import app from freedombox.diagnostic_check import (DiagnosticCheck, - DiagnosticCheckParameters, Result) + DiagnosticCheckParameters, Result) from freedombox.modules import firewall logger = logging.getLogger(__name__) @@ -120,7 +120,7 @@ class Firewall(app.FollowerComponent): def diagnose(self) -> _list_type[DiagnosticCheck]: """Check if the firewall ports are open and only as expected. - See :py:meth:`plinth.app.Component.diagnose`. + See :py:meth:`freedombox.app.Component.diagnose`. """ results = [] diff --git a/freedombox/modules/firewall/tests/test_components.py b/freedombox/modules/firewall/tests/test_components.py index 2ab218016..0a896c913 100644 --- a/freedombox/modules/firewall/tests/test_components.py +++ b/freedombox/modules/firewall/tests/test_components.py @@ -10,7 +10,7 @@ import pytest from freedombox.app import App from freedombox.diagnostic_check import DiagnosticCheck, Result from freedombox.modules.firewall.components import (Firewall, - FirewallLocalProtection) + FirewallLocalProtection) @pytest.fixture(name='empty_firewall_list', autouse=True) @@ -42,7 +42,7 @@ def test_init(): assert firewall.is_external -@patch('plinth.modules.firewall.get_port_details') +@patch('freedombox.modules.firewall.get_port_details') def test_port_details(get_port_details): """Test retrieving port details for a firewall component.""" return_values = { @@ -64,8 +64,8 @@ def test_port_details(get_port_details): }] -@patch('plinth.modules.firewall.add_service') -@patch('plinth.modules.firewall.get_enabled_services') +@patch('freedombox.modules.firewall.add_service') +@patch('freedombox.modules.firewall.get_enabled_services') def test_enable(get_enabled_services, add_service): """Test enabling a firewall component.""" @@ -92,9 +92,9 @@ def test_enable(get_enabled_services, add_service): add_service.assert_has_calls(calls) -@patch('plinth.modules.firewall.remove_service') -@patch('plinth.modules.firewall.add_service') -@patch('plinth.modules.firewall.get_enabled_services') +@patch('freedombox.modules.firewall.remove_service') +@patch('freedombox.modules.firewall.add_service') +@patch('freedombox.modules.firewall.get_enabled_services') def test_disable(get_enabled_services, add_service, remove_service): """Test disabling a firewall component.""" Firewall('firewall-1', ports=['test-port1'], is_external=False) @@ -130,8 +130,8 @@ def test_disable(get_enabled_services, add_service, remove_service): remove_service.assert_has_calls(calls) -@patch('plinth.modules.firewall.get_port_details') -@patch('plinth.modules.firewall.get_enabled_services') +@patch('freedombox.modules.firewall.get_port_details') +@patch('freedombox.modules.firewall.get_enabled_services') def test_diagnose(get_enabled_services, get_port_details): """Test diagnosing open/closed firewall ports.""" @@ -227,7 +227,7 @@ def test_local_protection_init(): assert component.tcp_ports == ['1234', '4567'] -@patch('plinth.modules.firewall.add_passthrough') +@patch('freedombox.modules.firewall.add_passthrough') def test_local_protection_enable(add_passthrough): """Test enabling local protection component.""" component = FirewallLocalProtection('test-component', ['1234', '4567']) @@ -246,7 +246,7 @@ def test_local_protection_enable(add_passthrough): add_passthrough.assert_has_calls(calls) -@patch('plinth.modules.firewall.remove_passthrough') +@patch('freedombox.modules.firewall.remove_passthrough') def test_local_protection_disable(remove_passthrough): """Test disabling local protection component.""" component = FirewallLocalProtection('test-component', ['1234', '4567']) @@ -265,7 +265,7 @@ def test_local_protection_disable(remove_passthrough): remove_passthrough.assert_has_calls(calls) -@patch('plinth.modules.firewall.components.FirewallLocalProtection.enable') +@patch('freedombox.modules.firewall.components.FirewallLocalProtection.enable') def test_local_protection_setup(enable): """Test setting up protection when updating the app.""" diff --git a/freedombox/modules/gitweb/tests/test_privileged.py b/freedombox/modules/gitweb/tests/test_privileged.py index 95ca93dd4..9e66bba0f 100644 --- a/freedombox/modules/gitweb/tests/test_privileged.py +++ b/freedombox/modules/gitweb/tests/test_privileged.py @@ -19,7 +19,7 @@ REPO_DATA = { } pytestmark = pytest.mark.usefixtures('mock_privileged', 'mock_run_as_user') -privileged_modules_to_mock = ['plinth.modules.gitweb.privileged'] +privileged_modules_to_mock = ['freedombox.modules.gitweb.privileged'] git_installed = pytest.mark.skipif(not pathlib.Path('/usr/bin/git').exists(), reason='git is not installed') @@ -125,7 +125,7 @@ def test_action_create_repo_with_invalid_urls(url): keep_ownership=True) -@patch('plinth.action_utils.run') +@patch('freedombox.action_utils.run') def test_setup_git_creentials(run): """Test that setting up git credentials works.""" url = 'https://user:pass@host.example/path?key=value' diff --git a/freedombox/modules/gitweb/tests/test_views.py b/freedombox/modules/gitweb/tests/test_views.py index 80cc3f8f2..621f6d1ff 100644 --- a/freedombox/modules/gitweb/tests/test_views.py +++ b/freedombox/modules/gitweb/tests/test_views.py @@ -13,8 +13,8 @@ from django.http.response import Http404 from freedombox import module_loader from freedombox.modules.gitweb import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') EXISTING_REPOS = [ { @@ -38,10 +38,10 @@ EXISTING_REPOS = [ @pytest.fixture(autouse=True, scope='module') def fixture_gitweb_urls(): - """Make sure gitweb app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.gitweb') + """Make sure gitweb app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.gitweb') module_loader.include_urls() yield @@ -49,9 +49,9 @@ def fixture_gitweb_urls(): @pytest.fixture(autouse=True) def gitweb_patch(): """Patch gitweb.""" - privileged = 'plinth.modules.gitweb.privileged' - with patch('plinth.modules.gitweb.get_repo_list') as get_repo_list, \ - patch('plinth.app.App.get') as app_get, \ + privileged = 'freedombox.modules.gitweb.privileged' + with patch('freedombox.modules.gitweb.get_repo_list') as get_repo_list, \ + patch('freedombox.app.App.get') as app_get, \ patch(f'{privileged}.create_repo'), \ patch(f'{privileged}.repo_exists') as repo_exists, \ patch(f'{privileged}.repo_info') as repo_info, \ @@ -92,7 +92,7 @@ def make_request(request, view, **kwargs): def test_repos_view(rf): """Test that a repo list has correct view data.""" - with patch('plinth.views.AppView.get_context_data', + with patch('freedombox.views.AppView.get_context_data', return_value={'is_enabled': True}): view = views.GitwebAppView.as_view() response, _ = make_request(rf.get(''), view) @@ -157,7 +157,7 @@ def test_create_repo_failed_view(rf): """Test that repo creation failure sends correct error message.""" general_error_message = "An error occurred while creating the repository." error_description = 'some error' - with patch('plinth.modules.gitweb.create_repo', + with patch('freedombox.modules.gitweb.create_repo', side_effect=PermissionError(error_description)): form_data = { 'gitweb-name': 'something_other', @@ -193,7 +193,7 @@ def test_clone_repo_view(rf): def test_clone_repo_missing_remote_view(rf): """Test that cloning non-existing repo shows correct error message.""" - with patch('plinth.modules.gitweb.privileged.repo_exists', + with patch('freedombox.modules.gitweb.privileged.repo_exists', return_value=False): form_data = { 'gitweb-name': 'https://example.com/test.git', @@ -281,7 +281,7 @@ def test_edit_repository_invalid_name_view(rf): def test_edit_repository_no_change_view(rf): """Test that not changing any values don't edit the repo.""" - with patch('plinth.modules.gitweb.edit_repo') as edit_repo: + with patch('freedombox.modules.gitweb.edit_repo') as edit_repo: form_data = { 'gitweb-name': EXISTING_REPOS[0]['name'], 'gitweb-description': EXISTING_REPOS[0]['description'], @@ -301,7 +301,7 @@ def test_edit_repository_no_change_view(rf): def test_edit_repository_failed_view(rf): """Test that failed repo editing sends correct error message.""" - with patch('plinth.modules.gitweb.edit_repo', + with patch('freedombox.modules.gitweb.edit_repo', side_effect=PermissionError('Error')): form_data = { 'gitweb-name': 'something_other', @@ -343,7 +343,7 @@ def test_delete_repository_view(rf): def test_delete_repository_fail_view(rf): """Test that failed repository deletion sends correct error message.""" - with patch('plinth.modules.gitweb.privileged.delete_repo', + with patch('freedombox.modules.gitweb.privileged.delete_repo', side_effect=FileNotFoundError('Error')): response, messages = make_request(rf.post(''), views.delete, name=EXISTING_REPOS[0]['name']) diff --git a/freedombox/modules/help/tests/test_views.py b/freedombox/modules/help/tests/test_views.py index cf0457786..04f5b1b8b 100644 --- a/freedombox/modules/help/tests/test_views.py +++ b/freedombox/modules/help/tests/test_views.py @@ -24,8 +24,8 @@ from freedombox import cfg, module_loader from freedombox.modules import help as help_module from freedombox.modules.help import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') def _is_page(response): @@ -36,14 +36,14 @@ def _is_page(response): @pytest.fixture(autouse=True, scope='module') def fixture_app_urls(): - """Make sure app's URLs are part of plinth.urls.""" + """Make sure app's URLs are part of freedombox.urls.""" urls = [ re_path(r'^apps/$', views.index, name='apps'), re_path(r'^system/$', views.index, name='system') ] - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=urls): - modules.append('plinth.modules.help') + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=urls)): + modules.append('freedombox.modules.help') module_loader.include_urls() yield @@ -105,8 +105,8 @@ def test_contribute_page(requests_get, decompress, apt_cache, rf): response.context_data['help']) -@patch('plinth.modules.upgrades.views.is_newer_version_available') -@patch('plinth.modules.upgrades.views.get_os_release') +@patch('freedombox.modules.upgrades.views.is_newer_version_available') +@patch('freedombox.modules.upgrades.views.get_os_release') def test_about(_get_os_release, _is_newer_version_available, rf): """Test some expected items in about view.""" about_url = urls.reverse('help:about') diff --git a/freedombox/modules/jsxc/views.py b/freedombox/modules/jsxc/views.py index cbf7161f7..ff0574e01 100644 --- a/freedombox/modules/jsxc/views.py +++ b/freedombox/modules/jsxc/views.py @@ -6,7 +6,7 @@ import copy from django.http import Http404 from django.views.generic import TemplateView -import plinth.app as app_module +import freedombox.app as app_module from freedombox.middleware import CONTENT_SECURITY_POLICY from freedombox.modules.names.components import DomainName diff --git a/freedombox/modules/kiwix/tests/test_privileged.py b/freedombox/modules/kiwix/tests/test_privileged.py index 5e2efc71b..b658a6c3b 100644 --- a/freedombox/modules/kiwix/tests/test_privileged.py +++ b/freedombox/modules/kiwix/tests/test_privileged.py @@ -9,11 +9,11 @@ from unittest.mock import patch import pytest -import plinth.settings +import freedombox.settings from freedombox.modules.kiwix import privileged pytestmark = pytest.mark.usefixtures('mock_privileged') -privileged_modules_to_mock = ['plinth.modules.kiwix.privileged'] +privileged_modules_to_mock = ['freedombox.modules.kiwix.privileged'] EMPTY_LIBRARY_CONTENTS = ''' @@ -40,10 +40,10 @@ def fixture_kiwix_home(tmp_path): @pytest.fixture(name='upload_dir') def fixture_upload_dir(tmp_path): """Overwrite the Django upload path.""" - old_value = plinth.settings.FILE_UPLOAD_TEMP_DIR - plinth.settings.FILE_UPLOAD_TEMP_DIR = tmp_path + old_value = freedombox.settings.FILE_UPLOAD_TEMP_DIR + freedombox.settings.FILE_UPLOAD_TEMP_DIR = tmp_path yield tmp_path - plinth.settings.FILE_UPLOAD_TEMP_DIR = old_value + freedombox.settings.FILE_UPLOAD_TEMP_DIR = old_value @pytest.fixture(autouse=True) diff --git a/freedombox/modules/kiwix/tests/test_views.py b/freedombox/modules/kiwix/tests/test_views.py index 8e213817c..17bd7c120 100644 --- a/freedombox/modules/kiwix/tests/test_views.py +++ b/freedombox/modules/kiwix/tests/test_views.py @@ -14,18 +14,18 @@ from django.http.response import Http404 from freedombox import module_loader from freedombox.modules.kiwix import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') ZIM_ID = 'bc4f8cdf-5626-2b13-3860-0033deddfbea' @pytest.fixture(autouse=True, scope='module') def fixture_kiwix_urls(): - """Make sure kiwix app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.kiwix') + """Make sure kiwix app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.kiwix') module_loader.include_urls() yield @@ -43,8 +43,8 @@ def make_request(request, view, **kwargs): @pytest.fixture(autouse=True) def fixture_kiwix_patch(): """Patch kiwix methods.""" - with patch( - 'plinth.modules.kiwix.privileged.list_packages') as list_libraries: + with patch('freedombox.modules.kiwix.privileged.list_packages' + ) as list_libraries: list_libraries.return_value = { ZIM_ID: { 'title': 'TestExistingPackage', @@ -75,7 +75,7 @@ def add_package_request(rf, file_path): return request -@patch('plinth.modules.kiwix.privileged.add_package') +@patch('freedombox.modules.kiwix.privileged.add_package') def test_add_package(add_package, file_path, add_package_request): """Test that adding content view works.""" response, messages = make_request(add_package_request, @@ -86,7 +86,7 @@ def test_add_package(add_package, file_path, add_package_request): add_package.assert_has_calls([call('FreedomBox.zim', file_path)]) -@patch('plinth.modules.kiwix.privileged.add_package') +@patch('freedombox.modules.kiwix.privileged.add_package') def test_add_package_failed(add_package, add_package_request): """Test that adding content package fails in case of an error.""" add_package.side_effect = RuntimeError('TestError') @@ -98,7 +98,7 @@ def test_add_package_failed(add_package, add_package_request): 'Failed to add content package.') -@patch('plinth.app.App.get') +@patch('freedombox.app.App.get') def test_delete_package_confirmation_view(_app, rf): """Test that deleting content confirmation shows correct title.""" response, _ = make_request(rf.get(''), views.delete_package, zim_id=ZIM_ID) @@ -106,8 +106,8 @@ def test_delete_package_confirmation_view(_app, rf): assert response.context_data['name'] == 'TestExistingPackage' -@patch('plinth.modules.kiwix.privileged.delete_package') -@patch('plinth.app.App.get') +@patch('freedombox.modules.kiwix.privileged.delete_package') +@patch('freedombox.app.App.get') def test_delete_package(_app, delete_package, rf): """Test that deleting a content package works.""" response, messages = make_request(rf.post(''), views.delete_package, @@ -118,7 +118,7 @@ def test_delete_package(_app, delete_package, rf): delete_package.assert_has_calls([call(ZIM_ID)]) -@patch('plinth.modules.kiwix.privileged.delete_package') +@patch('freedombox.modules.kiwix.privileged.delete_package') def test_delete_package_error(delete_package, rf): """Test that deleting content shows an error when operation fails.""" delete_package.side_effect = ValueError('TestError') diff --git a/freedombox/modules/letsencrypt/tests/test_components.py b/freedombox/modules/letsencrypt/tests/test_components.py index deeff90d0..802d0127c 100644 --- a/freedombox/modules/letsencrypt/tests/test_components.py +++ b/freedombox/modules/letsencrypt/tests/test_components.py @@ -37,7 +37,7 @@ def fixture_component(): @pytest.fixture(name='copy_certificate') def fixture_copy_certificate(): """Patch and return privileged.copy_certificate call.""" - with patch('plinth.modules.letsencrypt.privileged.copy_certificate' + with patch('freedombox.modules.letsencrypt.privileged.copy_certificate' ) as copy_certificate: yield copy_certificate @@ -45,7 +45,7 @@ def fixture_copy_certificate(): @pytest.fixture(name='compare_certificate') def fixture_compare_certificate(): """Patch and return privileged.compare_certificate call.""" - with patch('plinth.modules.letsencrypt.privileged.compare_certificate' + with patch('freedombox.modules.letsencrypt.privileged.compare_certificate' ) as compare_certificate: yield compare_certificate @@ -54,7 +54,7 @@ def fixture_compare_certificate(): def fixture_get_status(): """Return patched letsencrypt.get_status() method.""" domains = ['valid.example'] - with patch('plinth.modules.letsencrypt.get_status') as get_status: + with patch('freedombox.modules.letsencrypt.get_status') as get_status: get_status.return_value = { 'domains': { domain: { @@ -70,7 +70,7 @@ def fixture_get_status(): @pytest.fixture(name='domain_list') def fixture_domain_list(): """Return patch DomainName.list() method.""" - method = 'plinth.modules.names.components.DomainName.list' + method = 'freedombox.modules.names.components.DomainName.list' with patch(method) as domain_list: DomainType._all = {} DomainType('domain-type-1', 'type-1', 'url1', False) @@ -178,9 +178,9 @@ def _assert_restarted_daemons(component, daemons=None): daemons = daemons if daemons is not None else component.daemons expected_calls = [call(daemon) for daemon in daemons] - with patch('plinth.privileged.service.try_reload_or_restart' + with patch('freedombox.privileged.service.try_reload_or_restart' ) as try_reload_or_restart, patch( - 'plinth.privileged.service.try_restart') as try_restart: + 'freedombox.privileged.service.try_restart') as try_restart: yield if component.reload_daemons: diff --git a/freedombox/modules/letsencrypt/tests/test_domain_name_changes.py b/freedombox/modules/letsencrypt/tests/test_domain_name_changes.py index daacb0f39..c4d1ca301 100644 --- a/freedombox/modules/letsencrypt/tests/test_domain_name_changes.py +++ b/freedombox/modules/letsencrypt/tests/test_domain_name_changes.py @@ -27,8 +27,8 @@ def test_add_onion_domain(): assert not on_domain_removed('test', 'domain-type-tor', 'ddddd.onion') -@patch('plinth.modules.letsencrypt.get_status') -@patch('plinth.modules.letsencrypt.certificate_obtain') +@patch('freedombox.modules.letsencrypt.get_status') +@patch('freedombox.modules.letsencrypt.certificate_obtain') @pytest.mark.usefixtures('load_cfg') @pytest.mark.parametrize('domain,status_input,obtain,result', [ ('domain1.tld', { @@ -59,7 +59,7 @@ def test_add_valid_domain(certificate_obtain, get_status, domain, status_input, certificate_obtain.assert_not_called() -@patch('plinth.modules.letsencrypt.certificate_revoke') +@patch('freedombox.modules.letsencrypt.certificate_revoke') @pytest.mark.usefixtures('load_cfg') @pytest.mark.parametrize('domain,revoke,result', [ ('domain1.tld', True, True), diff --git a/freedombox/modules/matrixsynapse/tests/test_turn_config.py b/freedombox/modules/matrixsynapse/tests/test_turn_config.py index 5a12cdb20..70eafbf08 100644 --- a/freedombox/modules/matrixsynapse/tests/test_turn_config.py +++ b/freedombox/modules/matrixsynapse/tests/test_turn_config.py @@ -3,7 +3,7 @@ Test module for Matrix Synapse STUN/TURN configuration. """ -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch import pytest @@ -12,7 +12,7 @@ from freedombox.modules.coturn.components import TurnConfiguration from freedombox.modules.matrixsynapse import privileged pytestmark = pytest.mark.usefixtures('mock_privileged') -privileged_modules_to_mock = ['plinth.modules.matrixsynapse.privileged'] +privileged_modules_to_mock = ['freedombox.modules.matrixsynapse.privileged'] @pytest.fixture(name='managed_turn_conf_file') @@ -34,7 +34,7 @@ def fixture_set_paths(managed_turn_conf_file, overridden_turn_conf_file): """Run actions with custom root path.""" privileged.TURN_CONF_PATH = managed_turn_conf_file privileged.OVERRIDDEN_TURN_CONF_PATH = overridden_turn_conf_file - with patch('plinth.privileged.service.try_restart'): + with patch('freedombox.privileged.service.try_restart'): yield @@ -45,13 +45,14 @@ def fixture_test_configuration(managed_turn_conf_file, Overrides TURN configuration files. """ - matrixsynapse = 'plinth.modules.matrixsynapse' + matrixsynapse = 'freedombox.modules.matrixsynapse' with (patch(f'{matrixsynapse}.privileged.TURN_CONF_PATH', managed_turn_conf_file), patch(f'{matrixsynapse}.privileged.OVERRIDDEN_TURN_CONF_PATH', overridden_turn_conf_file), - patch(f'{matrixsynapse}.is_setup', return_value=True), - patch('plinth.app.App.get') as app_get): + patch(f'{matrixsynapse}.is_setup', + return_value=True), patch('freedombox.app.App.get') as + app_get): app = Mock() app_get.return_value = app app.needs_setup.return_value = False @@ -72,13 +73,12 @@ updated_coturn_configuration = TurnConfiguration( def _set_managed_configuration(config=coturn_configuration): - with patch('plinth.action_utils.service_try_restart'): + with patch('freedombox.action_utils.service_try_restart'): matrixsynapse.update_turn_configuration(config) -def _set_overridden_configuration( - config=overridden_configuration): - with patch('plinth.action_utils.service_try_restart'): +def _set_overridden_configuration(config=overridden_configuration): + with patch('freedombox.action_utils.service_try_restart'): matrixsynapse.update_turn_configuration(config, managed=False) diff --git a/freedombox/modules/mediawiki/tests/test_settings.py b/freedombox/modules/mediawiki/tests/test_settings.py index 68c4cb5bb..198062023 100644 --- a/freedombox/modules/mediawiki/tests/test_settings.py +++ b/freedombox/modules/mediawiki/tests/test_settings.py @@ -13,7 +13,7 @@ from freedombox.modules.mediawiki import privileged pytestmark = pytest.mark.usefixtures('mock_privileged') current_directory = pathlib.Path(__file__).parent -privileged_modules_to_mock = ['plinth.modules.mediawiki.privileged'] +privileged_modules_to_mock = ['freedombox.modules.mediawiki.privileged'] @pytest.fixture(name='test_configuration', autouse=True) @@ -25,8 +25,9 @@ def fixture_test_configuration(tmp_path): settings_file_name = 'FreedomBoxSettings.php' conf_file = tmp_path / settings_file_name conf_file.touch() - with (patch('plinth.modules.mediawiki.USER_CONFIG_FILE', conf_file), - patch('plinth.modules.mediawiki.privileged.CONF_FILE', conf_file)): + with (patch('freedombox.modules.mediawiki.USER_CONFIG_FILE', conf_file), + patch('freedombox.modules.mediawiki.privileged.CONF_FILE', + conf_file)): yield diff --git a/freedombox/modules/miniflux/tests/test_views.py b/freedombox/modules/miniflux/tests/test_views.py index 833750a5d..6419aac25 100644 --- a/freedombox/modules/miniflux/tests/test_views.py +++ b/freedombox/modules/miniflux/tests/test_views.py @@ -10,16 +10,16 @@ from django.contrib.messages.storage.fallback import FallbackStorage from freedombox import module_loader from freedombox.modules.miniflux import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') @pytest.fixture(autouse=True, scope='module') def fixture_miniflux_urls(): - """Make sure Miniflux app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.miniflux') + """Make sure Miniflux app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.miniflux') module_loader.include_urls() yield @@ -48,7 +48,7 @@ def test_create_admin_user_view(rf): assert response.status_code == 200 -@patch('plinth.modules.miniflux.privileged.create_admin_user') +@patch('freedombox.modules.miniflux.privileged.create_admin_user') def test_create_admin_user_form_valid(create_admin_user, rf): """Test that the create admin user form is valid and redirects.""" form_data = { @@ -99,7 +99,7 @@ def test_password_too_short(rf): 0] == 'Ensure this value has at least 6 characters (it has 4).' -@patch('plinth.modules.miniflux.privileged.create_admin_user') +@patch('freedombox.modules.miniflux.privileged.create_admin_user') def test_recreate_existing_user(create_admin_user, rf): """Test that trying to recreate an existing user fails.""" create_admin_user.side_effect = Exception( @@ -126,7 +126,7 @@ def test_recreate_existing_user(create_admin_user, rf): ############################ -@patch('plinth.modules.miniflux.privileged.reset_user_password') +@patch('freedombox.modules.miniflux.privileged.reset_user_password') def test_reset_user_password_form_valid(reset_user_password, rf): """Test that the reset user password form is valid and redirects.""" reset_user_password.return_value = 'Password changed!' @@ -145,7 +145,7 @@ def test_reset_user_password_form_valid(reset_user_password, rf): assert list(messages)[0].message == 'Password reset for user: admin' -@patch('plinth.modules.miniflux.privileged.reset_user_password') +@patch('freedombox.modules.miniflux.privileged.reset_user_password') def test_reset_user_password_for_invalid_user(reset_user_password, rf): """Test that the resetting user password for an invalid user fails.""" reset_user_password.side_effect = Exception('user not found') diff --git a/freedombox/modules/oidc/tests/test_components.py b/freedombox/modules/oidc/tests/test_components.py index 4c8349a3b..390fc05e4 100644 --- a/freedombox/modules/oidc/tests/test_components.py +++ b/freedombox/modules/oidc/tests/test_components.py @@ -50,7 +50,7 @@ def test_get_client_secret(openid_connect): @pytest.mark.django_db -@patch('plinth.modules.names.components.DomainName.list_names') +@patch('freedombox.modules.names.components.DomainName.list_names') def test_setup(list_names, openid_connect): """Test creating a DB object.""" list_names.return_value = ('a.example', 'b.example') diff --git a/freedombox/modules/privacy/views.py b/freedombox/modules/privacy/views.py index a33d16126..4dca6d096 100644 --- a/freedombox/modules/privacy/views.py +++ b/freedombox/modules/privacy/views.py @@ -4,7 +4,7 @@ from django.contrib import messages from django.utils.translation import gettext as _ -import plinth.modules.names.privileged as names_privileged +import freedombox.modules.names.privileged as names_privileged from freedombox.modules import names, privacy from freedombox.modules.privacy.forms import PrivacyForm from freedombox.views import AppView diff --git a/freedombox/modules/samba/tests/test_views.py b/freedombox/modules/samba/tests/test_views.py index 93514f26d..2b45ab448 100644 --- a/freedombox/modules/samba/tests/test_views.py +++ b/freedombox/modules/samba/tests/test_views.py @@ -14,8 +14,8 @@ from django.contrib.messages.storage.fallback import FallbackStorage from freedombox import module_loader from freedombox.modules.samba import views -# For all tests, use plinth.urls instead of urls configured for testing -pytestmark = pytest.mark.urls('plinth.urls') +# For all tests, use freedombox.urls instead of urls configured for testing +pytestmark = pytest.mark.urls('freedombox.urls') setfacl_path = pathlib.Path('/usr/bin/setfacl') USERS = {"access_ok": ["testuser"], 'password_re_enter_needed': []} @@ -62,10 +62,10 @@ SHARES = [ @pytest.fixture(autouse=True, scope='module') def fixture_samba_urls(): - """Make sure samba app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.samba') + """Make sure samba app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.samba') module_loader.include_urls() yield @@ -73,9 +73,10 @@ def fixture_samba_urls(): @pytest.fixture(autouse=True) def samba_patch_privileged(): """Patch privileged scripts runner.""" - with patch('plinth.modules.samba.privileged.get_shares') as get_shares, \ - patch('plinth.modules.samba.privileged.delete_share'), \ - patch('plinth.modules.samba.privileged.add_share'): + with (patch('freedombox.modules.samba.privileged.get_shares') + as get_shares, + patch('freedombox.modules.samba.privileged.delete_share'), + patch('freedombox.modules.samba.privileged.add_share')): get_shares.return_value = SHARES yield @@ -92,11 +93,11 @@ def make_request(request, view, **kwargs): def test_samba_shares_view(rf): """Test that a share list has correct view data.""" - with (patch('plinth.views.AppView.get_context_data', + with (patch('freedombox.views.AppView.get_context_data', return_value={'is_enabled': True}), - patch('plinth.modules.samba.get_users', return_value=USERS), - patch('plinth.modules.storage.get_mounts', return_value=DISKS), - patch('plinth.views.AppView.app', return_value=None)): + patch('freedombox.modules.samba.get_users', return_value=USERS), + patch('freedombox.modules.storage.get_mounts', return_value=DISKS), + patch('freedombox.views.AppView.app', return_value=None)): view = views.SambaAppView.as_view() response, _ = make_request(rf.get(''), view) @@ -133,7 +134,7 @@ def test_enable_samba_share_failed_view(rf): form_data = {'filesystem_type': 'ext4', 'open_share': 'enable'} mount_point = urllib.parse.quote('/') error_message = 'Sharing failed' - with patch('plinth.modules.samba.add_share', + with patch('freedombox.modules.samba.add_share', side_effect=RuntimeError(error_message)): response, messages = make_request(rf.post('', data=form_data), views.share, mount_point=mount_point) @@ -161,7 +162,7 @@ def test_disable_samba_share_failed_view(rf): form_data = {'filesystem_type': 'ext4', 'open_share': 'disable'} mount_point = urllib.parse.quote('/') error_message = 'Unsharing failed' - with patch('plinth.modules.samba.privileged.delete_share', + with patch('freedombox.modules.samba.privileged.delete_share', side_effect=RuntimeError(error_message)): response, messages = make_request(rf.post('', data=form_data), views.share, mount_point=mount_point) diff --git a/freedombox/modules/storage/tests/test_storage.py b/freedombox/modules/storage/tests/test_storage.py index ae1f5d56d..07b91ac0f 100644 --- a/freedombox/modules/storage/tests/test_storage.py +++ b/freedombox/modules/storage/tests/test_storage.py @@ -32,7 +32,7 @@ def _is_container(): pytestmark = pytest.mark.usefixtures('mock_privileged', 'mock_run_as_user') -privileged_modules_to_mock = ['plinth.modules.storage.privileged'] +privileged_modules_to_mock = ['freedombox.modules.storage.privileged'] skip_if_container = pytest.mark.skipif(_is_container(), reason='running inside a container') diff --git a/freedombox/modules/tor/tests/test_tor.py b/freedombox/modules/tor/tests/test_tor.py index 5ee595f43..f1467ec09 100644 --- a/freedombox/modules/tor/tests/test_tor.py +++ b/freedombox/modules/tor/tests/test_tor.py @@ -11,7 +11,7 @@ from django.core.exceptions import ValidationError from freedombox.modules.tor import forms, utils -@patch('plinth.app.App.get') +@patch('freedombox.app.App.get') @pytest.mark.usefixtures('needs_root', 'load_cfg') def test_get_status(_app_get): """Test that get_status does not raise any unhandled exceptions. diff --git a/freedombox/modules/torproxy/tests/test_torproxy.py b/freedombox/modules/torproxy/tests/test_torproxy.py index 0c9e42947..4e68b0bae 100644 --- a/freedombox/modules/torproxy/tests/test_torproxy.py +++ b/freedombox/modules/torproxy/tests/test_torproxy.py @@ -22,7 +22,7 @@ class TestTorProxy: utils.is_apt_transport_tor_enabled() @staticmethod - @patch('plinth.app.App.get') + @patch('freedombox.app.App.get') @pytest.mark.usefixtures('needs_root', 'load_cfg') def test_get_status(_app_get): """Test that get_status does not raise any unhandled exceptions. diff --git a/freedombox/modules/upgrades/__init__.py b/freedombox/modules/upgrades/__init__.py index d15be4268..34a00d812 100644 --- a/freedombox/modules/upgrades/__init__.py +++ b/freedombox/modules/upgrades/__init__.py @@ -10,7 +10,7 @@ from aptsources import sourceslist from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_noop -import plinth +import freedombox from freedombox import action_utils from freedombox import app as app_module from freedombox import cfg, glib, kvstore, menu, package @@ -111,7 +111,7 @@ class UpgradesApp(app_module.App): from freedombox.notification import Notification try: note = Notification.get('upgrades-new-release') - if note.data['version'] == plinth.__version__: + if note.data['version'] == freedombox.__version__: # User already has notification for update to this version. It # may be dismissed or not yet dismissed return @@ -124,7 +124,7 @@ class UpgradesApp(app_module.App): dismiss = True data = { - 'version': plinth.__version__, + 'version': freedombox.__version__, 'app_name': 'translate:' + gettext_noop('Software Update'), 'app_icon': 'fa-refresh' } diff --git a/freedombox/modules/upgrades/tests/test_distupgrade.py b/freedombox/modules/upgrades/tests/test_distupgrade.py index 0c4c74437..db6bebc67 100644 --- a/freedombox/modules/upgrades/tests/test_distupgrade.py +++ b/freedombox/modules/upgrades/tests/test_distupgrade.py @@ -65,7 +65,7 @@ deb https://deb.debian.org/debian bookwormish main sources_list = tmp_path / 'sources.list' temp_sources_list = tmp_path / 'sources.list.fbx-dist-upgrade' - module = 'plinth.modules.upgrades.distupgrade' + module = 'freedombox.modules.upgrades.distupgrade' with patch(f'{module}.sources_list', sources_list), \ patch(f'{module}.temp_sources_list', temp_sources_list): sources_list.write_text(original) @@ -81,12 +81,13 @@ deb https://deb.debian.org/debian bookwormish main @patch('datetime.datetime') -@patch('plinth.modules.upgrades.utils.get_current_release') -@patch('plinth.modules.upgrades.distupgrade.utils.get_sources_list_codename') -@patch('plinth.action_utils.service_is_running') -@patch('plinth.modules.upgrades.utils.is_sufficient_free_space') -@patch('plinth.modules.upgrades.is_dist_upgrade_enabled') -@patch('plinth.modules.upgrades.utils.check_auto') +@patch('freedombox.modules.upgrades.utils.get_current_release') +@patch( + 'freedombox.modules.upgrades.distupgrade.utils.get_sources_list_codename') +@patch('freedombox.action_utils.service_is_running') +@patch('freedombox.modules.upgrades.utils.is_sufficient_free_space') +@patch('freedombox.modules.upgrades.is_dist_upgrade_enabled') +@patch('freedombox.modules.upgrades.utils.check_auto') def test_get_status(check_auto, is_dist_upgrade_enabled, is_sufficient_free_space, service_is_running, get_sources_list_codename, get_current_release, datetime): @@ -204,8 +205,8 @@ def test_get_status(check_auto, is_dist_upgrade_enabled, @patch('subprocess.run') -@patch('plinth.modules.snapshot.is_apt_snapshots_enabled') -@patch('plinth.modules.snapshot.is_supported') +@patch('freedombox.modules.snapshot.is_apt_snapshots_enabled') +@patch('freedombox.modules.snapshot.is_supported') def test_snapshot_run_and_disable(is_supported, is_apt_snapshots_enabled, run): """Test taking a snapshot.""" is_supported.return_value = False @@ -245,9 +246,9 @@ def test_snapshot_run_and_disable(is_supported, is_apt_snapshots_enabled, run): ] -@patch('plinth.action_utils.service_enable') -@patch('plinth.action_utils.service_disable') -@patch('plinth.action_utils.service_is_running') +@patch('freedombox.action_utils.service_enable') +@patch('freedombox.action_utils.service_disable') +@patch('freedombox.action_utils.service_is_running') def test_services_disable(service_is_running, service_disable, service_enable): """Test that disabling services works.""" service_is_running.return_value = False @@ -275,8 +276,8 @@ def test_apt_hold_packages(run, tmp_path): hold_flag = tmp_path / 'flag' run.side_effect = _run - with patch('plinth.action_utils.apt_hold_flag', hold_flag), \ - patch('plinth.modules.upgrades.distupgrade.PACKAGES_WITH_PROMPTS', + with patch('freedombox.action_utils.apt_hold_flag', hold_flag), \ + patch('freedombox.modules.upgrades.distupgrade.PACKAGES_WITH_PROMPTS', ['package1', 'package2']): with distupgrade._apt_hold_packages(): assert hold_flag.exists() @@ -311,10 +312,11 @@ def test_apt_hold_packages(run, tmp_path): assert run.call_args_list == expected_call -@patch('plinth.action_utils.debconf_set_selections') +@patch('freedombox.action_utils.debconf_set_selections') def test_debconf_set_selections(debconf_set_selections): """Test that setting debconf selections works.""" - selections = 'plinth.modules.upgrades.distupgrade.PRE_DEBCONF_SELECTIONS' + selections = ('freedombox.modules.upgrades.distupgrade.' + 'PRE_DEBCONF_SELECTIONS') with patch(selections, []): distupgrade._debconf_set_selections() debconf_set_selections.assert_not_called() @@ -328,26 +330,26 @@ def test_debconf_set_selections(debconf_set_selections): ['grub-pc grub-pc/install_devices_empty boolean true']) -@patch('plinth.modules.upgrades.distupgrade._apt_run') +@patch('freedombox.modules.upgrades.distupgrade._apt_run') def test_packages_remove_obsolete(apt_run): """Test that obsolete packages are removed.""" distupgrade._packages_remove_obsolete() apt_run.assert_not_called() # No obsolete package to remove currently. - with patch('plinth.modules.upgrades.distupgrade.OBSOLETE_PACKAGES', + with patch('freedombox.modules.upgrades.distupgrade.OBSOLETE_PACKAGES', ['searx']): distupgrade._packages_remove_obsolete() apt_run.assert_called_with(['remove', 'searx']) -@patch('plinth.modules.upgrades.distupgrade._apt_run') +@patch('freedombox.modules.upgrades.distupgrade._apt_run') def test_apt_update(apt_run): """Test that apt update works.""" distupgrade._apt_update() apt_run.assert_called_with(['update']) -@patch('plinth.modules.upgrades.distupgrade._apt_run') +@patch('freedombox.modules.upgrades.distupgrade._apt_run') @patch('subprocess.run') def test_apt_fix(run, apt_run): """Test that apt fixes work.""" @@ -359,14 +361,14 @@ def test_apt_fix(run, apt_run): assert apt_run.call_args_list == [call(['--fix-broken', 'install'])] -@patch('plinth.modules.upgrades.distupgrade._apt_run') +@patch('freedombox.modules.upgrades.distupgrade._apt_run') def test_apt_autoremove(apt_run): """Test that apt autoremove works.""" distupgrade._apt_autoremove() apt_run.assert_called_with(['autoremove']) -@patch('plinth.modules.upgrades.distupgrade._apt_run') +@patch('freedombox.modules.upgrades.distupgrade._apt_run') def test_apt_full_upgrade(apt_run): """Test that apt full upgrade works.""" apt_run.return_value = 0 @@ -384,7 +386,7 @@ def test_unatteneded_upgrades_run(run): check=False) -@patch('plinth.action_utils.service_restart') +@patch('freedombox.action_utils.service_restart') def test_freedombox_restart(service_restart): """Test that restarting freedombox service works.""" distupgrade._freedombox_restart() @@ -410,7 +412,7 @@ def test_on_complete(tmp_path): temp_sources_list = tmp_path / 'sources.list.fbx-dist-upgrade' temp_sources_list.write_text('after') - module = 'plinth.modules.upgrades.distupgrade' + module = 'freedombox.modules.upgrades.distupgrade' with patch(f'{module}.sources_list', sources_list), \ patch(f'{module}.temp_sources_list', temp_sources_list): distupgrade.on_complete() diff --git a/freedombox/modules/upgrades/tests/test_utils.py b/freedombox/modules/upgrades/tests/test_utils.py index abd98bc84..4a78c84ec 100644 --- a/freedombox/modules/upgrades/tests/test_utils.py +++ b/freedombox/modules/upgrades/tests/test_utils.py @@ -46,7 +46,7 @@ deb http://deb.debian.org/debian trixie main ''' sources_list = tmp_path / 'sources.list' - module = 'plinth.modules.upgrades.utils' + module = 'freedombox.modules.upgrades.utils' with patch(f'{module}.sources_list', sources_list): sources_list.write_text(list1) assert utils.get_sources_list_codename() == 'bookworm' @@ -71,7 +71,7 @@ def test_get_current_release(run): assert utils.get_current_release() == ('test-release', 'test-codename') -@patch('plinth.modules.upgrades.utils.get_sources_list_codename') +@patch('freedombox.modules.upgrades.utils.get_sources_list_codename') def test_is_distribution_unstable(get_sources_list_codename): """Test that checking for unstable distribution works.""" get_sources_list_codename.return_value = 'unstable' @@ -84,7 +84,7 @@ def test_is_distribution_unstable(get_sources_list_codename): assert not utils.is_distribution_unstable() -@patch('plinth.modules.upgrades.utils.get_current_release') +@patch('freedombox.modules.upgrades.utils.get_current_release') def test_is_distribution_rolling(get_current_release): """Test that checking for testing/unstable distribution works.""" for value in ['unstable', 'testing', 'n/a']: diff --git a/freedombox/modules/users/forms.py b/freedombox/modules/users/forms.py index f33cef58f..c7524daf2 100644 --- a/freedombox/modules/users/forms.py +++ b/freedombox/modules/users/forms.py @@ -18,8 +18,8 @@ from django.utils.deconstruct import deconstructible from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy -import plinth.forms -import plinth.modules.ssh.privileged as ssh_privileged +import freedombox.forms +import freedombox.modules.ssh.privileged as ssh_privileged from freedombox.modules import first_boot from freedombox.utils import is_user_admin from freedombox.views import messages_error @@ -181,7 +181,8 @@ class PasswordConfirmForm(forms.Form): class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin, - GroupsFieldMixin, plinth.forms.LanguageSelectionFormMixin, + GroupsFieldMixin, + freedombox.forms.LanguageSelectionFormMixin, PasswordConfirmForm, UserCreationForm): """Custom user create form. @@ -190,7 +191,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin, username = USERNAME_FIELD - language = plinth.forms.LanguageSelectionFormMixin.language + language = freedombox.forms.LanguageSelectionFormMixin.language class Meta(UserCreationForm.Meta): """Metadata to control automatic form building.""" @@ -198,7 +199,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin, fields = ('username', 'email', 'password1', 'password2', 'groups', 'language', 'confirm_password') widgets = { - 'groups': plinth.forms.CheckboxSelectMultiple(), + 'groups': freedombox.forms.CheckboxSelectMultiple(), } def __init__(self, request, *args, **kwargs): @@ -254,7 +255,8 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin, class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm, EmailFieldMixin, GroupsFieldMixin, - plinth.forms.LanguageSelectionFormMixin, forms.ModelForm): + freedombox.forms.LanguageSelectionFormMixin, + forms.ModelForm): """When user info is changed, also updates LDAP user.""" username = USERNAME_FIELD @@ -267,7 +269,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm, 'line. Blank lines and lines starting with # will be ' 'ignored.')) - language = plinth.forms.LanguageSelectionFormMixin.language + language = freedombox.forms.LanguageSelectionFormMixin.language delete = forms.BooleanField( label=gettext_lazy('Delete user'), required=False, @@ -283,7 +285,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm, 'is_active', 'delete', 'confirm_password') model = User widgets = { - 'groups': plinth.forms.CheckboxSelectMultipleWithReadOnly(), + 'groups': freedombox.forms.CheckboxSelectMultipleWithReadOnly(), } def __init__(self, request, username, *args, **kwargs): diff --git a/freedombox/modules/users/tests/test_privileged.py b/freedombox/modules/users/tests/test_privileged.py index 879727b76..4cbfb7048 100644 --- a/freedombox/modules/users/tests/test_privileged.py +++ b/freedombox/modules/users/tests/test_privileged.py @@ -39,7 +39,8 @@ pytestmark: list[pytest.MarkDecorator] = [ pytest.mark.skipif(not _is_ldap_set_up(), reason='LDAP is not configured') ] privileged_modules_to_mock = [ - 'plinth.modules.users.privileged', 'plinth.modules.security.privileged' + 'freedombox.modules.users.privileged', + 'freedombox.modules.security.privileged' ] diff --git a/freedombox/modules/users/tests/test_views.py b/freedombox/modules/users/tests/test_views.py index d5d395f70..37e39117b 100644 --- a/freedombox/modules/users/tests/test_views.py +++ b/freedombox/modules/users/tests/test_views.py @@ -16,17 +16,17 @@ from freedombox.modules.users import views from ..components import UsersAndGroups -# For all tests, plinth.urls instead of urls configured for testing, and +# For all tests, freedombox.urls instead of urls configured for testing, and # django database -pytestmark = [pytest.mark.urls('plinth.urls'), pytest.mark.django_db] +pytestmark = [pytest.mark.urls('freedombox.urls'), pytest.mark.django_db] @pytest.fixture(autouse=True, scope='module') def fixture_users_urls(): - """Make sure users app's URLs are part of plinth.urls.""" - with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \ - patch('plinth.urls.urlpatterns', new=[]): - modules.append('plinth.modules.users') + """Make sure users app's URLs are part of freedombox.urls.""" + with (patch('freedombox.module_loader._modules_to_load', new=[]) as + modules, patch('freedombox.urls.urlpatterns', new=[])): + modules.append('freedombox.modules.users') module_loader.include_urls() yield @@ -42,7 +42,7 @@ def module_patch(): UsersAndGroups('users-and-groups-minetest', reserved_usernames=['debian-minetest']) - privileged = 'plinth.modules.users.privileged' + privileged = 'freedombox.modules.users.privileged' with patch('pwd.getpwall', return_value=pwd_users), \ patch(f'{privileged}.create_user'), \ patch(f'{privileged}.add_user_to_group'), \ @@ -50,8 +50,8 @@ def module_patch(): patch(f'{privileged}.set_user_status'), \ patch(f'{privileged}.rename_user'), \ patch(f'{privileged}.get_group_users') as get_group_users, \ - patch('plinth.modules.ssh.privileged.set_keys'), \ - patch('plinth.modules.ssh.privileged.get_keys') as get_keys, \ + patch('freedombox.modules.ssh.privileged.set_keys'), \ + patch('freedombox.modules.ssh.privileged.get_keys') as get_keys, \ patch(f'{privileged}.get_user_groups') as get_user_groups, \ patch(f'{privileged}.remove_user'): get_group_users.return_value = ['admin'] @@ -72,11 +72,11 @@ def make_request(request, view, as_admin=True, **kwargs): request.user = admin_user if as_admin else user - with patch('plinth.modules.users.forms.is_user_admin', + with patch('freedombox.modules.users.forms.is_user_admin', return_value=as_admin), \ - patch('plinth.modules.users.views.is_user_admin', + patch('freedombox.modules.users.views.is_user_admin', return_value=as_admin), \ - patch('plinth.modules.users.views.update_session_auth_hash'): + patch('freedombox.modules.users.views.update_session_auth_hash'): response = view(request, **kwargs) @@ -85,9 +85,9 @@ def make_request(request, view, as_admin=True, **kwargs): def test_users_list_view(rf): """Test users list view has correct view data.""" - with (patch('plinth.views.AppView.get_context_data', + with (patch('freedombox.views.AppView.get_context_data', return_value={'is_enabled': True}), - patch('plinth.views.AppView.app', return_value=None)): + patch('freedombox.views.AppView.app', return_value=None)): view = views.UserList.as_view() response, messages = make_request(rf.get('/'), view) diff --git a/freedombox/modules/users/views.py b/freedombox/modules/users/views.py index 46c44eb20..2ce93e5a1 100644 --- a/freedombox/modules/users/views.py +++ b/freedombox/modules/users/views.py @@ -35,7 +35,7 @@ from fido2 import webauthn from fido2.server import Fido2Server from fido2.webauthn import AttestedCredentialData, AuthenticationResponse -import plinth.modules.ssh.privileged as ssh_privileged +import freedombox.modules.ssh.privileged as ssh_privileged from freedombox import translation from freedombox.models import UserPasskey from freedombox.modules import first_boot diff --git a/freedombox/package.py b/freedombox/package.py index 523a88a0c..33582f27f 100644 --- a/freedombox/package.py +++ b/freedombox/package.py @@ -11,10 +11,10 @@ import apt.cache from django.utils.translation import gettext as _ from django.utils.translation import gettext_lazy, gettext_noop -import plinth.privileged.packages as privileged +import freedombox.privileged.packages as privileged from freedombox import app as app_module from freedombox.diagnostic_check import (DiagnosticCheck, - DiagnosticCheckParameters, Result) + DiagnosticCheckParameters, Result) from freedombox.errors import MissingPackageError from freedombox.utils import format_lazy diff --git a/freedombox/setup.py b/freedombox/setup.py index 93e935d4d..91051b734 100644 --- a/freedombox/setup.py +++ b/freedombox/setup.py @@ -13,7 +13,7 @@ from typing import Union import apt from django.utils.translation import gettext_noop -import plinth +import freedombox from freedombox import app as app_module from freedombox.diagnostic_check import Result from freedombox.errors import MissingPackageError @@ -443,7 +443,7 @@ class ForceUpgrader(): def __init__(self): """Initialize the force upgrader.""" - if plinth.cfg.develop: + if freedombox.cfg.develop: self.UPGRADE_ATTEMPT_WAIT_SECONDS = 10 def on_package_cache_updated(self): @@ -724,7 +724,7 @@ class DpkgHandler: def __init__(self) -> None: """Initialize the dpkg handler.""" - if plinth.cfg.develop: + if freedombox.cfg.develop: self.HANDLE_ATTEMPT_WAIT_SECONDS = 10 def on_dpkg_invoked(self) -> None: diff --git a/freedombox/tests/conftest.py b/freedombox/tests/conftest.py index 07b9950a9..f02a17943 100644 --- a/freedombox/tests/conftest.py +++ b/freedombox/tests/conftest.py @@ -13,7 +13,7 @@ from freedombox import cfg @pytest.fixture(name='shortcuts_file') def fixture_shortcuts_file(): - with patch('plinth.frontpage.get_custom_shortcuts_paths') as func: + with patch('freedombox.frontpage.get_custom_shortcuts_paths') as func: def setter(file_name): path = pathlib.Path(__file__).parent / 'data' / 'shortcuts' diff --git a/freedombox/tests/functional/enable-all-apps b/freedombox/tests/functional/enable-all-apps index f80e82d1b..9159f8104 100755 --- a/freedombox/tests/functional/enable-all-apps +++ b/freedombox/tests/functional/enable-all-apps @@ -7,8 +7,9 @@ from splinter import Browser -from plinth import app as app_module, module_loader -from plinth.tests.functional import app_enable, install, login +from freedombox import app as app_module +from freedombox import module_loader +from freedombox.tests.functional import app_enable, install, login module_loader.load_modules() app_module.apps_init() diff --git a/freedombox/tests/test_action_utils.py b/freedombox/tests/test_action_utils.py index fba2b43c8..cac09e9c3 100644 --- a/freedombox/tests/test_action_utils.py +++ b/freedombox/tests/test_action_utils.py @@ -12,13 +12,15 @@ from unittest.mock import Mock, call, patch import pytest from freedombox.action_utils import (get_addresses, get_hostname, - is_systemd_running, move_uploaded_file, run, - run_as_user, service_action, service_disable, - service_enable, service_is_enabled, - service_is_running, service_reload, - service_restart, service_start, service_stop, - service_try_reload_or_restart, - service_try_restart, service_unmask, umask) + is_systemd_running, move_uploaded_file, + run, run_as_user, service_action, + service_disable, service_enable, + service_is_enabled, service_is_running, + service_reload, service_restart, + service_start, service_stop, + service_try_reload_or_restart, + service_try_restart, service_unmask, + umask) UNKNOWN = 'unknowndeamon.service' UNKNOWN_SOCKET = 'unknowndeamon.socket' @@ -75,7 +77,7 @@ def test_service_enable_and_disable(): service_enable(UNKNOWN) -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_start(mock): """Test staring a service.""" @@ -87,7 +89,7 @@ def test_service_start(mock): mock.mock_calls = [call(UNKNOWN, 'start', check=True)] -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_stop(mock): """Test stopping a service.""" @@ -106,7 +108,7 @@ def test_service_stop(mock): ] -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_restart(mock): """Test restaring a service.""" @@ -122,7 +124,7 @@ def test_service_restart(mock): assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)] -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_try_restart(mock): """Test try-restaring a service.""" @@ -138,7 +140,7 @@ def test_service_try_restart(mock): assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)] -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_reload(mock): """Test reloading a service.""" @@ -154,7 +156,7 @@ def test_service_reload(mock): assert mock.mock_calls == [call(UNKNOWN, 'reload', check=False)] -@patch('plinth.action_utils.service_action') +@patch('freedombox.action_utils.service_action') @systemd_installed def test_service_try_reload_or_restart(mock): """Test try-reload-or-restart on a service.""" @@ -231,11 +233,11 @@ def fixture_update_dir(tmp_path): tmp_path /= 'source' tmp_path.mkdir() - import plinth.settings - old_value = plinth.settings.FILE_UPLOAD_TEMP_DIR - plinth.settings.FILE_UPLOAD_TEMP_DIR = tmp_path + import freedombox.settings + old_value = freedombox.settings.FILE_UPLOAD_TEMP_DIR + freedombox.settings.FILE_UPLOAD_TEMP_DIR = tmp_path yield tmp_path - plinth.settings.FILE_UPLOAD_TEMP_DIR = old_value + freedombox.settings.FILE_UPLOAD_TEMP_DIR = old_value def test_move_uploaded_file(tmp_path, upload_dir): @@ -329,7 +331,7 @@ def test_run_as_user(subprocess_run): ] -@patch('plinth.actions.thread_storage') +@patch('freedombox.actions.thread_storage') @patch('subprocess.run') def test_run_capture(subprocess_run, thread_storage): """Test running a command with stdin/stdout capture works.""" @@ -350,7 +352,7 @@ def test_run_capture(subprocess_run, thread_storage): assert thread_storage.stderr == 'initial-stderrtest-stderr' -@patch('plinth.actions.thread_storage') +@patch('freedombox.actions.thread_storage') @patch('subprocess.run') def test_run_no_capture(subprocess_run, thread_storage): """Test running a command without stdin/stdout capture works.""" @@ -372,7 +374,7 @@ def test_run_no_capture(subprocess_run, thread_storage): assert thread_storage.stderr == 'initial-stderr' -@patch('plinth.actions.thread_storage', None) +@patch('freedombox.actions.thread_storage', None) @patch('subprocess.run') def test_run_no_storage(subprocess_run): """Test running a command without thread storage.""" diff --git a/freedombox/tests/test_actions.py b/freedombox/tests/test_actions.py index 3c0c756ee..38de4d580 100644 --- a/freedombox/tests/test_actions.py +++ b/freedombox/tests/test_actions.py @@ -100,9 +100,9 @@ def test_privileged_argument_annotation_check(): privileged(func2_valid) -@patch('plinth.actions._read_from_server') -@patch('plinth.actions._request_to_server') -@patch('plinth.actions._get_privileged_action_module_name') +@patch('freedombox.actions._read_from_server') +@patch('freedombox.actions._request_to_server') +@patch('freedombox.actions._get_privileged_action_module_name') def test_privileged_method_call(get_module_name, request_to_server, read_from_server): """Test that privileged method calls the superuser action properly.""" @@ -129,9 +129,9 @@ def test_privileged_method_call(get_module_name, request_to_server, ] -@patch('plinth.actions._read_from_server') -@patch('plinth.actions._request_to_server') -@patch('plinth.actions._get_privileged_action_module_name') +@patch('freedombox.actions._read_from_server') +@patch('freedombox.actions._request_to_server') +@patch('freedombox.actions._get_privileged_action_module_name') def test_privileged_method_exceptions(get_module_name, request_to_server, read_from_server): """Test that exceptions on privileged methods are return properly.""" @@ -157,7 +157,7 @@ def test_privileged_method_exceptions(get_module_name, request_to_server, @patch('importlib.import_module') -@patch('plinth.module_loader.get_module_import_path') +@patch('freedombox.module_loader.get_module_import_path') @patch('os.getuid') def test_call_syntax_checks(getuid, get_module_import_path, import_module): """Test that calling a method results in proper syntax checks.""" @@ -169,13 +169,13 @@ def test_call_syntax_checks(getuid, get_module_import_path, import_module): privileged_call('foo.bar', 'x-action', {}) # Module import test - get_module_import_path.return_value = 'plinth.modules.test_module' + get_module_import_path.return_value = 'freedombox.modules.test_module' import_module.side_effect = ModuleNotFoundError with pytest.raises(SyntaxError, match='Specified module not found'): privileged_call('test_module', 'x-action', {}) import_module.assert_has_calls( - [call('plinth.modules.test_module.privileged')]) + [call('freedombox.modules.test_module.privileged')]) # Finding action in a module module = type('', (), {}) diff --git a/freedombox/tests/test_app.py b/freedombox/tests/test_app.py index b6469a705..6cf241791 100644 --- a/freedombox/tests/test_app.py +++ b/freedombox/tests/test_app.py @@ -9,13 +9,13 @@ from unittest.mock import Mock, call, patch import pytest from freedombox import log -from freedombox.app import (App, Component, EnableState, FollowerComponent, Info, - LeaderComponent, apps_init) +from freedombox.app import (App, Component, EnableState, FollowerComponent, + Info, LeaderComponent, apps_init) from freedombox.diagnostic_check import DiagnosticCheck, Result # pylint: disable=protected-access -privileged_modules_to_mock = ['plinth.privileged'] +privileged_modules_to_mock = ['freedombox.privileged'] class AppTest(App): @@ -300,7 +300,7 @@ def test_app_has_diagnostics(app_with_components): assert app.has_diagnostics() -@patch('plinth.setup.run_setup_on_app') +@patch('freedombox.setup.run_setup_on_app') def test_app_repair(_run_setup_on_app, app_with_components): """Test running repair on an app.""" component = app_with_components.get_component('test-follower-1') @@ -345,9 +345,9 @@ def test_app_has_logs(app_with_components): assert not app.has_diagnostics() -@patch('plinth.privileged.service._assert_service_is_managed_by_plinth') -@patch('plinth.action_utils.service_get_logs') -@patch('plinth.action_utils.service_show') +@patch('freedombox.privileged.service._assert_service_is_managed_by_plinth') +@patch('freedombox.action_utils.service_get_logs') +@patch('freedombox.action_utils.service_show') def test_app_get_logs(service_show, service_get_logs, _, app_with_components, mock_privileged): """Test retrieving logs from an app.""" @@ -443,7 +443,7 @@ def test_component_has_diagnostics(): assert not component.has_diagnostics() -@patch('plinth.setup.run_setup_on_app') +@patch('freedombox.setup.run_setup_on_app') def test_component_repair(_run_setup_on_app): """Test running repair on component.""" component = Component('test-component') @@ -608,7 +608,7 @@ class ModuleTest2: self.add(Info('app3', version=1)) -@patch('plinth.module_loader.loaded_modules') +@patch('freedombox.module_loader.loaded_modules') def test_apps_init(loaded_modules): """Test that initializing all apps works.""" loaded_modules.items.return_value = [('test1', ModuleTest1()), @@ -646,7 +646,7 @@ class ModuleCircularTest: self.add(Info('app3', version=1)) -@patch('plinth.module_loader.loaded_modules') +@patch('freedombox.module_loader.loaded_modules') def test_apps_init_circular_depends(loaded_modules): """Test initializing apps with circular dependencies.""" loaded_modules.items.return_value = [('test', ModuleCircularTest())] diff --git a/freedombox/tests/test_cfg.py b/freedombox/tests/test_cfg.py index ef05b04ee..64739dd2c 100644 --- a/freedombox/tests/test_cfg.py +++ b/freedombox/tests/test_cfg.py @@ -46,7 +46,7 @@ def test_read_default_config_file(): compare_configurations(parser) -@patch('plinth.cfg.get_config_paths') +@patch('freedombox.cfg.get_config_paths') def test_read_primary_config_file(get_config_paths): """Verify that the primary config file is used by default.""" config_path = CONFIG_FILE_WITH_MISSING_OPTIONS @@ -55,7 +55,7 @@ def test_read_primary_config_file(get_config_paths): assert cfg.config_files[-1] == config_path -@patch('plinth.cfg.get_config_paths') +@patch('freedombox.cfg.get_config_paths') def test_read_dot_d_config_files(get_config_paths): """Verify that the configuration is read from .d directories.""" root_dir = pathlib.Path(__file__).resolve().parent @@ -74,7 +74,7 @@ def test_read_develop_config_file(): """Verify that the correct develop config file is used.""" test_dir = os.path.dirname(os.path.realpath(__file__)) develop_root = os.path.realpath(os.path.join(test_dir, '..', '..')) - develop_config_file = os.path.join(develop_root, 'plinth', + develop_config_file = os.path.join(develop_root, 'freedombox', 'develop.config') config_path = cfg.get_develop_config_path() cfg.read_file(config_path) diff --git a/freedombox/tests/test_config.py b/freedombox/tests/test_config.py index 2e56a6911..30eb94fc4 100644 --- a/freedombox/tests/test_config.py +++ b/freedombox/tests/test_config.py @@ -12,7 +12,7 @@ from freedombox.config import DropinConfigs from freedombox.diagnostic_check import DiagnosticCheck, Result pytestmark = pytest.mark.usefixtures('mock_privileged') -privileged_modules_to_mock = ['plinth.privileged.config'] +privileged_modules_to_mock = ['freedombox.privileged.config'] @pytest.fixture(name='dropin_configs') @@ -33,7 +33,8 @@ def fixture_dropin_configs(): @pytest.fixture(autouse=True) def fixture_assert_dropin_config(dropin_configs): """Mock asserting dropin config path.""" - with patch('plinth.privileged.config._get_managed_dropin_config') as mock: + with patch( + 'freedombox.privileged.config._get_managed_dropin_config') as mock: mock.return_value = dropin_configs yield @@ -70,7 +71,7 @@ def _assert_symlinks(component, tmp_path, should_exist, copy_only=False): def test_dropin_configs_setup(dropin_configs, tmp_path): """Test setup for dropin configs component.""" - with patch('plinth.config.DropinConfigs.ROOT', new=tmp_path): + with patch('freedombox.config.DropinConfigs.ROOT', new=tmp_path): is_enabled = Mock() App.get('test-app').is_enabled = is_enabled @@ -85,7 +86,7 @@ def test_dropin_configs_setup(dropin_configs, tmp_path): def test_dropin_configs_enable_disable_symlinks(dropin_configs, tmp_path): """Test enable/disable for dropin configs component for symlinks.""" - with patch('plinth.config.DropinConfigs.ROOT', new=tmp_path): + with patch('freedombox.config.DropinConfigs.ROOT', new=tmp_path): # Enable when nothing exists dropin_configs.enable() _assert_symlinks(dropin_configs, tmp_path, should_exist=True) @@ -117,7 +118,7 @@ def test_dropin_configs_enable_disable_symlinks(dropin_configs, tmp_path): def test_dropin_configs_enable_disable_copy_only(dropin_configs, tmp_path): """Test enable/disable for dropin configs component for copying.""" - with patch('plinth.config.DropinConfigs.ROOT', new=tmp_path): + with patch('freedombox.config.DropinConfigs.ROOT', new=tmp_path): dropin_configs.copy_only = True for path in ['/etc/test/path1', '/etc/path2']: target = dropin_configs.get_target_path(path) @@ -159,7 +160,7 @@ def test_dropin_configs_enable_disable_copy_only(dropin_configs, tmp_path): def test_dropin_config_diagnose_symlinks(dropin_configs, tmp_path): """Test diagnosing dropin configs for symlinks.""" - with patch('plinth.config.DropinConfigs.ROOT', new=tmp_path): + with patch('freedombox.config.DropinConfigs.ROOT', new=tmp_path): # Nothing exists results = dropin_configs.diagnose() assert results == [ @@ -202,7 +203,7 @@ def test_dropin_config_diagnose_symlinks(dropin_configs, tmp_path): def test_dropin_config_diagnose_copy_only(dropin_configs, tmp_path): """Test diagnosing dropin configs.""" - with patch('plinth.config.DropinConfigs.ROOT', new=tmp_path): + with patch('freedombox.config.DropinConfigs.ROOT', new=tmp_path): dropin_configs.copy_only = True for path in ['/etc/test/path1', '/etc/path2']: target = dropin_configs.get_target_path(path) diff --git a/freedombox/tests/test_container.py b/freedombox/tests/test_container.py index e8bcccbda..861d06138 100644 --- a/freedombox/tests/test_container.py +++ b/freedombox/tests/test_container.py @@ -11,8 +11,8 @@ from freedombox.diagnostic_check import DiagnosticCheck, Result pytestmark = pytest.mark.usefixtures('mock_privileged') privileged_modules_to_mock = [ - 'plinth.privileged', 'plinth.privileged.container', - 'plinth.privileged.service' + 'freedombox.privileged', 'freedombox.privileged.container', + 'freedombox.privileged.service' ] @@ -31,7 +31,7 @@ def fixture_container(): ['service1.service'], {'/dev/host1': '/dev/cont1'}, [(1234, 'tcp4')]) app1.add(container) - with patch('plinth.app.App.list') as app_list: + with patch('freedombox.app.App.list') as app_list: app_list.return_value = [app1] yield container @@ -63,7 +63,7 @@ def test_container_init(container): assert container.listen_ports == [(1234, 'tcp4')] -@patch('plinth.action_utils.podman_is_enabled') +@patch('freedombox.action_utils.podman_is_enabled') def test_container_is_enabled(podman_is_enabled, container): """Test checking if container is enabled.""" podman_is_enabled.return_value = False @@ -73,8 +73,8 @@ def test_container_is_enabled(podman_is_enabled, container): assert container.is_enabled() -@patch('plinth.action_utils.service_enable') -@patch('plinth.action_utils.podman_enable') +@patch('freedombox.action_utils.service_enable') +@patch('freedombox.action_utils.podman_enable') def test_container_enable(podman_enable, enable, container): """Test enabling a container component.""" container.enable() @@ -82,8 +82,8 @@ def test_container_enable(podman_enable, enable, container): assert enable.mock_calls == [call('name1')] -@patch('plinth.action_utils.service_disable') -@patch('plinth.action_utils.podman_disable') +@patch('freedombox.action_utils.service_disable') +@patch('freedombox.action_utils.podman_disable') def test_container_disable(podman_disable, disable, container): """Test disabling a container component.""" container.disable() @@ -91,7 +91,7 @@ def test_container_disable(podman_disable, disable, container): assert disable.mock_calls == [call('name1')] -@patch('plinth.action_utils.service_is_running') +@patch('freedombox.action_utils.service_is_running') def test_container_is_running(service_is_running, container): """Test checking of container component is running.""" service_is_running.return_value = False @@ -103,9 +103,9 @@ def test_container_is_running(service_is_running, container): assert container.is_running() -@patch('plinth.action_utils.service_disable') -@patch('plinth.action_utils.service_enable') -@patch('plinth.action_utils.service_is_running') +@patch('freedombox.action_utils.service_disable') +@patch('freedombox.action_utils.service_enable') +@patch('freedombox.action_utils.service_is_running') def test_container_ensure_running(service_is_running, enable, disable, container): """Test checking of container component can be ensured to be running.""" @@ -124,11 +124,11 @@ def test_container_ensure_running(service_is_running, enable, disable, assert disable.mock_calls == [call('name1')] -@patch('plinth.action_utils.service_disable') -@patch('plinth.action_utils.service_start') -@patch('plinth.action_utils.podman_disable') -@patch('plinth.action_utils.podman_is_enabled') -@patch('plinth.action_utils.podman_create') +@patch('freedombox.action_utils.service_disable') +@patch('freedombox.action_utils.service_start') +@patch('freedombox.action_utils.podman_disable') +@patch('freedombox.action_utils.podman_is_enabled') +@patch('freedombox.action_utils.podman_create') def test_container_setup(podman_create, is_enabled, disable, service_start, service_disable, container): """Test setting up the container.""" @@ -152,7 +152,7 @@ def test_container_setup(podman_create, is_enabled, disable, service_start, assert service_disable.mock_calls == [call('name1')] -@patch('plinth.action_utils.podman_uninstall') +@patch('freedombox.action_utils.podman_uninstall') def test_container_uninstall(podman_uninstall, container): """Test uninstalling the container.""" container.uninstall() @@ -162,8 +162,8 @@ def test_container_uninstall(podman_uninstall, container): ] -@patch('plinth.action_utils.service_is_running') -@patch('plinth.container.diagnose_port_listening') +@patch('freedombox.action_utils.service_is_running') +@patch('freedombox.container.diagnose_port_listening') def test_container_diagnose(diagnose_port_listening, service_is_running, container): """Test diagnosing the container.""" diff --git a/freedombox/tests/test_context_processors.py b/freedombox/tests/test_context_processors.py index 245615bb7..0362e3b34 100644 --- a/freedombox/tests/test_context_processors.py +++ b/freedombox/tests/test_context_processors.py @@ -10,7 +10,7 @@ from django.urls import resolve from freedombox import context_processors as cp -@patch('plinth.notification.Notification') +@patch('freedombox.notification.Notification') def test_common(Notification, load_cfg, rf, test_menu): """Verify that the common() function returns the correct values.""" url = '/apps/testapp/create/' diff --git a/freedombox/tests/test_daemon.py b/freedombox/tests/test_daemon.py index 2ea5904c5..ec5d29d89 100644 --- a/freedombox/tests/test_daemon.py +++ b/freedombox/tests/test_daemon.py @@ -10,11 +10,12 @@ from unittest.mock import Mock, call, patch import pytest from freedombox.app import App, FollowerComponent, Info -from freedombox.daemon import (Daemon, RelatedDaemon, SharedDaemon, app_is_running, - diagnose_netcat, diagnose_port_listening) +from freedombox.daemon import (Daemon, RelatedDaemon, SharedDaemon, + app_is_running, diagnose_netcat, + diagnose_port_listening) from freedombox.diagnostic_check import DiagnosticCheck, Result -privileged_modules_to_mock = ['plinth.privileged.service'] +privileged_modules_to_mock = ['freedombox.privileged.service'] class AppTest(App): @@ -35,7 +36,7 @@ def fixture_app_list(daemon): app1 = AppTest() app1.add(Info('test-app', 1)) app1.add(daemon) - with patch('plinth.app.App.list') as app_list: + with patch('freedombox.app.App.list') as app_list: app_list.return_value = [app1] yield app_list @@ -60,7 +61,7 @@ def test_initialization(): assert daemon.alias == 'test-unit-2' -@patch('plinth.action_utils.service_is_enabled') +@patch('freedombox.action_utils.service_is_enabled') def test_is_enabled(service_is_enabled, daemon): """Test that daemon enabled check works.""" service_is_enabled.return_value = True @@ -77,7 +78,7 @@ def test_is_enabled(service_is_enabled, daemon): service_is_enabled.assert_has_calls([call('test-unit', strict_check=True)]) -@patch('plinth.app.apps_init') +@patch('freedombox.app.apps_init') @patch('subprocess.run') def test_enable(subprocess_run, apps_init, app_list, mock_privileged, daemon): """Test that enabling the daemon works.""" @@ -105,7 +106,7 @@ def test_enable(subprocess_run, apps_init, app_list, mock_privileged, daemon): **common_args) -@patch('plinth.app.apps_init') +@patch('freedombox.app.apps_init') @patch('subprocess.run') def test_disable(subprocess_run, apps_init, app_list, mock_privileged, daemon): """Test that disabling the daemon works.""" @@ -132,7 +133,7 @@ def test_disable(subprocess_run, apps_init, app_list, mock_privileged, daemon): **common_args) -@patch('plinth.action_utils.service_is_running') +@patch('freedombox.action_utils.service_is_running') def test_is_running(service_is_running, daemon): """Test that checking that the daemon is running works.""" service_is_running.return_value = True @@ -143,9 +144,9 @@ def test_is_running(service_is_running, daemon): assert not daemon.is_running() -@patch('plinth.app.apps_init') -@patch('plinth.action_utils.service_is_running') -@patch('plinth.action_utils.service_show') +@patch('freedombox.app.apps_init') +@patch('freedombox.action_utils.service_is_running') +@patch('freedombox.action_utils.service_show') @patch('subprocess.run') def test_ensure_running(subprocess_run, service_show, service_is_running, apps_init, app_list, mock_privileged, daemon): @@ -182,8 +183,8 @@ def test_ensure_running(subprocess_run, service_show, service_is_running, ] -@patch('plinth.action_utils.service_is_running') -@patch('plinth.daemon.diagnose_port_listening') +@patch('freedombox.action_utils.service_is_running') +@patch('freedombox.daemon.diagnose_port_listening') def test_diagnose(port_listening, service_is_running, daemon): """Test running diagnostics.""" @@ -216,7 +217,7 @@ def test_diagnose(port_listening, service_is_running, daemon): assert results[0].result == Result.FAILED -@patch('plinth.action_utils.service_is_running') +@patch('freedombox.action_utils.service_is_running') def test_app_is_running(service_is_running): """Test that checking whether app is running works.""" daemon1 = Daemon('test-daemon-1', 'test-unit-1') @@ -388,7 +389,7 @@ def test_shared_daemon_leader(): assert not component1.is_leader -@patch('plinth.action_utils.service_is_enabled') +@patch('freedombox.action_utils.service_is_enabled') def test_shared_daemon_set_enabled(service_is_enabled): """Test that enabled status is determined by unit status.""" component = SharedDaemon('test-component', 'test-daemon') @@ -406,7 +407,7 @@ def test_shared_daemon_set_enabled(service_is_enabled): assert component.is_enabled() -@patch('plinth.privileged.service.disable') +@patch('freedombox.privileged.service.disable') def test_shared_daemon_disable(disable_method): """Test that shared daemon disables service correctly.""" diff --git a/freedombox/tests/test_frontpage.py b/freedombox/tests/test_frontpage.py index 083bf7fe9..45ceb9eaa 100644 --- a/freedombox/tests/test_frontpage.py +++ b/freedombox/tests/test_frontpage.py @@ -106,7 +106,7 @@ def test_shortcut_list_web_apps_only(common_shortcuts): assert return_list == [cuts[0], cuts[1], cuts[2]] -@patch('plinth.modules.users.privileged.get_user_groups') +@patch('freedombox.modules.users.privileged.get_user_groups') def test_shortcut_list_with_username(get_user_groups, common_shortcuts): """Test listing for particular users.""" cuts = common_shortcuts diff --git a/freedombox/tests/test_middleware.py b/freedombox/tests/test_middleware.py index 323ef62a4..38fd3b77a 100644 --- a/freedombox/tests/test_middleware.py +++ b/freedombox/tests/test_middleware.py @@ -16,8 +16,8 @@ from django.urls import resolve from stronghold.decorators import public from freedombox import app as app_module -from freedombox.middleware import (AdminRequiredMiddleware, CommonErrorMiddleware, - SetupMiddleware) +from freedombox.middleware import (AdminRequiredMiddleware, + CommonErrorMiddleware, SetupMiddleware) @pytest.fixture(name='kwargs') @@ -89,7 +89,7 @@ class TestSetupMiddleware: assert response is None @staticmethod - @patch('plinth.views.SetupView') + @patch('freedombox.views.SetupView') @patch('django.urls.resolve') @patch('django.urls.reverse', return_value='users:login') @pytest.mark.django_db @@ -133,7 +133,7 @@ class TestSetupMiddleware: view.assert_called_once_with(request, app_id='mockapp') @staticmethod - @patch('plinth.operation.manager') + @patch('freedombox.operation.manager') @patch('django.contrib.messages.error') @patch('django.contrib.messages.success') @patch('django.urls.resolve') @@ -221,8 +221,8 @@ class TestAdminMiddleware: web_request.user.groups.filter().exists = Mock(return_value=False) web_request.session = MagicMock() with patch( - 'plinth.middleware.AdminRequiredMiddleware.check_user_group', - lambda x, y: False): + 'freedombox.middleware.AdminRequiredMiddleware.' + 'check_user_group', lambda x, y: False): with pytest.raises(PermissionDenied): middleware.process_view(web_request, **kwargs) @@ -233,8 +233,8 @@ class TestAdminMiddleware: web_request.user.groups.filter().exists = Mock(return_value=False) web_request.session = MagicMock() with patch( - 'plinth.middleware.AdminRequiredMiddleware.check_user_group', - lambda x, y: True): + 'freedombox.middleware.AdminRequiredMiddleware.' + 'check_user_group', lambda x, y: True): response = middleware.process_view(web_request, **kwargs) assert response is None diff --git a/freedombox/tests/test_module_loader.py b/freedombox/tests/test_module_loader.py index fbbcb05b9..fa75982de 100644 --- a/freedombox/tests/test_module_loader.py +++ b/freedombox/tests/test_module_loader.py @@ -8,8 +8,8 @@ from unittest.mock import mock_open, patch from freedombox import module_loader -@patch('pathlib.Path.open', mock_open(read_data='plinth.modules.apache\n')) +@patch('pathlib.Path.open', mock_open(read_data='freedombox.modules.apache\n')) def test_get_module_import_path(): """Returning the module import path.""" import_path = module_loader.get_module_import_path('apache') - assert import_path == 'plinth.modules.apache' + assert import_path == 'freedombox.modules.apache' diff --git a/freedombox/tests/test_notification.py b/freedombox/tests/test_notification.py index e08d8c012..b989bb4e0 100644 --- a/freedombox/tests/test_notification.py +++ b/freedombox/tests/test_notification.py @@ -334,7 +334,7 @@ def test_list_filter_user_and_group(note, user): assert list(Notification.list(user=user)) == [note] -@patch('plinth.notification.gettext') +@patch('freedombox.notification.gettext') def test_display_context(gettext, note, user, rf): """Test display context for a notification.""" request = rf.get('/freedombox/help/about/') diff --git a/freedombox/tests/test_operation.py b/freedombox/tests/test_operation.py index 0d795702b..60fdbb756 100644 --- a/freedombox/tests/test_operation.py +++ b/freedombox/tests/test_operation.py @@ -25,7 +25,7 @@ class AppTest(app.App): self.add(info) -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_operation_default_initialization(update_notification): """Test Operation initialization with default values.""" target = Mock() @@ -48,7 +48,7 @@ def test_operation_default_initialization(update_notification): update_notification.assert_has_calls([call()]) -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_operation_initialization(update_notification): """Test Operation initialization with explicit values.""" on_complete = Mock() @@ -73,7 +73,7 @@ def test_operation_str(): assert str(operation) == 'Operation: testapp: op1' -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_successful_operation(update_notification): """Test running a operation that succeeds.""" target = Mock() @@ -90,7 +90,7 @@ def test_successful_operation(update_notification): update_notification.assert_has_calls([call(), call()]) -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_error_operation(update_notification): """Test running an operation that fails.""" target = Mock() @@ -109,7 +109,7 @@ def test_error_operation(update_notification): update_notification.assert_has_calls([call(), call()]) -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_join_before_start(update_notification): """Test waiting until operation finishes..""" event = threading.Event() @@ -131,7 +131,7 @@ def test_join_before_start(update_notification): assert success -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_join_raises_exception(update_notification): """Test that joining raises exception if thread does..""" target = Mock() @@ -157,7 +157,7 @@ def test_getting_operation_from_thread(): assert operation.thread_data['test_operation'] == operation -@patch('plinth.operation.Operation._update_notification') +@patch('freedombox.operation.Operation._update_notification') def test_updating_operation(update_notification): """Test that operation object can be updated from within the thread.""" exception = RuntimeError('error1') @@ -176,7 +176,7 @@ def test_updating_operation(update_notification): update_notification.assert_has_calls([call(), call(), call()]) -@patch('plinth.app.App.get') +@patch('freedombox.app.App.get') def test_message(app_get): """Test getting the operation's message.""" operation = Operation('testid', 'testapp', 'op1', Mock()) @@ -205,7 +205,7 @@ def test_message(app_get): assert operation.translated_message == 'Finished: op1' -@patch('plinth.app.App.get') +@patch('freedombox.app.App.get') @pytest.mark.django_db def test_update_notification(app_get): """Test that operation notification is created.""" diff --git a/freedombox/tests/test_package.py b/freedombox/tests/test_package.py index 3fb5d57a8..de6681562 100644 --- a/freedombox/tests/test_package.py +++ b/freedombox/tests/test_package.py @@ -109,7 +109,7 @@ def test_packages_get_actual_packages(cache): component.get_actual_packages() -@patch('plinth.package.install') +@patch('freedombox.package.install') def test_packages_setup(install): """Test setting up packages component.""" @@ -139,9 +139,9 @@ def test_packages_setup(install): install.assert_has_calls([call(['python3'], skip_recommends=False)]) -@patch('plinth.package.packages_installed') -@patch('plinth.package.uninstall') -@patch('plinth.package.install') +@patch('freedombox.package.packages_installed') +@patch('freedombox.package.uninstall') +@patch('freedombox.package.install') def test_packages_setup_with_conflicts(install, uninstall, packages_installed): """Test setting up packages with conflicts.""" packages_installed.return_value = ['exim4-base'] @@ -169,8 +169,8 @@ def test_packages_setup_with_conflicts(install, uninstall, packages_installed): install.assert_has_calls([call(['bash'], skip_recommends=False)]) -@patch('plinth.package.refresh_package_lists') -@patch('plinth.package.uninstall') +@patch('freedombox.package.refresh_package_lists') +@patch('freedombox.package.uninstall') def test_packages_uninstall(uninstall, _refresh_package_lists): """Test uninstalling packages component.""" @@ -185,8 +185,8 @@ def test_packages_uninstall(uninstall, _refresh_package_lists): uninstall.assert_has_calls([call(['bash', 'dash'], purge=True)]) -@patch('plinth.package.refresh_package_lists') -@patch('plinth.package.uninstall') +@patch('freedombox.package.refresh_package_lists') +@patch('freedombox.package.uninstall') @patch('apt.Cache') def test_packages_uninstall_exclusion(cache, uninstall, _refresh_package_lists): @@ -333,7 +333,7 @@ def test_diagnose(cache): ] -@patch('plinth.package.packages_installed') +@patch('freedombox.package.packages_installed') def test_packages_find_conflicts(packages_installed_): """Test finding conflicts.""" packages_installed_.return_value = [] @@ -353,7 +353,7 @@ def test_packages_find_conflicts(packages_installed_): assert component.find_conflicts() == ['package1', 'package2'] -@patch('plinth.package.refresh_package_lists') +@patch('freedombox.package.refresh_package_lists') @patch('apt.Cache') @patch('pathlib.Path') def test_packages_is_available(path_class, cache, refresh_package_lists): diff --git a/freedombox/tests/test_templatetags.py b/freedombox/tests/test_templatetags.py index 32bcb5990..c7f21970a 100644 --- a/freedombox/tests/test_templatetags.py +++ b/freedombox/tests/test_templatetags.py @@ -49,7 +49,7 @@ def test_highlighting(): assert _verify_active_menuitems(menu) -@patch('plinth.web_server.resolve_static_path') +@patch('freedombox.web_server.resolve_static_path') def test_icon(resolve_static_path, tmp_path): """Test that the icon tag works for basic usage.""" icon1 = tmp_path / 'icon1.svg' @@ -60,7 +60,7 @@ def test_icon(resolve_static_path, tmp_path): '>') -@patch('plinth.web_server.resolve_static_path') +@patch('freedombox.web_server.resolve_static_path') def test_icon_attributes(resolve_static_path, tmp_path): """Test that the icon tag works with attributes.""" icon1 = tmp_path / 'icon1.svg' @@ -78,8 +78,8 @@ def test_icon_attributes(resolve_static_path, tmp_path): 'data-icon-name="icon1" >') -@patch('plinth.utils.random_string') -@patch('plinth.web_server.resolve_static_path') +@patch('freedombox.utils.random_string') +@patch('freedombox.web_server.resolve_static_path') def test_icon_auto_ids(resolve_static_path, random_string, tmp_path): """Test that the icon tag works for implementing automatic IDs.""" random_string.return_value = 'randomvalue' @@ -93,7 +93,7 @@ def test_icon_auto_ids(resolve_static_path, random_string, tmp_path): '') -@patch('plinth.web_server.resolve_static_path') +@patch('freedombox.web_server.resolve_static_path') def test_icon_xml_stripping(resolve_static_path, tmp_path): """Test that the icon tag strips the XML header.""" icon2 = tmp_path / 'icon2.svg' diff --git a/freedombox/tests/test_web_server.py b/freedombox/tests/test_web_server.py index fd90cef23..4b4bfd521 100644 --- a/freedombox/tests/test_web_server.py +++ b/freedombox/tests/test_web_server.py @@ -65,7 +65,7 @@ def test_static_files_mount(mount, load_cfg): @patch('sys.modules') -@patch('plinth.app.App.list') +@patch('freedombox.app.App.list') def test_resolve_static_path(app_list, sys_modules, tmp_path): """Test that resolving a static path works as expected.""" app_list.return_value = [] diff --git a/freedombox/views.py b/freedombox/views.py index aa2283559..6d2552092 100644 --- a/freedombox/views.py +++ b/freedombox/views.py @@ -714,7 +714,7 @@ class UninstallView(FormView): if self.has_backup_restore and form.cleaned_data['should_backup']: repository_id = form.cleaned_data['repository'] - import plinth.modules.backups.repository as repository_module + import freedombox.modules.backups.repository as repository_module repository = repository_module.get_instance(repository_id) if repository.flags.get('mountable'): repository.mount() diff --git a/run b/run index 0d19015bd..e50eb02ba 100755 --- a/run +++ b/run @@ -3,6 +3,6 @@ # SPDX-License-Identifier: AGPL-3.0-or-later # -import plinth.__main__ +import freedombox.__main__ -plinth.__main__.main() +freedombox.__main__.main()