mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
*: Additional import path related changes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
baa44e91a2
commit
c700e0866e
@ -11,14 +11,14 @@ import argparse
|
|||||||
import getpass
|
import getpass
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import plinth.web_framework
|
import freedombox.web_framework
|
||||||
from plinth.modules.users import privileged
|
from freedombox.modules.users import privileged
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Ask for new password, setup Django and update a user's password."""
|
"""Ask for new password, setup Django and update a user's password."""
|
||||||
try:
|
try:
|
||||||
plinth.web_framework.init()
|
freedombox.web_framework.init()
|
||||||
except Exception:
|
except Exception:
|
||||||
_print('Error initializing Django.')
|
_print('Error initializing Django.')
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# 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()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import plinth.privileged_daemon
|
import freedombox.privileged_daemon
|
||||||
|
|
||||||
plinth.privileged_daemon.main()
|
freedombox.privileged_daemon.main()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
import plinth.__main__
|
import freedombox.__main__
|
||||||
|
|
||||||
plinth.__main__.main()
|
freedombox.__main__.main()
|
||||||
|
|||||||
@ -463,8 +463,8 @@ def _privileged_call(module_name, action_name, arguments, log_error=True):
|
|||||||
raise SyntaxError('Invalid module name')
|
raise SyntaxError('Invalid module name')
|
||||||
|
|
||||||
cfg.read()
|
cfg.read()
|
||||||
if module_name == 'plinth':
|
if module_name == 'freedombox':
|
||||||
import_path = 'plinth'
|
import_path = 'freedombox'
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import_path = module_loader.get_module_import_path(module_name)
|
import_path = module_loader.get_module_import_path(module_name)
|
||||||
|
|||||||
@ -73,7 +73,7 @@ def fixture_load_cfg():
|
|||||||
saved_state[key] = getattr(cfg, key)
|
saved_state[key] = getattr(cfg, key)
|
||||||
|
|
||||||
root_dir = pathlib.Path(__file__).resolve().parent
|
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))
|
cfg.read_file(str(cfg_file))
|
||||||
yield cfg
|
yield cfg
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ def fixture_mock_run_as_user():
|
|||||||
from freedombox import action_utils
|
from freedombox import action_utils
|
||||||
return action_utils.run(*args, **kwargs)
|
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
|
mock.side_effect = _bypass_runuser
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from django.utils.translation import gettext_noop
|
|||||||
from freedombox import app, log, privileged
|
from freedombox import app, log, privileged
|
||||||
from freedombox.daemon import diagnose_port_listening
|
from freedombox.daemon import diagnose_port_listening
|
||||||
from freedombox.diagnostic_check import (DiagnosticCheck,
|
from freedombox.diagnostic_check import (DiagnosticCheck,
|
||||||
DiagnosticCheckParameters, Result)
|
DiagnosticCheckParameters, Result)
|
||||||
|
|
||||||
|
|
||||||
class Container(app.LeaderComponent, log.LogEmitter):
|
class Container(app.LeaderComponent, log.LogEmitter):
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from django.utils.translation import gettext_noop
|
|||||||
|
|
||||||
from freedombox import action_utils, app, log
|
from freedombox import action_utils, app, log
|
||||||
from freedombox.diagnostic_check import (DiagnosticCheck,
|
from freedombox.diagnostic_check import (DiagnosticCheck,
|
||||||
DiagnosticCheckParameters, Result)
|
DiagnosticCheckParameters, Result)
|
||||||
|
|
||||||
|
|
||||||
class Daemon(app.LeaderComponent, log.LogEmitter):
|
class Daemon(app.LeaderComponent, log.LogEmitter):
|
||||||
|
|||||||
@ -11,12 +11,12 @@ from django.utils import translation
|
|||||||
from django.utils.translation import get_language_info
|
from django.utils.translation import get_language_info
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
import plinth
|
import freedombox
|
||||||
|
|
||||||
|
|
||||||
def _get_repository_choices():
|
def _get_repository_choices():
|
||||||
"""Return the list of available repositories."""
|
"""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)
|
choices = [(repository.uuid, repository.name)
|
||||||
for repository in repository_module.get_repositories()
|
for repository in repository_module.get_repositories()
|
||||||
if repository.is_usable()]
|
if repository.is_usable()]
|
||||||
@ -109,9 +109,9 @@ class LanguageSelectionFormMixin:
|
|||||||
|
|
||||||
for language_code, language_name in settings.LANGUAGES:
|
for language_code, language_name in settings.LANGUAGES:
|
||||||
locale_code = translation.to_locale(language_code)
|
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(
|
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(
|
supported_languages.append(
|
||||||
(language_code,
|
(language_code,
|
||||||
_get_local_name(language_code, language_name)))
|
_get_local_name(language_code, language_name)))
|
||||||
|
|||||||
@ -133,7 +133,7 @@ def get_configuration(syslog_identifier='freedombox'):
|
|||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
'formatters': {
|
'formatters': {
|
||||||
'color': {
|
'color': {
|
||||||
'()': 'plinth.log.ColoredFormatter',
|
'()': 'freedombox.log.ColoredFormatter',
|
||||||
'format': '{colored_levelname} {colored_name} {message}',
|
'format': '{colored_levelname} {colored_name} {message}',
|
||||||
'style': '{'
|
'style': '{'
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ from django.utils.translation import gettext_noop
|
|||||||
|
|
||||||
from freedombox import action_utils, app, kvstore
|
from freedombox import action_utils, app, kvstore
|
||||||
from freedombox.diagnostic_check import (DiagnosticCheck,
|
from freedombox.diagnostic_check import (DiagnosticCheck,
|
||||||
DiagnosticCheckParameters, Result)
|
DiagnosticCheckParameters, Result)
|
||||||
from freedombox.privileged import service as service_privileged
|
from freedombox.privileged import service as service_privileged
|
||||||
|
|
||||||
from . import privileged
|
from . import privileged
|
||||||
|
|||||||
@ -11,8 +11,8 @@ import pytest
|
|||||||
from freedombox import app, kvstore
|
from freedombox import app, kvstore
|
||||||
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
||||||
from freedombox.modules.apache.components import (Webserver, WebserverRoot,
|
from freedombox.modules.apache.components import (Webserver, WebserverRoot,
|
||||||
check_url, diagnose_url,
|
check_url, diagnose_url,
|
||||||
diagnose_url_on_all)
|
diagnose_url_on_all)
|
||||||
|
|
||||||
|
|
||||||
def test_webserver_init():
|
def test_webserver_init():
|
||||||
@ -34,7 +34,7 @@ def test_webserver_init():
|
|||||||
assert not webserver.expect_redirects
|
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):
|
def test_webserver_is_enabled(webserver_is_enabled):
|
||||||
"""Test that checking webserver configuration enabled works."""
|
"""Test that checking webserver configuration enabled works."""
|
||||||
webserver = Webserver('test-webserver', 'test-config', kind='module')
|
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')])
|
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):
|
def test_webserver_enable(enable):
|
||||||
"""Test that enabling webserver configuration works."""
|
"""Test that enabling webserver configuration works."""
|
||||||
webserver = Webserver('test-webserver', 'test-config', kind='module')
|
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')])
|
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):
|
def test_webserver_disable(disable):
|
||||||
"""Test that disabling webserver configuration works."""
|
"""Test that disabling webserver configuration works."""
|
||||||
webserver = Webserver('test-webserver', 'test-config', kind='module')
|
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')])
|
disable.assert_has_calls([call('test-config', 'module')])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.apache.components.diagnose_url')
|
@patch('freedombox.modules.apache.components.diagnose_url')
|
||||||
@patch('plinth.modules.apache.components.diagnose_url_on_all')
|
@patch('freedombox.modules.apache.components.diagnose_url_on_all')
|
||||||
def test_webserver_diagnose(diagnose_url_on_all, diagnose_url):
|
def test_webserver_diagnose(diagnose_url_on_all, diagnose_url):
|
||||||
"""Test running diagnostics."""
|
"""Test running diagnostics."""
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ def test_webserver_diagnose(diagnose_url_on_all, diagnose_url):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.privileged.service.restart')
|
@patch('freedombox.privileged.service.restart')
|
||||||
@patch('plinth.privileged.service.reload')
|
@patch('freedombox.privileged.service.reload')
|
||||||
def test_webserver_setup(service_reload, service_restart):
|
def test_webserver_setup(service_reload, service_restart):
|
||||||
"""Test that component restart/reloads web server during app upgrades."""
|
"""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
|
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):
|
def test_webserver_root_enable(link_root):
|
||||||
"""Test that enabling webserver root works."""
|
"""Test that enabling webserver root works."""
|
||||||
webserver = WebserverRoot('test-webserver', 'test-config')
|
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:
|
) as get:
|
||||||
get.return_value = None
|
get.return_value = None
|
||||||
webserver.enable()
|
webserver.enable()
|
||||||
@ -197,12 +197,12 @@ def test_webserver_root_enable(link_root):
|
|||||||
link_root.assert_has_calls([call('x-domain', 'test-config')])
|
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):
|
def test_webserver_root_disable(unlink_root):
|
||||||
"""Test that disabling webserver root works."""
|
"""Test that disabling webserver root works."""
|
||||||
webserver = WebserverRoot('test-webserver', 'test-config')
|
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:
|
) as get:
|
||||||
get.return_value = None
|
get.return_value = None
|
||||||
webserver.disable()
|
webserver.disable()
|
||||||
@ -224,9 +224,9 @@ def test_webserver_root_domain_get():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@patch('plinth.modules.apache.privileged.unlink_root')
|
@patch('freedombox.modules.apache.privileged.unlink_root')
|
||||||
@patch('plinth.modules.apache.privileged.link_root')
|
@patch('freedombox.modules.apache.privileged.link_root')
|
||||||
@patch('plinth.app.Component.app', new_callable=PropertyMock)
|
@patch('freedombox.app.Component.app', new_callable=PropertyMock)
|
||||||
def test_webserver_root_domain_set(component_app, link_root, unlink_root):
|
def test_webserver_root_domain_set(component_app, link_root, unlink_root):
|
||||||
"""Test setting webserver root's domain."""
|
"""Test setting webserver root's domain."""
|
||||||
webserver = WebserverRoot('test-webserver', 'test-config')
|
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
|
@pytest.mark.django_db
|
||||||
@patch('plinth.modules.apache.components.WebserverRoot.disable')
|
@patch('freedombox.modules.apache.components.WebserverRoot.disable')
|
||||||
@patch('plinth.modules.apache.components.WebserverRoot.enable')
|
@patch('freedombox.modules.apache.components.WebserverRoot.enable')
|
||||||
@patch('plinth.modules.apache.components.diagnose_url')
|
@patch('freedombox.modules.apache.components.diagnose_url')
|
||||||
@patch('plinth.app.Component.app', new_callable=PropertyMock)
|
@patch('freedombox.app.Component.app', new_callable=PropertyMock)
|
||||||
def test_webserver_root_diagnose(component_app, diagnose_url, enable, disable):
|
def test_webserver_root_diagnose(component_app, diagnose_url, enable, disable):
|
||||||
"""Test running diagnostics on webserver root component."""
|
"""Test running diagnostics on webserver root component."""
|
||||||
webserver = WebserverRoot('test-webserver', 'test-config')
|
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]
|
assert webserver.diagnose() == [result]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.privileged.service.reload')
|
@patch('freedombox.privileged.service.reload')
|
||||||
def test_webserver_root_setup(service_reload):
|
def test_webserver_root_setup(service_reload):
|
||||||
"""Test that component reloads web server during app upgrades."""
|
"""Test that component reloads web server during app upgrades."""
|
||||||
|
|
||||||
@ -311,9 +311,9 @@ def test_webserver_root_setup(service_reload):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@patch('plinth.modules.apache.components.WebserverRoot.disable')
|
@patch('freedombox.modules.apache.components.WebserverRoot.disable')
|
||||||
@patch('plinth.modules.apache.components.WebserverRoot.enable')
|
@patch('freedombox.modules.apache.components.WebserverRoot.enable')
|
||||||
@patch('plinth.app.Component.app', new_callable=PropertyMock)
|
@patch('freedombox.app.Component.app', new_callable=PropertyMock)
|
||||||
def test_webserver_root_uninstall(component_app, enable, disable):
|
def test_webserver_root_uninstall(component_app, enable, disable):
|
||||||
"""Test that component removes the DB key during uninstall."""
|
"""Test that component removes the DB key during uninstall."""
|
||||||
webserver = WebserverRoot('test-webserver', 'test-config')
|
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'
|
assert kvstore.get_default('test-webserver_domain', 'x-value') == 'x-value'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.apache.components.check_url')
|
@patch('freedombox.modules.apache.components.check_url')
|
||||||
@patch('plinth.action_utils.get_addresses')
|
@patch('freedombox.action_utils.get_addresses')
|
||||||
def test_diagnose_url(get_addresses, check):
|
def test_diagnose_url(get_addresses, check):
|
||||||
"""Test diagnosing a URL."""
|
"""Test diagnosing a URL."""
|
||||||
args = {
|
args = {
|
||||||
|
|||||||
@ -93,7 +93,7 @@ class TestBackupProcesses:
|
|||||||
backup_handler.assert_called_once()
|
backup_handler.assert_called_once()
|
||||||
|
|
||||||
@staticmethod
|
@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):
|
def test_restore_apps(mock_install):
|
||||||
"""Test that restore_handler is called."""
|
"""Test that restore_handler is called."""
|
||||||
restore_handler = MagicMock()
|
restore_handler = MagicMock()
|
||||||
@ -101,8 +101,8 @@ class TestBackupProcesses:
|
|||||||
restore_handler.assert_called_once()
|
restore_handler.assert_called_once()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.app.App.get_setup_state')
|
@patch('freedombox.app.App.get_setup_state')
|
||||||
@patch('plinth.app.App.list')
|
@patch('freedombox.app.App.list')
|
||||||
def test_get_all_components_for_backup(apps_list, get_setup_state):
|
def test_get_all_components_for_backup(apps_list, get_setup_state):
|
||||||
"""Test listing components supporting backup and needing backup."""
|
"""Test listing components supporting backup and needing backup."""
|
||||||
get_setup_state.side_effect = [
|
get_setup_state.side_effect = [
|
||||||
@ -121,7 +121,7 @@ class TestBackupProcesses:
|
|||||||
assert returned_components == expected_components
|
assert returned_components == expected_components
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.app.App.list')
|
@patch('freedombox.app.App.list')
|
||||||
def test_get_components_in_order(apps_list):
|
def test_get_components_in_order(apps_list):
|
||||||
"""Test that components are listed in correct dependency order."""
|
"""Test that components are listed in correct dependency order."""
|
||||||
apps = [
|
apps = [
|
||||||
@ -155,10 +155,10 @@ class TestBackupProcesses:
|
|||||||
assert not apps[1].locked
|
assert not apps[1].locked
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.action_utils.webserver_is_enabled')
|
@patch('freedombox.action_utils.webserver_is_enabled')
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
@patch('plinth.privileged.service.stop')
|
@patch('freedombox.privileged.service.stop')
|
||||||
@patch('plinth.modules.apache.privileged.disable')
|
@patch('freedombox.modules.apache.privileged.disable')
|
||||||
def test__shutdown_services(apache_disable, service_stop,
|
def test__shutdown_services(apache_disable, service_stop,
|
||||||
service_is_running, webserver_is_enabled):
|
service_is_running, webserver_is_enabled):
|
||||||
"""Test that services are stopped in correct order."""
|
"""Test that services are stopped in correct order."""
|
||||||
@ -188,8 +188,8 @@ class TestBackupProcesses:
|
|||||||
service_stop.assert_has_calls([call('b'), call('a')])
|
service_stop.assert_has_calls([call('b'), call('a')])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.privileged.service.start')
|
@patch('freedombox.privileged.service.start')
|
||||||
@patch('plinth.modules.apache.privileged.enable')
|
@patch('freedombox.modules.apache.privileged.enable')
|
||||||
def test__restore_services(apache_enable, service_start):
|
def test__restore_services(apache_enable, service_start):
|
||||||
"""Test that services are restored in correct order."""
|
"""Test that services are restored in correct order."""
|
||||||
original_state = [
|
original_state = [
|
||||||
|
|||||||
@ -12,13 +12,14 @@ import pytest
|
|||||||
|
|
||||||
from freedombox.modules import backups
|
from freedombox.modules import backups
|
||||||
from freedombox.modules.backups import privileged
|
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
|
from freedombox.tests import config as test_config
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('needs_root', 'needs_borg', 'load_cfg',
|
pytestmark = pytest.mark.usefixtures('needs_root', 'needs_borg', 'load_cfg',
|
||||||
'mock_privileged')
|
'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
|
# try to access a non-existing url and a URL that exists but does not
|
||||||
# grant access
|
# grant access
|
||||||
|
|||||||
@ -245,7 +245,7 @@ def test_backup_restore_hooks(backup_restore):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@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):
|
def test_backup_restore_backup_pre(dump_settings, backup_restore):
|
||||||
"""Test running backup-pre hook."""
|
"""Test running backup-pre hook."""
|
||||||
packet = None
|
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'})])
|
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):
|
def test_backup_restore_restore_pre(delete_before_restore, backup_restore):
|
||||||
"""Test running restore-pre hook."""
|
"""Test running restore-pre hook."""
|
||||||
packet = None
|
packet = None
|
||||||
@ -275,7 +275,7 @@ def test_backup_restore_restore_pre(delete_before_restore, backup_restore):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@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):
|
def test_backup_restore_restore_post(load_settings, backup_restore):
|
||||||
"""Test running restore-post hook."""
|
"""Test running restore-post hook."""
|
||||||
packet = None
|
packet = None
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from unittest.mock import MagicMock, call, patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import plinth.modules.backups.repository as repository_module
|
import freedombox.modules.backups.repository as repository_module
|
||||||
from freedombox.app import App
|
from freedombox.app import App
|
||||||
|
|
||||||
from ..components import BackupRestore
|
from ..components import BackupRestore
|
||||||
@ -420,8 +420,8 @@ cases = [
|
|||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'schedule_params,archives_data,test_now,run_periods,cleanups', cases)
|
'schedule_params,archives_data,test_now,run_periods,cleanups', cases)
|
||||||
@patch('plinth.app.App.get_setup_state')
|
@patch('freedombox.app.App.get_setup_state')
|
||||||
@patch('plinth.modules.backups.repository.get_instance')
|
@patch('freedombox.modules.backups.repository.get_instance')
|
||||||
def test_run_schedule(get_instance, get_setup_state, schedule_params,
|
def test_run_schedule(get_instance, get_setup_state, schedule_params,
|
||||||
archives_data, test_now, run_periods, cleanups):
|
archives_data, test_now, run_periods, cleanups):
|
||||||
"""Test that backups are run at expected time."""
|
"""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.generate_archive_name = lambda: \
|
||||||
repository_module.BaseBorgRepository.generate_archive_name(None)
|
repository_module.BaseBorgRepository.generate_archive_name(None)
|
||||||
|
|
||||||
with patch('plinth.modules.backups.schedule.datetime') as mock_datetime, \
|
with patch('freedombox.modules.backups.schedule.datetime') as \
|
||||||
patch('plinth.modules.backups.repository.datetime') \
|
mock_datetime, \
|
||||||
as repo_datetime, patch('plinth.app.App.list') as app_list:
|
patch('freedombox.modules.backups.repository.datetime') \
|
||||||
|
as repo_datetime, patch('freedombox.app.App.list') as app_list:
|
||||||
app_list.return_value = [
|
app_list.return_value = [
|
||||||
_get_test_app('test-app1'),
|
_get_test_app('test-app1'),
|
||||||
_get_test_app('test-app2'),
|
_get_test_app('test-app2'),
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import pytest
|
|||||||
from freedombox.modules.calibre import privileged
|
from freedombox.modules.calibre import privileged
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_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)
|
@pytest.fixture(autouse=True)
|
||||||
|
|||||||
@ -13,16 +13,16 @@ from django.http.response import Http404
|
|||||||
from freedombox import module_loader
|
from freedombox import module_loader
|
||||||
from freedombox.modules.calibre import views
|
from freedombox.modules.calibre import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_calibre_urls():
|
def fixture_calibre_urls():
|
||||||
"""Make sure calibre app's URLs are part of plinth.urls."""
|
"""Make sure calibre app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.calibre')
|
modules.append('freedombox.modules.calibre')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ def fixture_calibre_urls():
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def calibre_patch():
|
def calibre_patch():
|
||||||
"""Patch calibre methods."""
|
"""Patch calibre methods."""
|
||||||
with patch('plinth.modules.calibre.privileged.list_libraries'
|
with patch('freedombox.modules.calibre.privileged.list_libraries'
|
||||||
) as list_libraries:
|
) as list_libraries:
|
||||||
list_libraries.return_value = ['TestExistingLibrary']
|
list_libraries.return_value = ['TestExistingLibrary']
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ def make_request(request, view, **kwargs):
|
|||||||
return response, messages
|
return response, messages
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.calibre.privileged.create_library')
|
@patch('freedombox.modules.calibre.privileged.create_library')
|
||||||
def test_create_library(create_library, rf):
|
def test_create_library(create_library, rf):
|
||||||
"""Test that create library view works."""
|
"""Test that create library view works."""
|
||||||
form_data = {'calibre-name': 'TestLibrary'}
|
form_data = {'calibre-name': 'TestLibrary'}
|
||||||
@ -61,7 +61,7 @@ def test_create_library(create_library, rf):
|
|||||||
create_library.assert_has_calls([call('TestLibrary')])
|
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):
|
def test_create_library_failed(create_library, rf):
|
||||||
"""Test that create library fails as expected."""
|
"""Test that create library fails as expected."""
|
||||||
create_library.side_effect = RuntimeError('TestError')
|
create_library.side_effect = RuntimeError('TestError')
|
||||||
@ -100,7 +100,7 @@ def test_create_library_invalid_name(rf):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
def test_delete_library_confirmation_view(_app, rf):
|
def test_delete_library_confirmation_view(_app, rf):
|
||||||
"""Test that deleting library confirmation shows correct name."""
|
"""Test that deleting library confirmation shows correct name."""
|
||||||
response, _ = make_request(rf.get(''), views.delete_library,
|
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'
|
assert response.context_data['name'] == 'TestExistingLibrary'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.calibre.privileged.delete_library')
|
@patch('freedombox.modules.calibre.privileged.delete_library')
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
def test_delete_library(_app, delete_library, rf):
|
def test_delete_library(_app, delete_library, rf):
|
||||||
"""Test that deleting a library works."""
|
"""Test that deleting a library works."""
|
||||||
response, messages = make_request(rf.post(''), views.delete_library,
|
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')])
|
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):
|
def test_delete_library_error(delete_library, rf):
|
||||||
"""Test that deleting a library shows error when operation fails."""
|
"""Test that deleting a library shows error when operation fails."""
|
||||||
delete_library.side_effect = ValueError('TestError')
|
delete_library.side_effect = ValueError('TestError')
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from freedombox import __main__ as plinth_main
|
|||||||
from freedombox import utils
|
from freedombox import utils
|
||||||
from freedombox.modules.apache import uws_directory_of_user, uws_url_of_user
|
from freedombox.modules.apache import uws_directory_of_user, uws_url_of_user
|
||||||
from freedombox.modules.config import (_home_page_scid2url, change_home_page,
|
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():
|
def test_homepage_mapping():
|
||||||
@ -70,7 +70,7 @@ def test_homepage_mapping_skip_ci():
|
|||||||
|
|
||||||
|
|
||||||
@patch(
|
@patch(
|
||||||
'plinth.frontpage.Shortcut.list',
|
'freedombox.frontpage.Shortcut.list',
|
||||||
Mock(return_value=[
|
Mock(return_value=[
|
||||||
Mock(url='url/for/' + id, component_id=id) for id in ('a', 'b')
|
Mock(url='url/for/' + id, component_id=id) for id in ('a', 'b')
|
||||||
]))
|
]))
|
||||||
|
|||||||
@ -104,7 +104,7 @@ def test_component_init_and_list():
|
|||||||
assert [component1, component2, component3] == list(TurnConsumer.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):
|
def test_notify_on_configuration_changed(get_config, turn_configuration):
|
||||||
"""Test configuration change notifications."""
|
"""Test configuration change notifications."""
|
||||||
component = TurnConsumer('component')
|
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)])
|
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):
|
def test_get_configuration(get_config, turn_configuration):
|
||||||
"""Test coturn configuration retrieval using component."""
|
"""Test coturn configuration retrieval using component."""
|
||||||
get_config.return_value = turn_configuration
|
get_config.return_value = turn_configuration
|
||||||
@ -122,7 +122,7 @@ def test_get_configuration(get_config, turn_configuration):
|
|||||||
assert component.get_configuration() == 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):
|
def test_get_user_configuration(get_config, turn_configuration):
|
||||||
"""Test coturn user configuration retrieval using component."""
|
"""Test coturn user configuration retrieval using component."""
|
||||||
get_config.return_value = turn_configuration
|
get_config.return_value = turn_configuration
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import gettext_lazy as _
|
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 app as app_module
|
||||||
from freedombox import views
|
from freedombox import views
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class AppTest(App):
|
|||||||
|
|
||||||
def test_get_results():
|
def test_get_results():
|
||||||
"""Test getting the diagnostics results."""
|
"""Test getting the diagnostics results."""
|
||||||
var = 'plinth.modules.diagnostics.current_results'
|
var = 'freedombox.modules.diagnostics.current_results'
|
||||||
with patch(var, {}):
|
with patch(var, {}):
|
||||||
assert get_results() == {'progress_percentage': 100, 'results': {}}
|
assert get_results() == {'progress_percentage': 100, 'results': {}}
|
||||||
|
|
||||||
|
|||||||
@ -71,7 +71,7 @@ def test_update_success():
|
|||||||
update_resp = Mock()
|
update_resp = Mock()
|
||||||
update_resp.text = response_to_update_request
|
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:
|
side_effect=[salt_resp, update_resp]) as mock_get:
|
||||||
addr = gnudip.update(server='http://www.2mbit.com:80', ip_type='ipv4',
|
addr = gnudip.update(server='http://www.2mbit.com:80', ip_type='ipv4',
|
||||||
domain='gnudip.dyn.mpis.net', username='gnudip',
|
domain='gnudip.dyn.mpis.net', username='gnudip',
|
||||||
|
|||||||
@ -23,7 +23,7 @@ overridden_configuration = TurnConfiguration(
|
|||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
||||||
current_directory = pathlib.Path(__file__).parent
|
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')
|
@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'.
|
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 = Mock()
|
||||||
app_get.return_value = app
|
app_get.return_value = app
|
||||||
app.needs_setup.return_value = False
|
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):
|
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)
|
ejabberd.update_turn_configuration(config, managed=managed)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -6,14 +6,14 @@ import logging
|
|||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
import plinth.app
|
import freedombox.app
|
||||||
from freedombox import cfg, frontpage, menu
|
from freedombox import cfg, frontpage, menu
|
||||||
from freedombox.config import DropinConfigs
|
from freedombox.config import DropinConfigs
|
||||||
from freedombox.daemon import Daemon
|
from freedombox.daemon import Daemon
|
||||||
from freedombox.modules.apache.components import Webserver
|
from freedombox.modules.apache.components import Webserver
|
||||||
from freedombox.modules.backups.components import BackupRestore
|
from freedombox.modules.backups.components import BackupRestore
|
||||||
from freedombox.modules.firewall.components import (Firewall,
|
from freedombox.modules.firewall.components import (Firewall,
|
||||||
FirewallLocalProtection)
|
FirewallLocalProtection)
|
||||||
from freedombox.modules.letsencrypt.components import LetsEncrypt
|
from freedombox.modules.letsencrypt.components import LetsEncrypt
|
||||||
from freedombox.package import Packages
|
from freedombox.package import Packages
|
||||||
from freedombox.privileged import service as service_privileged
|
from freedombox.privileged import service as service_privileged
|
||||||
@ -47,7 +47,7 @@ _description = [
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class EmailApp(plinth.app.App):
|
class EmailApp(freedombox.app.App):
|
||||||
"""FreedomBox app for an email server."""
|
"""FreedomBox app for an email server."""
|
||||||
|
|
||||||
app_id = 'email'
|
app_id = 'email'
|
||||||
@ -58,12 +58,12 @@ class EmailApp(plinth.app.App):
|
|||||||
"""Initialize the email app."""
|
"""Initialize the email app."""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
info = plinth.app.Info(app_id=self.app_id, version=self._version,
|
info = freedombox.app.Info(
|
||||||
name=_('Postfix/Dovecot'),
|
app_id=self.app_id, version=self._version,
|
||||||
icon_filename='email', description=_description,
|
name=_('Postfix/Dovecot'), icon_filename='email',
|
||||||
manual_page='Email', clients=manifest.clients,
|
description=_description, manual_page='Email',
|
||||||
tags=manifest.tags,
|
clients=manifest.clients, tags=manifest.tags,
|
||||||
donation_url='https://rspamd.com/support.html')
|
donation_url='https://rspamd.com/support.html')
|
||||||
self.add(info)
|
self.add(info)
|
||||||
|
|
||||||
menu_item = menu.Menu('menu-email', info.name, info.icon_filename,
|
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,
|
def on_domain_added(sender, domain_type, name, description='', services=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""Handle addition of a new domain."""
|
"""Handle addition of a new domain."""
|
||||||
app = plinth.app.App.get('email')
|
app = freedombox.app.App.get('email')
|
||||||
if app.needs_setup():
|
if app.needs_setup():
|
||||||
return
|
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):
|
def on_domain_removed(sender, domain_type, name='', **kwargs):
|
||||||
"""Handle removal of a domain."""
|
"""Handle removal of a domain."""
|
||||||
app = plinth.app.App.get('email')
|
app = freedombox.app.App.get('email')
|
||||||
if app.needs_setup():
|
if app.needs_setup():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ from django.utils.translation import gettext_noop
|
|||||||
|
|
||||||
from freedombox import app
|
from freedombox import app
|
||||||
from freedombox.diagnostic_check import (DiagnosticCheck,
|
from freedombox.diagnostic_check import (DiagnosticCheck,
|
||||||
DiagnosticCheckParameters, Result)
|
DiagnosticCheckParameters, Result)
|
||||||
from freedombox.modules import firewall
|
from freedombox.modules import firewall
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -120,7 +120,7 @@ class Firewall(app.FollowerComponent):
|
|||||||
def diagnose(self) -> _list_type[DiagnosticCheck]:
|
def diagnose(self) -> _list_type[DiagnosticCheck]:
|
||||||
"""Check if the firewall ports are open and only as expected.
|
"""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 = []
|
results = []
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import pytest
|
|||||||
from freedombox.app import App
|
from freedombox.app import App
|
||||||
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
||||||
from freedombox.modules.firewall.components import (Firewall,
|
from freedombox.modules.firewall.components import (Firewall,
|
||||||
FirewallLocalProtection)
|
FirewallLocalProtection)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='empty_firewall_list', autouse=True)
|
@pytest.fixture(name='empty_firewall_list', autouse=True)
|
||||||
@ -42,7 +42,7 @@ def test_init():
|
|||||||
assert firewall.is_external
|
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):
|
def test_port_details(get_port_details):
|
||||||
"""Test retrieving port details for a firewall component."""
|
"""Test retrieving port details for a firewall component."""
|
||||||
return_values = {
|
return_values = {
|
||||||
@ -64,8 +64,8 @@ def test_port_details(get_port_details):
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.firewall.add_service')
|
@patch('freedombox.modules.firewall.add_service')
|
||||||
@patch('plinth.modules.firewall.get_enabled_services')
|
@patch('freedombox.modules.firewall.get_enabled_services')
|
||||||
def test_enable(get_enabled_services, add_service):
|
def test_enable(get_enabled_services, add_service):
|
||||||
"""Test enabling a firewall component."""
|
"""Test enabling a firewall component."""
|
||||||
|
|
||||||
@ -92,9 +92,9 @@ def test_enable(get_enabled_services, add_service):
|
|||||||
add_service.assert_has_calls(calls)
|
add_service.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.firewall.remove_service')
|
@patch('freedombox.modules.firewall.remove_service')
|
||||||
@patch('plinth.modules.firewall.add_service')
|
@patch('freedombox.modules.firewall.add_service')
|
||||||
@patch('plinth.modules.firewall.get_enabled_services')
|
@patch('freedombox.modules.firewall.get_enabled_services')
|
||||||
def test_disable(get_enabled_services, add_service, remove_service):
|
def test_disable(get_enabled_services, add_service, remove_service):
|
||||||
"""Test disabling a firewall component."""
|
"""Test disabling a firewall component."""
|
||||||
Firewall('firewall-1', ports=['test-port1'], is_external=False)
|
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)
|
remove_service.assert_has_calls(calls)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.firewall.get_port_details')
|
@patch('freedombox.modules.firewall.get_port_details')
|
||||||
@patch('plinth.modules.firewall.get_enabled_services')
|
@patch('freedombox.modules.firewall.get_enabled_services')
|
||||||
def test_diagnose(get_enabled_services, get_port_details):
|
def test_diagnose(get_enabled_services, get_port_details):
|
||||||
"""Test diagnosing open/closed firewall ports."""
|
"""Test diagnosing open/closed firewall ports."""
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ def test_local_protection_init():
|
|||||||
assert component.tcp_ports == ['1234', '4567']
|
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):
|
def test_local_protection_enable(add_passthrough):
|
||||||
"""Test enabling local protection component."""
|
"""Test enabling local protection component."""
|
||||||
component = FirewallLocalProtection('test-component', ['1234', '4567'])
|
component = FirewallLocalProtection('test-component', ['1234', '4567'])
|
||||||
@ -246,7 +246,7 @@ def test_local_protection_enable(add_passthrough):
|
|||||||
add_passthrough.assert_has_calls(calls)
|
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):
|
def test_local_protection_disable(remove_passthrough):
|
||||||
"""Test disabling local protection component."""
|
"""Test disabling local protection component."""
|
||||||
component = FirewallLocalProtection('test-component', ['1234', '4567'])
|
component = FirewallLocalProtection('test-component', ['1234', '4567'])
|
||||||
@ -265,7 +265,7 @@ def test_local_protection_disable(remove_passthrough):
|
|||||||
remove_passthrough.assert_has_calls(calls)
|
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):
|
def test_local_protection_setup(enable):
|
||||||
"""Test setting up protection when updating the app."""
|
"""Test setting up protection when updating the app."""
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ REPO_DATA = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged', 'mock_run_as_user')
|
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(),
|
git_installed = pytest.mark.skipif(not pathlib.Path('/usr/bin/git').exists(),
|
||||||
reason='git is not installed')
|
reason='git is not installed')
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ def test_action_create_repo_with_invalid_urls(url):
|
|||||||
keep_ownership=True)
|
keep_ownership=True)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.run')
|
@patch('freedombox.action_utils.run')
|
||||||
def test_setup_git_creentials(run):
|
def test_setup_git_creentials(run):
|
||||||
"""Test that setting up git credentials works."""
|
"""Test that setting up git credentials works."""
|
||||||
url = 'https://user:pass@host.example/path?key=value'
|
url = 'https://user:pass@host.example/path?key=value'
|
||||||
|
|||||||
@ -13,8 +13,8 @@ from django.http.response import Http404
|
|||||||
from freedombox import module_loader
|
from freedombox import module_loader
|
||||||
from freedombox.modules.gitweb import views
|
from freedombox.modules.gitweb import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
|
|
||||||
EXISTING_REPOS = [
|
EXISTING_REPOS = [
|
||||||
{
|
{
|
||||||
@ -38,10 +38,10 @@ EXISTING_REPOS = [
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_gitweb_urls():
|
def fixture_gitweb_urls():
|
||||||
"""Make sure gitweb app's URLs are part of plinth.urls."""
|
"""Make sure gitweb app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.gitweb')
|
modules.append('freedombox.modules.gitweb')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -49,9 +49,9 @@ def fixture_gitweb_urls():
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def gitweb_patch():
|
def gitweb_patch():
|
||||||
"""Patch gitweb."""
|
"""Patch gitweb."""
|
||||||
privileged = 'plinth.modules.gitweb.privileged'
|
privileged = 'freedombox.modules.gitweb.privileged'
|
||||||
with patch('plinth.modules.gitweb.get_repo_list') as get_repo_list, \
|
with patch('freedombox.modules.gitweb.get_repo_list') as get_repo_list, \
|
||||||
patch('plinth.app.App.get') as app_get, \
|
patch('freedombox.app.App.get') as app_get, \
|
||||||
patch(f'{privileged}.create_repo'), \
|
patch(f'{privileged}.create_repo'), \
|
||||||
patch(f'{privileged}.repo_exists') as repo_exists, \
|
patch(f'{privileged}.repo_exists') as repo_exists, \
|
||||||
patch(f'{privileged}.repo_info') as repo_info, \
|
patch(f'{privileged}.repo_info') as repo_info, \
|
||||||
@ -92,7 +92,7 @@ def make_request(request, view, **kwargs):
|
|||||||
|
|
||||||
def test_repos_view(rf):
|
def test_repos_view(rf):
|
||||||
"""Test that a repo list has correct view data."""
|
"""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}):
|
return_value={'is_enabled': True}):
|
||||||
view = views.GitwebAppView.as_view()
|
view = views.GitwebAppView.as_view()
|
||||||
response, _ = make_request(rf.get(''), 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."""
|
"""Test that repo creation failure sends correct error message."""
|
||||||
general_error_message = "An error occurred while creating the repository."
|
general_error_message = "An error occurred while creating the repository."
|
||||||
error_description = 'some error'
|
error_description = 'some error'
|
||||||
with patch('plinth.modules.gitweb.create_repo',
|
with patch('freedombox.modules.gitweb.create_repo',
|
||||||
side_effect=PermissionError(error_description)):
|
side_effect=PermissionError(error_description)):
|
||||||
form_data = {
|
form_data = {
|
||||||
'gitweb-name': 'something_other',
|
'gitweb-name': 'something_other',
|
||||||
@ -193,7 +193,7 @@ def test_clone_repo_view(rf):
|
|||||||
|
|
||||||
def test_clone_repo_missing_remote_view(rf):
|
def test_clone_repo_missing_remote_view(rf):
|
||||||
"""Test that cloning non-existing repo shows correct error message."""
|
"""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):
|
return_value=False):
|
||||||
form_data = {
|
form_data = {
|
||||||
'gitweb-name': 'https://example.com/test.git',
|
'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):
|
def test_edit_repository_no_change_view(rf):
|
||||||
"""Test that not changing any values don't edit the repo."""
|
"""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 = {
|
form_data = {
|
||||||
'gitweb-name': EXISTING_REPOS[0]['name'],
|
'gitweb-name': EXISTING_REPOS[0]['name'],
|
||||||
'gitweb-description': EXISTING_REPOS[0]['description'],
|
'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):
|
def test_edit_repository_failed_view(rf):
|
||||||
"""Test that failed repo editing sends correct error message."""
|
"""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')):
|
side_effect=PermissionError('Error')):
|
||||||
form_data = {
|
form_data = {
|
||||||
'gitweb-name': 'something_other',
|
'gitweb-name': 'something_other',
|
||||||
@ -343,7 +343,7 @@ def test_delete_repository_view(rf):
|
|||||||
def test_delete_repository_fail_view(rf):
|
def test_delete_repository_fail_view(rf):
|
||||||
"""Test that failed repository deletion sends correct error message."""
|
"""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')):
|
side_effect=FileNotFoundError('Error')):
|
||||||
response, messages = make_request(rf.post(''), views.delete,
|
response, messages = make_request(rf.post(''), views.delete,
|
||||||
name=EXISTING_REPOS[0]['name'])
|
name=EXISTING_REPOS[0]['name'])
|
||||||
|
|||||||
@ -24,8 +24,8 @@ from freedombox import cfg, module_loader
|
|||||||
from freedombox.modules import help as help_module
|
from freedombox.modules import help as help_module
|
||||||
from freedombox.modules.help import views
|
from freedombox.modules.help import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
|
|
||||||
|
|
||||||
def _is_page(response):
|
def _is_page(response):
|
||||||
@ -36,14 +36,14 @@ def _is_page(response):
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_app_urls():
|
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 = [
|
urls = [
|
||||||
re_path(r'^apps/$', views.index, name='apps'),
|
re_path(r'^apps/$', views.index, name='apps'),
|
||||||
re_path(r'^system/$', views.index, name='system')
|
re_path(r'^system/$', views.index, name='system')
|
||||||
]
|
]
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=urls):
|
modules, patch('freedombox.urls.urlpatterns', new=urls)):
|
||||||
modules.append('plinth.modules.help')
|
modules.append('freedombox.modules.help')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ def test_contribute_page(requests_get, decompress, apt_cache, rf):
|
|||||||
response.context_data['help'])
|
response.context_data['help'])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.upgrades.views.is_newer_version_available')
|
@patch('freedombox.modules.upgrades.views.is_newer_version_available')
|
||||||
@patch('plinth.modules.upgrades.views.get_os_release')
|
@patch('freedombox.modules.upgrades.views.get_os_release')
|
||||||
def test_about(_get_os_release, _is_newer_version_available, rf):
|
def test_about(_get_os_release, _is_newer_version_available, rf):
|
||||||
"""Test some expected items in about view."""
|
"""Test some expected items in about view."""
|
||||||
about_url = urls.reverse('help:about')
|
about_url = urls.reverse('help:about')
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import copy
|
|||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.views.generic import TemplateView
|
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.middleware import CONTENT_SECURITY_POLICY
|
||||||
from freedombox.modules.names.components import DomainName
|
from freedombox.modules.names.components import DomainName
|
||||||
|
|
||||||
|
|||||||
@ -9,11 +9,11 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import plinth.settings
|
import freedombox.settings
|
||||||
from freedombox.modules.kiwix import privileged
|
from freedombox.modules.kiwix import privileged
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_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 = '''<?xml version="1.0" encoding="UTF-8"?>
|
EMPTY_LIBRARY_CONTENTS = '''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<library version="20110515">
|
<library version="20110515">
|
||||||
@ -40,10 +40,10 @@ def fixture_kiwix_home(tmp_path):
|
|||||||
@pytest.fixture(name='upload_dir')
|
@pytest.fixture(name='upload_dir')
|
||||||
def fixture_upload_dir(tmp_path):
|
def fixture_upload_dir(tmp_path):
|
||||||
"""Overwrite the Django upload path."""
|
"""Overwrite the Django upload path."""
|
||||||
old_value = plinth.settings.FILE_UPLOAD_TEMP_DIR
|
old_value = freedombox.settings.FILE_UPLOAD_TEMP_DIR
|
||||||
plinth.settings.FILE_UPLOAD_TEMP_DIR = tmp_path
|
freedombox.settings.FILE_UPLOAD_TEMP_DIR = tmp_path
|
||||||
yield 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)
|
@pytest.fixture(autouse=True)
|
||||||
|
|||||||
@ -14,18 +14,18 @@ from django.http.response import Http404
|
|||||||
from freedombox import module_loader
|
from freedombox import module_loader
|
||||||
from freedombox.modules.kiwix import views
|
from freedombox.modules.kiwix import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
|
|
||||||
ZIM_ID = 'bc4f8cdf-5626-2b13-3860-0033deddfbea'
|
ZIM_ID = 'bc4f8cdf-5626-2b13-3860-0033deddfbea'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_kiwix_urls():
|
def fixture_kiwix_urls():
|
||||||
"""Make sure kiwix app's URLs are part of plinth.urls."""
|
"""Make sure kiwix app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.kiwix')
|
modules.append('freedombox.modules.kiwix')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -43,8 +43,8 @@ def make_request(request, view, **kwargs):
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def fixture_kiwix_patch():
|
def fixture_kiwix_patch():
|
||||||
"""Patch kiwix methods."""
|
"""Patch kiwix methods."""
|
||||||
with patch(
|
with patch('freedombox.modules.kiwix.privileged.list_packages'
|
||||||
'plinth.modules.kiwix.privileged.list_packages') as list_libraries:
|
) as list_libraries:
|
||||||
list_libraries.return_value = {
|
list_libraries.return_value = {
|
||||||
ZIM_ID: {
|
ZIM_ID: {
|
||||||
'title': 'TestExistingPackage',
|
'title': 'TestExistingPackage',
|
||||||
@ -75,7 +75,7 @@ def add_package_request(rf, file_path):
|
|||||||
return request
|
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):
|
def test_add_package(add_package, file_path, add_package_request):
|
||||||
"""Test that adding content view works."""
|
"""Test that adding content view works."""
|
||||||
response, messages = make_request(add_package_request,
|
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)])
|
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):
|
def test_add_package_failed(add_package, add_package_request):
|
||||||
"""Test that adding content package fails in case of an error."""
|
"""Test that adding content package fails in case of an error."""
|
||||||
add_package.side_effect = RuntimeError('TestError')
|
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.')
|
'Failed to add content package.')
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
def test_delete_package_confirmation_view(_app, rf):
|
def test_delete_package_confirmation_view(_app, rf):
|
||||||
"""Test that deleting content confirmation shows correct title."""
|
"""Test that deleting content confirmation shows correct title."""
|
||||||
response, _ = make_request(rf.get(''), views.delete_package, zim_id=ZIM_ID)
|
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'
|
assert response.context_data['name'] == 'TestExistingPackage'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.kiwix.privileged.delete_package')
|
@patch('freedombox.modules.kiwix.privileged.delete_package')
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
def test_delete_package(_app, delete_package, rf):
|
def test_delete_package(_app, delete_package, rf):
|
||||||
"""Test that deleting a content package works."""
|
"""Test that deleting a content package works."""
|
||||||
response, messages = make_request(rf.post(''), views.delete_package,
|
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)])
|
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):
|
def test_delete_package_error(delete_package, rf):
|
||||||
"""Test that deleting content shows an error when operation fails."""
|
"""Test that deleting content shows an error when operation fails."""
|
||||||
delete_package.side_effect = ValueError('TestError')
|
delete_package.side_effect = ValueError('TestError')
|
||||||
|
|||||||
@ -37,7 +37,7 @@ def fixture_component():
|
|||||||
@pytest.fixture(name='copy_certificate')
|
@pytest.fixture(name='copy_certificate')
|
||||||
def fixture_copy_certificate():
|
def fixture_copy_certificate():
|
||||||
"""Patch and return privileged.copy_certificate call."""
|
"""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:
|
) as copy_certificate:
|
||||||
yield copy_certificate
|
yield copy_certificate
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ def fixture_copy_certificate():
|
|||||||
@pytest.fixture(name='compare_certificate')
|
@pytest.fixture(name='compare_certificate')
|
||||||
def fixture_compare_certificate():
|
def fixture_compare_certificate():
|
||||||
"""Patch and return privileged.compare_certificate call."""
|
"""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:
|
) as compare_certificate:
|
||||||
yield compare_certificate
|
yield compare_certificate
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def fixture_compare_certificate():
|
|||||||
def fixture_get_status():
|
def fixture_get_status():
|
||||||
"""Return patched letsencrypt.get_status() method."""
|
"""Return patched letsencrypt.get_status() method."""
|
||||||
domains = ['valid.example']
|
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 = {
|
get_status.return_value = {
|
||||||
'domains': {
|
'domains': {
|
||||||
domain: {
|
domain: {
|
||||||
@ -70,7 +70,7 @@ def fixture_get_status():
|
|||||||
@pytest.fixture(name='domain_list')
|
@pytest.fixture(name='domain_list')
|
||||||
def fixture_domain_list():
|
def fixture_domain_list():
|
||||||
"""Return patch DomainName.list() method."""
|
"""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:
|
with patch(method) as domain_list:
|
||||||
DomainType._all = {}
|
DomainType._all = {}
|
||||||
DomainType('domain-type-1', 'type-1', 'url1', False)
|
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
|
daemons = daemons if daemons is not None else component.daemons
|
||||||
|
|
||||||
expected_calls = [call(daemon) for daemon in 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(
|
) as try_reload_or_restart, patch(
|
||||||
'plinth.privileged.service.try_restart') as try_restart:
|
'freedombox.privileged.service.try_restart') as try_restart:
|
||||||
yield
|
yield
|
||||||
|
|
||||||
if component.reload_daemons:
|
if component.reload_daemons:
|
||||||
|
|||||||
@ -27,8 +27,8 @@ def test_add_onion_domain():
|
|||||||
assert not on_domain_removed('test', 'domain-type-tor', 'ddddd.onion')
|
assert not on_domain_removed('test', 'domain-type-tor', 'ddddd.onion')
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.letsencrypt.get_status')
|
@patch('freedombox.modules.letsencrypt.get_status')
|
||||||
@patch('plinth.modules.letsencrypt.certificate_obtain')
|
@patch('freedombox.modules.letsencrypt.certificate_obtain')
|
||||||
@pytest.mark.usefixtures('load_cfg')
|
@pytest.mark.usefixtures('load_cfg')
|
||||||
@pytest.mark.parametrize('domain,status_input,obtain,result', [
|
@pytest.mark.parametrize('domain,status_input,obtain,result', [
|
||||||
('domain1.tld', {
|
('domain1.tld', {
|
||||||
@ -59,7 +59,7 @@ def test_add_valid_domain(certificate_obtain, get_status, domain, status_input,
|
|||||||
certificate_obtain.assert_not_called()
|
certificate_obtain.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.letsencrypt.certificate_revoke')
|
@patch('freedombox.modules.letsencrypt.certificate_revoke')
|
||||||
@pytest.mark.usefixtures('load_cfg')
|
@pytest.mark.usefixtures('load_cfg')
|
||||||
@pytest.mark.parametrize('domain,revoke,result', [
|
@pytest.mark.parametrize('domain,revoke,result', [
|
||||||
('domain1.tld', True, True),
|
('domain1.tld', True, True),
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
Test module for Matrix Synapse STUN/TURN configuration.
|
Test module for Matrix Synapse STUN/TURN configuration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from unittest.mock import patch, Mock
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ from freedombox.modules.coturn.components import TurnConfiguration
|
|||||||
from freedombox.modules.matrixsynapse import privileged
|
from freedombox.modules.matrixsynapse import privileged
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_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')
|
@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."""
|
"""Run actions with custom root path."""
|
||||||
privileged.TURN_CONF_PATH = managed_turn_conf_file
|
privileged.TURN_CONF_PATH = managed_turn_conf_file
|
||||||
privileged.OVERRIDDEN_TURN_CONF_PATH = overridden_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
|
yield
|
||||||
|
|
||||||
|
|
||||||
@ -45,13 +45,14 @@ def fixture_test_configuration(managed_turn_conf_file,
|
|||||||
|
|
||||||
Overrides TURN configuration files.
|
Overrides TURN configuration files.
|
||||||
"""
|
"""
|
||||||
matrixsynapse = 'plinth.modules.matrixsynapse'
|
matrixsynapse = 'freedombox.modules.matrixsynapse'
|
||||||
with (patch(f'{matrixsynapse}.privileged.TURN_CONF_PATH',
|
with (patch(f'{matrixsynapse}.privileged.TURN_CONF_PATH',
|
||||||
managed_turn_conf_file),
|
managed_turn_conf_file),
|
||||||
patch(f'{matrixsynapse}.privileged.OVERRIDDEN_TURN_CONF_PATH',
|
patch(f'{matrixsynapse}.privileged.OVERRIDDEN_TURN_CONF_PATH',
|
||||||
overridden_turn_conf_file),
|
overridden_turn_conf_file),
|
||||||
patch(f'{matrixsynapse}.is_setup', return_value=True),
|
patch(f'{matrixsynapse}.is_setup',
|
||||||
patch('plinth.app.App.get') as app_get):
|
return_value=True), patch('freedombox.app.App.get') as
|
||||||
|
app_get):
|
||||||
app = Mock()
|
app = Mock()
|
||||||
app_get.return_value = app
|
app_get.return_value = app
|
||||||
app.needs_setup.return_value = False
|
app.needs_setup.return_value = False
|
||||||
@ -72,13 +73,12 @@ updated_coturn_configuration = TurnConfiguration(
|
|||||||
|
|
||||||
|
|
||||||
def _set_managed_configuration(config=coturn_configuration):
|
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)
|
matrixsynapse.update_turn_configuration(config)
|
||||||
|
|
||||||
|
|
||||||
def _set_overridden_configuration(
|
def _set_overridden_configuration(config=overridden_configuration):
|
||||||
config=overridden_configuration):
|
with patch('freedombox.action_utils.service_try_restart'):
|
||||||
with patch('plinth.action_utils.service_try_restart'):
|
|
||||||
matrixsynapse.update_turn_configuration(config, managed=False)
|
matrixsynapse.update_turn_configuration(config, managed=False)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from freedombox.modules.mediawiki import privileged
|
|||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
||||||
current_directory = pathlib.Path(__file__).parent
|
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)
|
@pytest.fixture(name='test_configuration', autouse=True)
|
||||||
@ -25,8 +25,9 @@ def fixture_test_configuration(tmp_path):
|
|||||||
settings_file_name = 'FreedomBoxSettings.php'
|
settings_file_name = 'FreedomBoxSettings.php'
|
||||||
conf_file = tmp_path / settings_file_name
|
conf_file = tmp_path / settings_file_name
|
||||||
conf_file.touch()
|
conf_file.touch()
|
||||||
with (patch('plinth.modules.mediawiki.USER_CONFIG_FILE', conf_file),
|
with (patch('freedombox.modules.mediawiki.USER_CONFIG_FILE', conf_file),
|
||||||
patch('plinth.modules.mediawiki.privileged.CONF_FILE', conf_file)):
|
patch('freedombox.modules.mediawiki.privileged.CONF_FILE',
|
||||||
|
conf_file)):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,16 +10,16 @@ from django.contrib.messages.storage.fallback import FallbackStorage
|
|||||||
from freedombox import module_loader
|
from freedombox import module_loader
|
||||||
from freedombox.modules.miniflux import views
|
from freedombox.modules.miniflux import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_miniflux_urls():
|
def fixture_miniflux_urls():
|
||||||
"""Make sure Miniflux app's URLs are part of plinth.urls."""
|
"""Make sure Miniflux app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.miniflux')
|
modules.append('freedombox.modules.miniflux')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def test_create_admin_user_view(rf):
|
|||||||
assert response.status_code == 200
|
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):
|
def test_create_admin_user_form_valid(create_admin_user, rf):
|
||||||
"""Test that the create admin user form is valid and redirects."""
|
"""Test that the create admin user form is valid and redirects."""
|
||||||
form_data = {
|
form_data = {
|
||||||
@ -99,7 +99,7 @@ def test_password_too_short(rf):
|
|||||||
0] == 'Ensure this value has at least 6 characters (it has 4).'
|
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):
|
def test_recreate_existing_user(create_admin_user, rf):
|
||||||
"""Test that trying to recreate an existing user fails."""
|
"""Test that trying to recreate an existing user fails."""
|
||||||
create_admin_user.side_effect = Exception(
|
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):
|
def test_reset_user_password_form_valid(reset_user_password, rf):
|
||||||
"""Test that the reset user password form is valid and redirects."""
|
"""Test that the reset user password form is valid and redirects."""
|
||||||
reset_user_password.return_value = 'Password changed!'
|
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'
|
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):
|
def test_reset_user_password_for_invalid_user(reset_user_password, rf):
|
||||||
"""Test that the resetting user password for an invalid user fails."""
|
"""Test that the resetting user password for an invalid user fails."""
|
||||||
reset_user_password.side_effect = Exception('user not found')
|
reset_user_password.side_effect = Exception('user not found')
|
||||||
|
|||||||
@ -50,7 +50,7 @@ def test_get_client_secret(openid_connect):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@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):
|
def test_setup(list_names, openid_connect):
|
||||||
"""Test creating a DB object."""
|
"""Test creating a DB object."""
|
||||||
list_names.return_value = ('a.example', 'b.example')
|
list_names.return_value = ('a.example', 'b.example')
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import gettext as _
|
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 import names, privacy
|
||||||
from freedombox.modules.privacy.forms import PrivacyForm
|
from freedombox.modules.privacy.forms import PrivacyForm
|
||||||
from freedombox.views import AppView
|
from freedombox.views import AppView
|
||||||
|
|||||||
@ -14,8 +14,8 @@ from django.contrib.messages.storage.fallback import FallbackStorage
|
|||||||
from freedombox import module_loader
|
from freedombox import module_loader
|
||||||
from freedombox.modules.samba import views
|
from freedombox.modules.samba import views
|
||||||
|
|
||||||
# For all tests, use plinth.urls instead of urls configured for testing
|
# For all tests, use freedombox.urls instead of urls configured for testing
|
||||||
pytestmark = pytest.mark.urls('plinth.urls')
|
pytestmark = pytest.mark.urls('freedombox.urls')
|
||||||
setfacl_path = pathlib.Path('/usr/bin/setfacl')
|
setfacl_path = pathlib.Path('/usr/bin/setfacl')
|
||||||
|
|
||||||
USERS = {"access_ok": ["testuser"], 'password_re_enter_needed': []}
|
USERS = {"access_ok": ["testuser"], 'password_re_enter_needed': []}
|
||||||
@ -62,10 +62,10 @@ SHARES = [
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='module')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_samba_urls():
|
def fixture_samba_urls():
|
||||||
"""Make sure samba app's URLs are part of plinth.urls."""
|
"""Make sure samba app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.samba')
|
modules.append('freedombox.modules.samba')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -73,9 +73,10 @@ def fixture_samba_urls():
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def samba_patch_privileged():
|
def samba_patch_privileged():
|
||||||
"""Patch privileged scripts runner."""
|
"""Patch privileged scripts runner."""
|
||||||
with patch('plinth.modules.samba.privileged.get_shares') as get_shares, \
|
with (patch('freedombox.modules.samba.privileged.get_shares')
|
||||||
patch('plinth.modules.samba.privileged.delete_share'), \
|
as get_shares,
|
||||||
patch('plinth.modules.samba.privileged.add_share'):
|
patch('freedombox.modules.samba.privileged.delete_share'),
|
||||||
|
patch('freedombox.modules.samba.privileged.add_share')):
|
||||||
get_shares.return_value = SHARES
|
get_shares.return_value = SHARES
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -92,11 +93,11 @@ def make_request(request, view, **kwargs):
|
|||||||
|
|
||||||
def test_samba_shares_view(rf):
|
def test_samba_shares_view(rf):
|
||||||
"""Test that a share list has correct view data."""
|
"""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}),
|
return_value={'is_enabled': True}),
|
||||||
patch('plinth.modules.samba.get_users', return_value=USERS),
|
patch('freedombox.modules.samba.get_users', return_value=USERS),
|
||||||
patch('plinth.modules.storage.get_mounts', return_value=DISKS),
|
patch('freedombox.modules.storage.get_mounts', return_value=DISKS),
|
||||||
patch('plinth.views.AppView.app', return_value=None)):
|
patch('freedombox.views.AppView.app', return_value=None)):
|
||||||
view = views.SambaAppView.as_view()
|
view = views.SambaAppView.as_view()
|
||||||
response, _ = make_request(rf.get(''), 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'}
|
form_data = {'filesystem_type': 'ext4', 'open_share': 'enable'}
|
||||||
mount_point = urllib.parse.quote('/')
|
mount_point = urllib.parse.quote('/')
|
||||||
error_message = 'Sharing failed'
|
error_message = 'Sharing failed'
|
||||||
with patch('plinth.modules.samba.add_share',
|
with patch('freedombox.modules.samba.add_share',
|
||||||
side_effect=RuntimeError(error_message)):
|
side_effect=RuntimeError(error_message)):
|
||||||
response, messages = make_request(rf.post('', data=form_data),
|
response, messages = make_request(rf.post('', data=form_data),
|
||||||
views.share, mount_point=mount_point)
|
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'}
|
form_data = {'filesystem_type': 'ext4', 'open_share': 'disable'}
|
||||||
mount_point = urllib.parse.quote('/')
|
mount_point = urllib.parse.quote('/')
|
||||||
error_message = 'Unsharing failed'
|
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)):
|
side_effect=RuntimeError(error_message)):
|
||||||
response, messages = make_request(rf.post('', data=form_data),
|
response, messages = make_request(rf.post('', data=form_data),
|
||||||
views.share, mount_point=mount_point)
|
views.share, mount_point=mount_point)
|
||||||
|
|||||||
@ -32,7 +32,7 @@ def _is_container():
|
|||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged', 'mock_run_as_user')
|
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(),
|
skip_if_container = pytest.mark.skipif(_is_container(),
|
||||||
reason='running inside a container')
|
reason='running inside a container')
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ from django.core.exceptions import ValidationError
|
|||||||
from freedombox.modules.tor import forms, utils
|
from freedombox.modules.tor import forms, utils
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
||||||
def test_get_status(_app_get):
|
def test_get_status(_app_get):
|
||||||
"""Test that get_status does not raise any unhandled exceptions.
|
"""Test that get_status does not raise any unhandled exceptions.
|
||||||
|
|||||||
@ -22,7 +22,7 @@ class TestTorProxy:
|
|||||||
utils.is_apt_transport_tor_enabled()
|
utils.is_apt_transport_tor_enabled()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
@pytest.mark.usefixtures('needs_root', 'load_cfg')
|
||||||
def test_get_status(_app_get):
|
def test_get_status(_app_get):
|
||||||
"""Test that get_status does not raise any unhandled exceptions.
|
"""Test that get_status does not raise any unhandled exceptions.
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from aptsources import sourceslist
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.utils.translation import gettext_noop
|
from django.utils.translation import gettext_noop
|
||||||
|
|
||||||
import plinth
|
import freedombox
|
||||||
from freedombox import action_utils
|
from freedombox import action_utils
|
||||||
from freedombox import app as app_module
|
from freedombox import app as app_module
|
||||||
from freedombox import cfg, glib, kvstore, menu, package
|
from freedombox import cfg, glib, kvstore, menu, package
|
||||||
@ -111,7 +111,7 @@ class UpgradesApp(app_module.App):
|
|||||||
from freedombox.notification import Notification
|
from freedombox.notification import Notification
|
||||||
try:
|
try:
|
||||||
note = Notification.get('upgrades-new-release')
|
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
|
# User already has notification for update to this version. It
|
||||||
# may be dismissed or not yet dismissed
|
# may be dismissed or not yet dismissed
|
||||||
return
|
return
|
||||||
@ -124,7 +124,7 @@ class UpgradesApp(app_module.App):
|
|||||||
dismiss = True
|
dismiss = True
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'version': plinth.__version__,
|
'version': freedombox.__version__,
|
||||||
'app_name': 'translate:' + gettext_noop('Software Update'),
|
'app_name': 'translate:' + gettext_noop('Software Update'),
|
||||||
'app_icon': 'fa-refresh'
|
'app_icon': 'fa-refresh'
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,7 +65,7 @@ deb https://deb.debian.org/debian bookwormish main
|
|||||||
sources_list = tmp_path / 'sources.list'
|
sources_list = tmp_path / 'sources.list'
|
||||||
temp_sources_list = tmp_path / 'sources.list.fbx-dist-upgrade'
|
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), \
|
with patch(f'{module}.sources_list', sources_list), \
|
||||||
patch(f'{module}.temp_sources_list', temp_sources_list):
|
patch(f'{module}.temp_sources_list', temp_sources_list):
|
||||||
sources_list.write_text(original)
|
sources_list.write_text(original)
|
||||||
@ -81,12 +81,13 @@ deb https://deb.debian.org/debian bookwormish main
|
|||||||
|
|
||||||
|
|
||||||
@patch('datetime.datetime')
|
@patch('datetime.datetime')
|
||||||
@patch('plinth.modules.upgrades.utils.get_current_release')
|
@patch('freedombox.modules.upgrades.utils.get_current_release')
|
||||||
@patch('plinth.modules.upgrades.distupgrade.utils.get_sources_list_codename')
|
@patch(
|
||||||
@patch('plinth.action_utils.service_is_running')
|
'freedombox.modules.upgrades.distupgrade.utils.get_sources_list_codename')
|
||||||
@patch('plinth.modules.upgrades.utils.is_sufficient_free_space')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
@patch('plinth.modules.upgrades.is_dist_upgrade_enabled')
|
@patch('freedombox.modules.upgrades.utils.is_sufficient_free_space')
|
||||||
@patch('plinth.modules.upgrades.utils.check_auto')
|
@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,
|
def test_get_status(check_auto, is_dist_upgrade_enabled,
|
||||||
is_sufficient_free_space, service_is_running,
|
is_sufficient_free_space, service_is_running,
|
||||||
get_sources_list_codename, get_current_release, datetime):
|
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('subprocess.run')
|
||||||
@patch('plinth.modules.snapshot.is_apt_snapshots_enabled')
|
@patch('freedombox.modules.snapshot.is_apt_snapshots_enabled')
|
||||||
@patch('plinth.modules.snapshot.is_supported')
|
@patch('freedombox.modules.snapshot.is_supported')
|
||||||
def test_snapshot_run_and_disable(is_supported, is_apt_snapshots_enabled, run):
|
def test_snapshot_run_and_disable(is_supported, is_apt_snapshots_enabled, run):
|
||||||
"""Test taking a snapshot."""
|
"""Test taking a snapshot."""
|
||||||
is_supported.return_value = False
|
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('freedombox.action_utils.service_enable')
|
||||||
@patch('plinth.action_utils.service_disable')
|
@patch('freedombox.action_utils.service_disable')
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
def test_services_disable(service_is_running, service_disable, service_enable):
|
def test_services_disable(service_is_running, service_disable, service_enable):
|
||||||
"""Test that disabling services works."""
|
"""Test that disabling services works."""
|
||||||
service_is_running.return_value = False
|
service_is_running.return_value = False
|
||||||
@ -275,8 +276,8 @@ def test_apt_hold_packages(run, tmp_path):
|
|||||||
|
|
||||||
hold_flag = tmp_path / 'flag'
|
hold_flag = tmp_path / 'flag'
|
||||||
run.side_effect = _run
|
run.side_effect = _run
|
||||||
with patch('plinth.action_utils.apt_hold_flag', hold_flag), \
|
with patch('freedombox.action_utils.apt_hold_flag', hold_flag), \
|
||||||
patch('plinth.modules.upgrades.distupgrade.PACKAGES_WITH_PROMPTS',
|
patch('freedombox.modules.upgrades.distupgrade.PACKAGES_WITH_PROMPTS',
|
||||||
['package1', 'package2']):
|
['package1', 'package2']):
|
||||||
with distupgrade._apt_hold_packages():
|
with distupgrade._apt_hold_packages():
|
||||||
assert hold_flag.exists()
|
assert hold_flag.exists()
|
||||||
@ -311,10 +312,11 @@ def test_apt_hold_packages(run, tmp_path):
|
|||||||
assert run.call_args_list == expected_call
|
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):
|
def test_debconf_set_selections(debconf_set_selections):
|
||||||
"""Test that setting debconf selections works."""
|
"""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, []):
|
with patch(selections, []):
|
||||||
distupgrade._debconf_set_selections()
|
distupgrade._debconf_set_selections()
|
||||||
debconf_set_selections.assert_not_called()
|
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'])
|
['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):
|
def test_packages_remove_obsolete(apt_run):
|
||||||
"""Test that obsolete packages are removed."""
|
"""Test that obsolete packages are removed."""
|
||||||
distupgrade._packages_remove_obsolete()
|
distupgrade._packages_remove_obsolete()
|
||||||
apt_run.assert_not_called() # No obsolete package to remove currently.
|
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']):
|
['searx']):
|
||||||
distupgrade._packages_remove_obsolete()
|
distupgrade._packages_remove_obsolete()
|
||||||
apt_run.assert_called_with(['remove', 'searx'])
|
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):
|
def test_apt_update(apt_run):
|
||||||
"""Test that apt update works."""
|
"""Test that apt update works."""
|
||||||
distupgrade._apt_update()
|
distupgrade._apt_update()
|
||||||
apt_run.assert_called_with(['update'])
|
apt_run.assert_called_with(['update'])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.modules.upgrades.distupgrade._apt_run')
|
@patch('freedombox.modules.upgrades.distupgrade._apt_run')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_apt_fix(run, apt_run):
|
def test_apt_fix(run, apt_run):
|
||||||
"""Test that apt fixes work."""
|
"""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'])]
|
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):
|
def test_apt_autoremove(apt_run):
|
||||||
"""Test that apt autoremove works."""
|
"""Test that apt autoremove works."""
|
||||||
distupgrade._apt_autoremove()
|
distupgrade._apt_autoremove()
|
||||||
apt_run.assert_called_with(['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):
|
def test_apt_full_upgrade(apt_run):
|
||||||
"""Test that apt full upgrade works."""
|
"""Test that apt full upgrade works."""
|
||||||
apt_run.return_value = 0
|
apt_run.return_value = 0
|
||||||
@ -384,7 +386,7 @@ def test_unatteneded_upgrades_run(run):
|
|||||||
check=False)
|
check=False)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_restart')
|
@patch('freedombox.action_utils.service_restart')
|
||||||
def test_freedombox_restart(service_restart):
|
def test_freedombox_restart(service_restart):
|
||||||
"""Test that restarting freedombox service works."""
|
"""Test that restarting freedombox service works."""
|
||||||
distupgrade._freedombox_restart()
|
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 = tmp_path / 'sources.list.fbx-dist-upgrade'
|
||||||
temp_sources_list.write_text('after')
|
temp_sources_list.write_text('after')
|
||||||
|
|
||||||
module = 'plinth.modules.upgrades.distupgrade'
|
module = 'freedombox.modules.upgrades.distupgrade'
|
||||||
with patch(f'{module}.sources_list', sources_list), \
|
with patch(f'{module}.sources_list', sources_list), \
|
||||||
patch(f'{module}.temp_sources_list', temp_sources_list):
|
patch(f'{module}.temp_sources_list', temp_sources_list):
|
||||||
distupgrade.on_complete()
|
distupgrade.on_complete()
|
||||||
|
|||||||
@ -46,7 +46,7 @@ deb http://deb.debian.org/debian trixie main
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
sources_list = tmp_path / 'sources.list'
|
sources_list = tmp_path / 'sources.list'
|
||||||
module = 'plinth.modules.upgrades.utils'
|
module = 'freedombox.modules.upgrades.utils'
|
||||||
with patch(f'{module}.sources_list', sources_list):
|
with patch(f'{module}.sources_list', sources_list):
|
||||||
sources_list.write_text(list1)
|
sources_list.write_text(list1)
|
||||||
assert utils.get_sources_list_codename() == 'bookworm'
|
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')
|
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):
|
def test_is_distribution_unstable(get_sources_list_codename):
|
||||||
"""Test that checking for unstable distribution works."""
|
"""Test that checking for unstable distribution works."""
|
||||||
get_sources_list_codename.return_value = 'unstable'
|
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()
|
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):
|
def test_is_distribution_rolling(get_current_release):
|
||||||
"""Test that checking for testing/unstable distribution works."""
|
"""Test that checking for testing/unstable distribution works."""
|
||||||
for value in ['unstable', 'testing', 'n/a']:
|
for value in ['unstable', 'testing', 'n/a']:
|
||||||
|
|||||||
@ -18,8 +18,8 @@ from django.utils.deconstruct import deconstructible
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
|
||||||
import plinth.forms
|
import freedombox.forms
|
||||||
import plinth.modules.ssh.privileged as ssh_privileged
|
import freedombox.modules.ssh.privileged as ssh_privileged
|
||||||
from freedombox.modules import first_boot
|
from freedombox.modules import first_boot
|
||||||
from freedombox.utils import is_user_admin
|
from freedombox.utils import is_user_admin
|
||||||
from freedombox.views import messages_error
|
from freedombox.views import messages_error
|
||||||
@ -181,7 +181,8 @@ class PasswordConfirmForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
|
class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
|
||||||
GroupsFieldMixin, plinth.forms.LanguageSelectionFormMixin,
|
GroupsFieldMixin,
|
||||||
|
freedombox.forms.LanguageSelectionFormMixin,
|
||||||
PasswordConfirmForm, UserCreationForm):
|
PasswordConfirmForm, UserCreationForm):
|
||||||
"""Custom user create form.
|
"""Custom user create form.
|
||||||
|
|
||||||
@ -190,7 +191,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
|
|||||||
|
|
||||||
username = USERNAME_FIELD
|
username = USERNAME_FIELD
|
||||||
|
|
||||||
language = plinth.forms.LanguageSelectionFormMixin.language
|
language = freedombox.forms.LanguageSelectionFormMixin.language
|
||||||
|
|
||||||
class Meta(UserCreationForm.Meta):
|
class Meta(UserCreationForm.Meta):
|
||||||
"""Metadata to control automatic form building."""
|
"""Metadata to control automatic form building."""
|
||||||
@ -198,7 +199,7 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
|
|||||||
fields = ('username', 'email', 'password1', 'password2', 'groups',
|
fields = ('username', 'email', 'password1', 'password2', 'groups',
|
||||||
'language', 'confirm_password')
|
'language', 'confirm_password')
|
||||||
widgets = {
|
widgets = {
|
||||||
'groups': plinth.forms.CheckboxSelectMultiple(),
|
'groups': freedombox.forms.CheckboxSelectMultiple(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, request, *args, **kwargs):
|
def __init__(self, request, *args, **kwargs):
|
||||||
@ -254,7 +255,8 @@ class CreateUserForm(ValidNewUsernameCheckMixin, EmailFieldMixin,
|
|||||||
|
|
||||||
class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm,
|
class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm,
|
||||||
EmailFieldMixin, GroupsFieldMixin,
|
EmailFieldMixin, GroupsFieldMixin,
|
||||||
plinth.forms.LanguageSelectionFormMixin, forms.ModelForm):
|
freedombox.forms.LanguageSelectionFormMixin,
|
||||||
|
forms.ModelForm):
|
||||||
"""When user info is changed, also updates LDAP user."""
|
"""When user info is changed, also updates LDAP user."""
|
||||||
|
|
||||||
username = USERNAME_FIELD
|
username = USERNAME_FIELD
|
||||||
@ -267,7 +269,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm,
|
|||||||
'line. Blank lines and lines starting with # will be '
|
'line. Blank lines and lines starting with # will be '
|
||||||
'ignored.'))
|
'ignored.'))
|
||||||
|
|
||||||
language = plinth.forms.LanguageSelectionFormMixin.language
|
language = freedombox.forms.LanguageSelectionFormMixin.language
|
||||||
|
|
||||||
delete = forms.BooleanField(
|
delete = forms.BooleanField(
|
||||||
label=gettext_lazy('Delete user'), required=False,
|
label=gettext_lazy('Delete user'), required=False,
|
||||||
@ -283,7 +285,7 @@ class UserUpdateForm(ValidNewUsernameCheckMixin, PasswordConfirmForm,
|
|||||||
'is_active', 'delete', 'confirm_password')
|
'is_active', 'delete', 'confirm_password')
|
||||||
model = User
|
model = User
|
||||||
widgets = {
|
widgets = {
|
||||||
'groups': plinth.forms.CheckboxSelectMultipleWithReadOnly(),
|
'groups': freedombox.forms.CheckboxSelectMultipleWithReadOnly(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, request, username, *args, **kwargs):
|
def __init__(self, request, username, *args, **kwargs):
|
||||||
|
|||||||
@ -39,7 +39,8 @@ pytestmark: list[pytest.MarkDecorator] = [
|
|||||||
pytest.mark.skipif(not _is_ldap_set_up(), reason='LDAP is not configured')
|
pytest.mark.skipif(not _is_ldap_set_up(), reason='LDAP is not configured')
|
||||||
]
|
]
|
||||||
privileged_modules_to_mock = [
|
privileged_modules_to_mock = [
|
||||||
'plinth.modules.users.privileged', 'plinth.modules.security.privileged'
|
'freedombox.modules.users.privileged',
|
||||||
|
'freedombox.modules.security.privileged'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,17 +16,17 @@ from freedombox.modules.users import views
|
|||||||
|
|
||||||
from ..components import UsersAndGroups
|
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
|
# 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')
|
@pytest.fixture(autouse=True, scope='module')
|
||||||
def fixture_users_urls():
|
def fixture_users_urls():
|
||||||
"""Make sure users app's URLs are part of plinth.urls."""
|
"""Make sure users app's URLs are part of freedombox.urls."""
|
||||||
with patch('plinth.module_loader._modules_to_load', new=[]) as modules, \
|
with (patch('freedombox.module_loader._modules_to_load', new=[]) as
|
||||||
patch('plinth.urls.urlpatterns', new=[]):
|
modules, patch('freedombox.urls.urlpatterns', new=[])):
|
||||||
modules.append('plinth.modules.users')
|
modules.append('freedombox.modules.users')
|
||||||
module_loader.include_urls()
|
module_loader.include_urls()
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ def module_patch():
|
|||||||
UsersAndGroups('users-and-groups-minetest',
|
UsersAndGroups('users-and-groups-minetest',
|
||||||
reserved_usernames=['debian-minetest'])
|
reserved_usernames=['debian-minetest'])
|
||||||
|
|
||||||
privileged = 'plinth.modules.users.privileged'
|
privileged = 'freedombox.modules.users.privileged'
|
||||||
with patch('pwd.getpwall', return_value=pwd_users), \
|
with patch('pwd.getpwall', return_value=pwd_users), \
|
||||||
patch(f'{privileged}.create_user'), \
|
patch(f'{privileged}.create_user'), \
|
||||||
patch(f'{privileged}.add_user_to_group'), \
|
patch(f'{privileged}.add_user_to_group'), \
|
||||||
@ -50,8 +50,8 @@ def module_patch():
|
|||||||
patch(f'{privileged}.set_user_status'), \
|
patch(f'{privileged}.set_user_status'), \
|
||||||
patch(f'{privileged}.rename_user'), \
|
patch(f'{privileged}.rename_user'), \
|
||||||
patch(f'{privileged}.get_group_users') as get_group_users, \
|
patch(f'{privileged}.get_group_users') as get_group_users, \
|
||||||
patch('plinth.modules.ssh.privileged.set_keys'), \
|
patch('freedombox.modules.ssh.privileged.set_keys'), \
|
||||||
patch('plinth.modules.ssh.privileged.get_keys') as get_keys, \
|
patch('freedombox.modules.ssh.privileged.get_keys') as get_keys, \
|
||||||
patch(f'{privileged}.get_user_groups') as get_user_groups, \
|
patch(f'{privileged}.get_user_groups') as get_user_groups, \
|
||||||
patch(f'{privileged}.remove_user'):
|
patch(f'{privileged}.remove_user'):
|
||||||
get_group_users.return_value = ['admin']
|
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
|
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), \
|
return_value=as_admin), \
|
||||||
patch('plinth.modules.users.views.is_user_admin',
|
patch('freedombox.modules.users.views.is_user_admin',
|
||||||
return_value=as_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)
|
response = view(request, **kwargs)
|
||||||
|
|
||||||
@ -85,9 +85,9 @@ def make_request(request, view, as_admin=True, **kwargs):
|
|||||||
|
|
||||||
def test_users_list_view(rf):
|
def test_users_list_view(rf):
|
||||||
"""Test users list view has correct view data."""
|
"""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}),
|
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()
|
view = views.UserList.as_view()
|
||||||
response, messages = make_request(rf.get('/'), view)
|
response, messages = make_request(rf.get('/'), view)
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ from fido2 import webauthn
|
|||||||
from fido2.server import Fido2Server
|
from fido2.server import Fido2Server
|
||||||
from fido2.webauthn import AttestedCredentialData, AuthenticationResponse
|
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 import translation
|
||||||
from freedombox.models import UserPasskey
|
from freedombox.models import UserPasskey
|
||||||
from freedombox.modules import first_boot
|
from freedombox.modules import first_boot
|
||||||
|
|||||||
@ -11,10 +11,10 @@ import apt.cache
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.utils.translation import gettext_lazy, gettext_noop
|
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 import app as app_module
|
||||||
from freedombox.diagnostic_check import (DiagnosticCheck,
|
from freedombox.diagnostic_check import (DiagnosticCheck,
|
||||||
DiagnosticCheckParameters, Result)
|
DiagnosticCheckParameters, Result)
|
||||||
from freedombox.errors import MissingPackageError
|
from freedombox.errors import MissingPackageError
|
||||||
from freedombox.utils import format_lazy
|
from freedombox.utils import format_lazy
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from typing import Union
|
|||||||
import apt
|
import apt
|
||||||
from django.utils.translation import gettext_noop
|
from django.utils.translation import gettext_noop
|
||||||
|
|
||||||
import plinth
|
import freedombox
|
||||||
from freedombox import app as app_module
|
from freedombox import app as app_module
|
||||||
from freedombox.diagnostic_check import Result
|
from freedombox.diagnostic_check import Result
|
||||||
from freedombox.errors import MissingPackageError
|
from freedombox.errors import MissingPackageError
|
||||||
@ -443,7 +443,7 @@ class ForceUpgrader():
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the force upgrader."""
|
"""Initialize the force upgrader."""
|
||||||
if plinth.cfg.develop:
|
if freedombox.cfg.develop:
|
||||||
self.UPGRADE_ATTEMPT_WAIT_SECONDS = 10
|
self.UPGRADE_ATTEMPT_WAIT_SECONDS = 10
|
||||||
|
|
||||||
def on_package_cache_updated(self):
|
def on_package_cache_updated(self):
|
||||||
@ -724,7 +724,7 @@ class DpkgHandler:
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize the dpkg handler."""
|
"""Initialize the dpkg handler."""
|
||||||
if plinth.cfg.develop:
|
if freedombox.cfg.develop:
|
||||||
self.HANDLE_ATTEMPT_WAIT_SECONDS = 10
|
self.HANDLE_ATTEMPT_WAIT_SECONDS = 10
|
||||||
|
|
||||||
def on_dpkg_invoked(self) -> None:
|
def on_dpkg_invoked(self) -> None:
|
||||||
|
|||||||
@ -13,7 +13,7 @@ from freedombox import cfg
|
|||||||
|
|
||||||
@pytest.fixture(name='shortcuts_file')
|
@pytest.fixture(name='shortcuts_file')
|
||||||
def fixture_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):
|
def setter(file_name):
|
||||||
path = pathlib.Path(__file__).parent / 'data' / 'shortcuts'
|
path = pathlib.Path(__file__).parent / 'data' / 'shortcuts'
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
|
|
||||||
from splinter import Browser
|
from splinter import Browser
|
||||||
|
|
||||||
from plinth import app as app_module, module_loader
|
from freedombox import app as app_module
|
||||||
from plinth.tests.functional import app_enable, install, login
|
from freedombox import module_loader
|
||||||
|
from freedombox.tests.functional import app_enable, install, login
|
||||||
|
|
||||||
module_loader.load_modules()
|
module_loader.load_modules()
|
||||||
app_module.apps_init()
|
app_module.apps_init()
|
||||||
|
|||||||
@ -12,13 +12,15 @@ from unittest.mock import Mock, call, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freedombox.action_utils import (get_addresses, get_hostname,
|
from freedombox.action_utils import (get_addresses, get_hostname,
|
||||||
is_systemd_running, move_uploaded_file, run,
|
is_systemd_running, move_uploaded_file,
|
||||||
run_as_user, service_action, service_disable,
|
run, run_as_user, service_action,
|
||||||
service_enable, service_is_enabled,
|
service_disable, service_enable,
|
||||||
service_is_running, service_reload,
|
service_is_enabled, service_is_running,
|
||||||
service_restart, service_start, service_stop,
|
service_reload, service_restart,
|
||||||
service_try_reload_or_restart,
|
service_start, service_stop,
|
||||||
service_try_restart, service_unmask, umask)
|
service_try_reload_or_restart,
|
||||||
|
service_try_restart, service_unmask,
|
||||||
|
umask)
|
||||||
|
|
||||||
UNKNOWN = 'unknowndeamon.service'
|
UNKNOWN = 'unknowndeamon.service'
|
||||||
UNKNOWN_SOCKET = 'unknowndeamon.socket'
|
UNKNOWN_SOCKET = 'unknowndeamon.socket'
|
||||||
@ -75,7 +77,7 @@ def test_service_enable_and_disable():
|
|||||||
service_enable(UNKNOWN)
|
service_enable(UNKNOWN)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_action')
|
@patch('freedombox.action_utils.service_action')
|
||||||
@systemd_installed
|
@systemd_installed
|
||||||
def test_service_start(mock):
|
def test_service_start(mock):
|
||||||
"""Test staring a service."""
|
"""Test staring a service."""
|
||||||
@ -87,7 +89,7 @@ def test_service_start(mock):
|
|||||||
mock.mock_calls = [call(UNKNOWN, 'start', check=True)]
|
mock.mock_calls = [call(UNKNOWN, 'start', check=True)]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_action')
|
@patch('freedombox.action_utils.service_action')
|
||||||
@systemd_installed
|
@systemd_installed
|
||||||
def test_service_stop(mock):
|
def test_service_stop(mock):
|
||||||
"""Test stopping a service."""
|
"""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
|
@systemd_installed
|
||||||
def test_service_restart(mock):
|
def test_service_restart(mock):
|
||||||
"""Test restaring a service."""
|
"""Test restaring a service."""
|
||||||
@ -122,7 +124,7 @@ def test_service_restart(mock):
|
|||||||
assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)]
|
assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_action')
|
@patch('freedombox.action_utils.service_action')
|
||||||
@systemd_installed
|
@systemd_installed
|
||||||
def test_service_try_restart(mock):
|
def test_service_try_restart(mock):
|
||||||
"""Test try-restaring a service."""
|
"""Test try-restaring a service."""
|
||||||
@ -138,7 +140,7 @@ def test_service_try_restart(mock):
|
|||||||
assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)]
|
assert mock.mock_calls == [call(UNKNOWN, 'stop', check=False)]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_action')
|
@patch('freedombox.action_utils.service_action')
|
||||||
@systemd_installed
|
@systemd_installed
|
||||||
def test_service_reload(mock):
|
def test_service_reload(mock):
|
||||||
"""Test reloading a service."""
|
"""Test reloading a service."""
|
||||||
@ -154,7 +156,7 @@ def test_service_reload(mock):
|
|||||||
assert mock.mock_calls == [call(UNKNOWN, 'reload', check=False)]
|
assert mock.mock_calls == [call(UNKNOWN, 'reload', check=False)]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_action')
|
@patch('freedombox.action_utils.service_action')
|
||||||
@systemd_installed
|
@systemd_installed
|
||||||
def test_service_try_reload_or_restart(mock):
|
def test_service_try_reload_or_restart(mock):
|
||||||
"""Test try-reload-or-restart on a service."""
|
"""Test try-reload-or-restart on a service."""
|
||||||
@ -231,11 +233,11 @@ def fixture_update_dir(tmp_path):
|
|||||||
tmp_path /= 'source'
|
tmp_path /= 'source'
|
||||||
tmp_path.mkdir()
|
tmp_path.mkdir()
|
||||||
|
|
||||||
import plinth.settings
|
import freedombox.settings
|
||||||
old_value = plinth.settings.FILE_UPLOAD_TEMP_DIR
|
old_value = freedombox.settings.FILE_UPLOAD_TEMP_DIR
|
||||||
plinth.settings.FILE_UPLOAD_TEMP_DIR = tmp_path
|
freedombox.settings.FILE_UPLOAD_TEMP_DIR = tmp_path
|
||||||
yield 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):
|
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')
|
@patch('subprocess.run')
|
||||||
def test_run_capture(subprocess_run, thread_storage):
|
def test_run_capture(subprocess_run, thread_storage):
|
||||||
"""Test running a command with stdin/stdout capture works."""
|
"""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'
|
assert thread_storage.stderr == 'initial-stderrtest-stderr'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.actions.thread_storage')
|
@patch('freedombox.actions.thread_storage')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_run_no_capture(subprocess_run, thread_storage):
|
def test_run_no_capture(subprocess_run, thread_storage):
|
||||||
"""Test running a command without stdin/stdout capture works."""
|
"""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'
|
assert thread_storage.stderr == 'initial-stderr'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.actions.thread_storage', None)
|
@patch('freedombox.actions.thread_storage', None)
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_run_no_storage(subprocess_run):
|
def test_run_no_storage(subprocess_run):
|
||||||
"""Test running a command without thread storage."""
|
"""Test running a command without thread storage."""
|
||||||
|
|||||||
@ -100,9 +100,9 @@ def test_privileged_argument_annotation_check():
|
|||||||
privileged(func2_valid)
|
privileged(func2_valid)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.actions._read_from_server')
|
@patch('freedombox.actions._read_from_server')
|
||||||
@patch('plinth.actions._request_to_server')
|
@patch('freedombox.actions._request_to_server')
|
||||||
@patch('plinth.actions._get_privileged_action_module_name')
|
@patch('freedombox.actions._get_privileged_action_module_name')
|
||||||
def test_privileged_method_call(get_module_name, request_to_server,
|
def test_privileged_method_call(get_module_name, request_to_server,
|
||||||
read_from_server):
|
read_from_server):
|
||||||
"""Test that privileged method calls the superuser action properly."""
|
"""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('freedombox.actions._read_from_server')
|
||||||
@patch('plinth.actions._request_to_server')
|
@patch('freedombox.actions._request_to_server')
|
||||||
@patch('plinth.actions._get_privileged_action_module_name')
|
@patch('freedombox.actions._get_privileged_action_module_name')
|
||||||
def test_privileged_method_exceptions(get_module_name, request_to_server,
|
def test_privileged_method_exceptions(get_module_name, request_to_server,
|
||||||
read_from_server):
|
read_from_server):
|
||||||
"""Test that exceptions on privileged methods are return properly."""
|
"""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('importlib.import_module')
|
||||||
@patch('plinth.module_loader.get_module_import_path')
|
@patch('freedombox.module_loader.get_module_import_path')
|
||||||
@patch('os.getuid')
|
@patch('os.getuid')
|
||||||
def test_call_syntax_checks(getuid, get_module_import_path, import_module):
|
def test_call_syntax_checks(getuid, get_module_import_path, import_module):
|
||||||
"""Test that calling a method results in proper syntax checks."""
|
"""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', {})
|
privileged_call('foo.bar', 'x-action', {})
|
||||||
|
|
||||||
# Module import test
|
# 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
|
import_module.side_effect = ModuleNotFoundError
|
||||||
with pytest.raises(SyntaxError, match='Specified module not found'):
|
with pytest.raises(SyntaxError, match='Specified module not found'):
|
||||||
privileged_call('test_module', 'x-action', {})
|
privileged_call('test_module', 'x-action', {})
|
||||||
|
|
||||||
import_module.assert_has_calls(
|
import_module.assert_has_calls(
|
||||||
[call('plinth.modules.test_module.privileged')])
|
[call('freedombox.modules.test_module.privileged')])
|
||||||
|
|
||||||
# Finding action in a module
|
# Finding action in a module
|
||||||
module = type('', (), {})
|
module = type('', (), {})
|
||||||
|
|||||||
@ -9,13 +9,13 @@ from unittest.mock import Mock, call, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freedombox import log
|
from freedombox import log
|
||||||
from freedombox.app import (App, Component, EnableState, FollowerComponent, Info,
|
from freedombox.app import (App, Component, EnableState, FollowerComponent,
|
||||||
LeaderComponent, apps_init)
|
Info, LeaderComponent, apps_init)
|
||||||
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
|
||||||
privileged_modules_to_mock = ['plinth.privileged']
|
privileged_modules_to_mock = ['freedombox.privileged']
|
||||||
|
|
||||||
|
|
||||||
class AppTest(App):
|
class AppTest(App):
|
||||||
@ -300,7 +300,7 @@ def test_app_has_diagnostics(app_with_components):
|
|||||||
assert app.has_diagnostics()
|
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):
|
def test_app_repair(_run_setup_on_app, app_with_components):
|
||||||
"""Test running repair on an app."""
|
"""Test running repair on an app."""
|
||||||
component = app_with_components.get_component('test-follower-1')
|
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()
|
assert not app.has_diagnostics()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.privileged.service._assert_service_is_managed_by_plinth')
|
@patch('freedombox.privileged.service._assert_service_is_managed_by_plinth')
|
||||||
@patch('plinth.action_utils.service_get_logs')
|
@patch('freedombox.action_utils.service_get_logs')
|
||||||
@patch('plinth.action_utils.service_show')
|
@patch('freedombox.action_utils.service_show')
|
||||||
def test_app_get_logs(service_show, service_get_logs, _, app_with_components,
|
def test_app_get_logs(service_show, service_get_logs, _, app_with_components,
|
||||||
mock_privileged):
|
mock_privileged):
|
||||||
"""Test retrieving logs from an app."""
|
"""Test retrieving logs from an app."""
|
||||||
@ -443,7 +443,7 @@ def test_component_has_diagnostics():
|
|||||||
assert not 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):
|
def test_component_repair(_run_setup_on_app):
|
||||||
"""Test running repair on component."""
|
"""Test running repair on component."""
|
||||||
component = Component('test-component')
|
component = Component('test-component')
|
||||||
@ -608,7 +608,7 @@ class ModuleTest2:
|
|||||||
self.add(Info('app3', version=1))
|
self.add(Info('app3', version=1))
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.module_loader.loaded_modules')
|
@patch('freedombox.module_loader.loaded_modules')
|
||||||
def test_apps_init(loaded_modules):
|
def test_apps_init(loaded_modules):
|
||||||
"""Test that initializing all apps works."""
|
"""Test that initializing all apps works."""
|
||||||
loaded_modules.items.return_value = [('test1', ModuleTest1()),
|
loaded_modules.items.return_value = [('test1', ModuleTest1()),
|
||||||
@ -646,7 +646,7 @@ class ModuleCircularTest:
|
|||||||
self.add(Info('app3', version=1))
|
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):
|
def test_apps_init_circular_depends(loaded_modules):
|
||||||
"""Test initializing apps with circular dependencies."""
|
"""Test initializing apps with circular dependencies."""
|
||||||
loaded_modules.items.return_value = [('test', ModuleCircularTest())]
|
loaded_modules.items.return_value = [('test', ModuleCircularTest())]
|
||||||
|
|||||||
@ -46,7 +46,7 @@ def test_read_default_config_file():
|
|||||||
compare_configurations(parser)
|
compare_configurations(parser)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.cfg.get_config_paths')
|
@patch('freedombox.cfg.get_config_paths')
|
||||||
def test_read_primary_config_file(get_config_paths):
|
def test_read_primary_config_file(get_config_paths):
|
||||||
"""Verify that the primary config file is used by default."""
|
"""Verify that the primary config file is used by default."""
|
||||||
config_path = CONFIG_FILE_WITH_MISSING_OPTIONS
|
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
|
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):
|
def test_read_dot_d_config_files(get_config_paths):
|
||||||
"""Verify that the configuration is read from .d directories."""
|
"""Verify that the configuration is read from .d directories."""
|
||||||
root_dir = pathlib.Path(__file__).resolve().parent
|
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."""
|
"""Verify that the correct develop config file is used."""
|
||||||
test_dir = os.path.dirname(os.path.realpath(__file__))
|
test_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
develop_root = os.path.realpath(os.path.join(test_dir, '..', '..'))
|
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')
|
'develop.config')
|
||||||
config_path = cfg.get_develop_config_path()
|
config_path = cfg.get_develop_config_path()
|
||||||
cfg.read_file(config_path)
|
cfg.read_file(config_path)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from freedombox.config import DropinConfigs
|
|||||||
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
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')
|
@pytest.fixture(name='dropin_configs')
|
||||||
@ -33,7 +33,8 @@ def fixture_dropin_configs():
|
|||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def fixture_assert_dropin_config(dropin_configs):
|
def fixture_assert_dropin_config(dropin_configs):
|
||||||
"""Mock asserting dropin config path."""
|
"""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
|
mock.return_value = dropin_configs
|
||||||
yield
|
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):
|
def test_dropin_configs_setup(dropin_configs, tmp_path):
|
||||||
"""Test setup for dropin configs component."""
|
"""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()
|
is_enabled = Mock()
|
||||||
App.get('test-app').is_enabled = is_enabled
|
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):
|
def test_dropin_configs_enable_disable_symlinks(dropin_configs, tmp_path):
|
||||||
"""Test enable/disable for dropin configs component for symlinks."""
|
"""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
|
# Enable when nothing exists
|
||||||
dropin_configs.enable()
|
dropin_configs.enable()
|
||||||
_assert_symlinks(dropin_configs, tmp_path, should_exist=True)
|
_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):
|
def test_dropin_configs_enable_disable_copy_only(dropin_configs, tmp_path):
|
||||||
"""Test enable/disable for dropin configs component for copying."""
|
"""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
|
dropin_configs.copy_only = True
|
||||||
for path in ['/etc/test/path1', '/etc/path2']:
|
for path in ['/etc/test/path1', '/etc/path2']:
|
||||||
target = dropin_configs.get_target_path(path)
|
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):
|
def test_dropin_config_diagnose_symlinks(dropin_configs, tmp_path):
|
||||||
"""Test diagnosing dropin configs for symlinks."""
|
"""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
|
# Nothing exists
|
||||||
results = dropin_configs.diagnose()
|
results = dropin_configs.diagnose()
|
||||||
assert results == [
|
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):
|
def test_dropin_config_diagnose_copy_only(dropin_configs, tmp_path):
|
||||||
"""Test diagnosing dropin configs."""
|
"""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
|
dropin_configs.copy_only = True
|
||||||
for path in ['/etc/test/path1', '/etc/path2']:
|
for path in ['/etc/test/path1', '/etc/path2']:
|
||||||
target = dropin_configs.get_target_path(path)
|
target = dropin_configs.get_target_path(path)
|
||||||
|
|||||||
@ -11,8 +11,8 @@ from freedombox.diagnostic_check import DiagnosticCheck, Result
|
|||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
pytestmark = pytest.mark.usefixtures('mock_privileged')
|
||||||
privileged_modules_to_mock = [
|
privileged_modules_to_mock = [
|
||||||
'plinth.privileged', 'plinth.privileged.container',
|
'freedombox.privileged', 'freedombox.privileged.container',
|
||||||
'plinth.privileged.service'
|
'freedombox.privileged.service'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ def fixture_container():
|
|||||||
['service1.service'], {'/dev/host1': '/dev/cont1'},
|
['service1.service'], {'/dev/host1': '/dev/cont1'},
|
||||||
[(1234, 'tcp4')])
|
[(1234, 'tcp4')])
|
||||||
app1.add(container)
|
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]
|
app_list.return_value = [app1]
|
||||||
yield container
|
yield container
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def test_container_init(container):
|
|||||||
assert container.listen_ports == [(1234, 'tcp4')]
|
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):
|
def test_container_is_enabled(podman_is_enabled, container):
|
||||||
"""Test checking if container is enabled."""
|
"""Test checking if container is enabled."""
|
||||||
podman_is_enabled.return_value = False
|
podman_is_enabled.return_value = False
|
||||||
@ -73,8 +73,8 @@ def test_container_is_enabled(podman_is_enabled, container):
|
|||||||
assert container.is_enabled()
|
assert container.is_enabled()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_enable')
|
@patch('freedombox.action_utils.service_enable')
|
||||||
@patch('plinth.action_utils.podman_enable')
|
@patch('freedombox.action_utils.podman_enable')
|
||||||
def test_container_enable(podman_enable, enable, container):
|
def test_container_enable(podman_enable, enable, container):
|
||||||
"""Test enabling a container component."""
|
"""Test enabling a container component."""
|
||||||
container.enable()
|
container.enable()
|
||||||
@ -82,8 +82,8 @@ def test_container_enable(podman_enable, enable, container):
|
|||||||
assert enable.mock_calls == [call('name1')]
|
assert enable.mock_calls == [call('name1')]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_disable')
|
@patch('freedombox.action_utils.service_disable')
|
||||||
@patch('plinth.action_utils.podman_disable')
|
@patch('freedombox.action_utils.podman_disable')
|
||||||
def test_container_disable(podman_disable, disable, container):
|
def test_container_disable(podman_disable, disable, container):
|
||||||
"""Test disabling a container component."""
|
"""Test disabling a container component."""
|
||||||
container.disable()
|
container.disable()
|
||||||
@ -91,7 +91,7 @@ def test_container_disable(podman_disable, disable, container):
|
|||||||
assert disable.mock_calls == [call('name1')]
|
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):
|
def test_container_is_running(service_is_running, container):
|
||||||
"""Test checking of container component is running."""
|
"""Test checking of container component is running."""
|
||||||
service_is_running.return_value = False
|
service_is_running.return_value = False
|
||||||
@ -103,9 +103,9 @@ def test_container_is_running(service_is_running, container):
|
|||||||
assert container.is_running()
|
assert container.is_running()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_disable')
|
@patch('freedombox.action_utils.service_disable')
|
||||||
@patch('plinth.action_utils.service_enable')
|
@patch('freedombox.action_utils.service_enable')
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
def test_container_ensure_running(service_is_running, enable, disable,
|
def test_container_ensure_running(service_is_running, enable, disable,
|
||||||
container):
|
container):
|
||||||
"""Test checking of container component can be ensured to be running."""
|
"""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')]
|
assert disable.mock_calls == [call('name1')]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_disable')
|
@patch('freedombox.action_utils.service_disable')
|
||||||
@patch('plinth.action_utils.service_start')
|
@patch('freedombox.action_utils.service_start')
|
||||||
@patch('plinth.action_utils.podman_disable')
|
@patch('freedombox.action_utils.podman_disable')
|
||||||
@patch('plinth.action_utils.podman_is_enabled')
|
@patch('freedombox.action_utils.podman_is_enabled')
|
||||||
@patch('plinth.action_utils.podman_create')
|
@patch('freedombox.action_utils.podman_create')
|
||||||
def test_container_setup(podman_create, is_enabled, disable, service_start,
|
def test_container_setup(podman_create, is_enabled, disable, service_start,
|
||||||
service_disable, container):
|
service_disable, container):
|
||||||
"""Test setting up the 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')]
|
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):
|
def test_container_uninstall(podman_uninstall, container):
|
||||||
"""Test uninstalling the container."""
|
"""Test uninstalling the container."""
|
||||||
container.uninstall()
|
container.uninstall()
|
||||||
@ -162,8 +162,8 @@ def test_container_uninstall(podman_uninstall, container):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
@patch('plinth.container.diagnose_port_listening')
|
@patch('freedombox.container.diagnose_port_listening')
|
||||||
def test_container_diagnose(diagnose_port_listening, service_is_running,
|
def test_container_diagnose(diagnose_port_listening, service_is_running,
|
||||||
container):
|
container):
|
||||||
"""Test diagnosing the container."""
|
"""Test diagnosing the container."""
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from django.urls import resolve
|
|||||||
from freedombox import context_processors as cp
|
from freedombox import context_processors as cp
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.notification.Notification')
|
@patch('freedombox.notification.Notification')
|
||||||
def test_common(Notification, load_cfg, rf, test_menu):
|
def test_common(Notification, load_cfg, rf, test_menu):
|
||||||
"""Verify that the common() function returns the correct values."""
|
"""Verify that the common() function returns the correct values."""
|
||||||
url = '/apps/testapp/create/'
|
url = '/apps/testapp/create/'
|
||||||
|
|||||||
@ -10,11 +10,12 @@ from unittest.mock import Mock, call, patch
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from freedombox.app import App, FollowerComponent, Info
|
from freedombox.app import App, FollowerComponent, Info
|
||||||
from freedombox.daemon import (Daemon, RelatedDaemon, SharedDaemon, app_is_running,
|
from freedombox.daemon import (Daemon, RelatedDaemon, SharedDaemon,
|
||||||
diagnose_netcat, diagnose_port_listening)
|
app_is_running, diagnose_netcat,
|
||||||
|
diagnose_port_listening)
|
||||||
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
from freedombox.diagnostic_check import DiagnosticCheck, Result
|
||||||
|
|
||||||
privileged_modules_to_mock = ['plinth.privileged.service']
|
privileged_modules_to_mock = ['freedombox.privileged.service']
|
||||||
|
|
||||||
|
|
||||||
class AppTest(App):
|
class AppTest(App):
|
||||||
@ -35,7 +36,7 @@ def fixture_app_list(daemon):
|
|||||||
app1 = AppTest()
|
app1 = AppTest()
|
||||||
app1.add(Info('test-app', 1))
|
app1.add(Info('test-app', 1))
|
||||||
app1.add(daemon)
|
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]
|
app_list.return_value = [app1]
|
||||||
yield app_list
|
yield app_list
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ def test_initialization():
|
|||||||
assert daemon.alias == 'test-unit-2'
|
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):
|
def test_is_enabled(service_is_enabled, daemon):
|
||||||
"""Test that daemon enabled check works."""
|
"""Test that daemon enabled check works."""
|
||||||
service_is_enabled.return_value = True
|
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)])
|
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')
|
@patch('subprocess.run')
|
||||||
def test_enable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
def test_enable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
||||||
"""Test that enabling the daemon works."""
|
"""Test that enabling the daemon works."""
|
||||||
@ -105,7 +106,7 @@ def test_enable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
|||||||
**common_args)
|
**common_args)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.apps_init')
|
@patch('freedombox.app.apps_init')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_disable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
def test_disable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
||||||
"""Test that disabling the daemon works."""
|
"""Test that disabling the daemon works."""
|
||||||
@ -132,7 +133,7 @@ def test_disable(subprocess_run, apps_init, app_list, mock_privileged, daemon):
|
|||||||
**common_args)
|
**common_args)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
def test_is_running(service_is_running, daemon):
|
def test_is_running(service_is_running, daemon):
|
||||||
"""Test that checking that the daemon is running works."""
|
"""Test that checking that the daemon is running works."""
|
||||||
service_is_running.return_value = True
|
service_is_running.return_value = True
|
||||||
@ -143,9 +144,9 @@ def test_is_running(service_is_running, daemon):
|
|||||||
assert not daemon.is_running()
|
assert not daemon.is_running()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.apps_init')
|
@patch('freedombox.app.apps_init')
|
||||||
@patch('plinth.action_utils.service_is_running')
|
@patch('freedombox.action_utils.service_is_running')
|
||||||
@patch('plinth.action_utils.service_show')
|
@patch('freedombox.action_utils.service_show')
|
||||||
@patch('subprocess.run')
|
@patch('subprocess.run')
|
||||||
def test_ensure_running(subprocess_run, service_show, service_is_running,
|
def test_ensure_running(subprocess_run, service_show, service_is_running,
|
||||||
apps_init, app_list, mock_privileged, daemon):
|
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('freedombox.action_utils.service_is_running')
|
||||||
@patch('plinth.daemon.diagnose_port_listening')
|
@patch('freedombox.daemon.diagnose_port_listening')
|
||||||
def test_diagnose(port_listening, service_is_running, daemon):
|
def test_diagnose(port_listening, service_is_running, daemon):
|
||||||
"""Test running diagnostics."""
|
"""Test running diagnostics."""
|
||||||
|
|
||||||
@ -216,7 +217,7 @@ def test_diagnose(port_listening, service_is_running, daemon):
|
|||||||
assert results[0].result == Result.FAILED
|
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):
|
def test_app_is_running(service_is_running):
|
||||||
"""Test that checking whether app is running works."""
|
"""Test that checking whether app is running works."""
|
||||||
daemon1 = Daemon('test-daemon-1', 'test-unit-1')
|
daemon1 = Daemon('test-daemon-1', 'test-unit-1')
|
||||||
@ -388,7 +389,7 @@ def test_shared_daemon_leader():
|
|||||||
assert not component1.is_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):
|
def test_shared_daemon_set_enabled(service_is_enabled):
|
||||||
"""Test that enabled status is determined by unit status."""
|
"""Test that enabled status is determined by unit status."""
|
||||||
component = SharedDaemon('test-component', 'test-daemon')
|
component = SharedDaemon('test-component', 'test-daemon')
|
||||||
@ -406,7 +407,7 @@ def test_shared_daemon_set_enabled(service_is_enabled):
|
|||||||
assert component.is_enabled()
|
assert component.is_enabled()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.privileged.service.disable')
|
@patch('freedombox.privileged.service.disable')
|
||||||
def test_shared_daemon_disable(disable_method):
|
def test_shared_daemon_disable(disable_method):
|
||||||
"""Test that shared daemon disables service correctly."""
|
"""Test that shared daemon disables service correctly."""
|
||||||
|
|
||||||
|
|||||||
@ -106,7 +106,7 @@ def test_shortcut_list_web_apps_only(common_shortcuts):
|
|||||||
assert return_list == [cuts[0], cuts[1], cuts[2]]
|
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):
|
def test_shortcut_list_with_username(get_user_groups, common_shortcuts):
|
||||||
"""Test listing for particular users."""
|
"""Test listing for particular users."""
|
||||||
cuts = common_shortcuts
|
cuts = common_shortcuts
|
||||||
|
|||||||
@ -16,8 +16,8 @@ from django.urls import resolve
|
|||||||
from stronghold.decorators import public
|
from stronghold.decorators import public
|
||||||
|
|
||||||
from freedombox import app as app_module
|
from freedombox import app as app_module
|
||||||
from freedombox.middleware import (AdminRequiredMiddleware, CommonErrorMiddleware,
|
from freedombox.middleware import (AdminRequiredMiddleware,
|
||||||
SetupMiddleware)
|
CommonErrorMiddleware, SetupMiddleware)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name='kwargs')
|
@pytest.fixture(name='kwargs')
|
||||||
@ -89,7 +89,7 @@ class TestSetupMiddleware:
|
|||||||
assert response is None
|
assert response is None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.views.SetupView')
|
@patch('freedombox.views.SetupView')
|
||||||
@patch('django.urls.resolve')
|
@patch('django.urls.resolve')
|
||||||
@patch('django.urls.reverse', return_value='users:login')
|
@patch('django.urls.reverse', return_value='users:login')
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
@ -133,7 +133,7 @@ class TestSetupMiddleware:
|
|||||||
view.assert_called_once_with(request, app_id='mockapp')
|
view.assert_called_once_with(request, app_id='mockapp')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@patch('plinth.operation.manager')
|
@patch('freedombox.operation.manager')
|
||||||
@patch('django.contrib.messages.error')
|
@patch('django.contrib.messages.error')
|
||||||
@patch('django.contrib.messages.success')
|
@patch('django.contrib.messages.success')
|
||||||
@patch('django.urls.resolve')
|
@patch('django.urls.resolve')
|
||||||
@ -221,8 +221,8 @@ class TestAdminMiddleware:
|
|||||||
web_request.user.groups.filter().exists = Mock(return_value=False)
|
web_request.user.groups.filter().exists = Mock(return_value=False)
|
||||||
web_request.session = MagicMock()
|
web_request.session = MagicMock()
|
||||||
with patch(
|
with patch(
|
||||||
'plinth.middleware.AdminRequiredMiddleware.check_user_group',
|
'freedombox.middleware.AdminRequiredMiddleware.'
|
||||||
lambda x, y: False):
|
'check_user_group', lambda x, y: False):
|
||||||
with pytest.raises(PermissionDenied):
|
with pytest.raises(PermissionDenied):
|
||||||
middleware.process_view(web_request, **kwargs)
|
middleware.process_view(web_request, **kwargs)
|
||||||
|
|
||||||
@ -233,8 +233,8 @@ class TestAdminMiddleware:
|
|||||||
web_request.user.groups.filter().exists = Mock(return_value=False)
|
web_request.user.groups.filter().exists = Mock(return_value=False)
|
||||||
web_request.session = MagicMock()
|
web_request.session = MagicMock()
|
||||||
with patch(
|
with patch(
|
||||||
'plinth.middleware.AdminRequiredMiddleware.check_user_group',
|
'freedombox.middleware.AdminRequiredMiddleware.'
|
||||||
lambda x, y: True):
|
'check_user_group', lambda x, y: True):
|
||||||
response = middleware.process_view(web_request, **kwargs)
|
response = middleware.process_view(web_request, **kwargs)
|
||||||
assert response is None
|
assert response is None
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,8 @@ from unittest.mock import mock_open, patch
|
|||||||
from freedombox import module_loader
|
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():
|
def test_get_module_import_path():
|
||||||
"""Returning the module import path."""
|
"""Returning the module import path."""
|
||||||
import_path = module_loader.get_module_import_path('apache')
|
import_path = module_loader.get_module_import_path('apache')
|
||||||
assert import_path == 'plinth.modules.apache'
|
assert import_path == 'freedombox.modules.apache'
|
||||||
|
|||||||
@ -334,7 +334,7 @@ def test_list_filter_user_and_group(note, user):
|
|||||||
assert list(Notification.list(user=user)) == [note]
|
assert list(Notification.list(user=user)) == [note]
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.notification.gettext')
|
@patch('freedombox.notification.gettext')
|
||||||
def test_display_context(gettext, note, user, rf):
|
def test_display_context(gettext, note, user, rf):
|
||||||
"""Test display context for a notification."""
|
"""Test display context for a notification."""
|
||||||
request = rf.get('/freedombox/help/about/')
|
request = rf.get('/freedombox/help/about/')
|
||||||
|
|||||||
@ -25,7 +25,7 @@ class AppTest(app.App):
|
|||||||
self.add(info)
|
self.add(info)
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.operation.Operation._update_notification')
|
@patch('freedombox.operation.Operation._update_notification')
|
||||||
def test_operation_default_initialization(update_notification):
|
def test_operation_default_initialization(update_notification):
|
||||||
"""Test Operation initialization with default values."""
|
"""Test Operation initialization with default values."""
|
||||||
target = Mock()
|
target = Mock()
|
||||||
@ -48,7 +48,7 @@ def test_operation_default_initialization(update_notification):
|
|||||||
update_notification.assert_has_calls([call()])
|
update_notification.assert_has_calls([call()])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.operation.Operation._update_notification')
|
@patch('freedombox.operation.Operation._update_notification')
|
||||||
def test_operation_initialization(update_notification):
|
def test_operation_initialization(update_notification):
|
||||||
"""Test Operation initialization with explicit values."""
|
"""Test Operation initialization with explicit values."""
|
||||||
on_complete = Mock()
|
on_complete = Mock()
|
||||||
@ -73,7 +73,7 @@ def test_operation_str():
|
|||||||
assert str(operation) == 'Operation: testapp: op1'
|
assert str(operation) == 'Operation: testapp: op1'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.operation.Operation._update_notification')
|
@patch('freedombox.operation.Operation._update_notification')
|
||||||
def test_successful_operation(update_notification):
|
def test_successful_operation(update_notification):
|
||||||
"""Test running a operation that succeeds."""
|
"""Test running a operation that succeeds."""
|
||||||
target = Mock()
|
target = Mock()
|
||||||
@ -90,7 +90,7 @@ def test_successful_operation(update_notification):
|
|||||||
update_notification.assert_has_calls([call(), call()])
|
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):
|
def test_error_operation(update_notification):
|
||||||
"""Test running an operation that fails."""
|
"""Test running an operation that fails."""
|
||||||
target = Mock()
|
target = Mock()
|
||||||
@ -109,7 +109,7 @@ def test_error_operation(update_notification):
|
|||||||
update_notification.assert_has_calls([call(), call()])
|
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):
|
def test_join_before_start(update_notification):
|
||||||
"""Test waiting until operation finishes.."""
|
"""Test waiting until operation finishes.."""
|
||||||
event = threading.Event()
|
event = threading.Event()
|
||||||
@ -131,7 +131,7 @@ def test_join_before_start(update_notification):
|
|||||||
assert success
|
assert success
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.operation.Operation._update_notification')
|
@patch('freedombox.operation.Operation._update_notification')
|
||||||
def test_join_raises_exception(update_notification):
|
def test_join_raises_exception(update_notification):
|
||||||
"""Test that joining raises exception if thread does.."""
|
"""Test that joining raises exception if thread does.."""
|
||||||
target = Mock()
|
target = Mock()
|
||||||
@ -157,7 +157,7 @@ def test_getting_operation_from_thread():
|
|||||||
assert operation.thread_data['test_operation'] == operation
|
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):
|
def test_updating_operation(update_notification):
|
||||||
"""Test that operation object can be updated from within the thread."""
|
"""Test that operation object can be updated from within the thread."""
|
||||||
exception = RuntimeError('error1')
|
exception = RuntimeError('error1')
|
||||||
@ -176,7 +176,7 @@ def test_updating_operation(update_notification):
|
|||||||
update_notification.assert_has_calls([call(), call(), call()])
|
update_notification.assert_has_calls([call(), call(), call()])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
def test_message(app_get):
|
def test_message(app_get):
|
||||||
"""Test getting the operation's message."""
|
"""Test getting the operation's message."""
|
||||||
operation = Operation('testid', 'testapp', 'op1', Mock())
|
operation = Operation('testid', 'testapp', 'op1', Mock())
|
||||||
@ -205,7 +205,7 @@ def test_message(app_get):
|
|||||||
assert operation.translated_message == 'Finished: op1'
|
assert operation.translated_message == 'Finished: op1'
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.app.App.get')
|
@patch('freedombox.app.App.get')
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_update_notification(app_get):
|
def test_update_notification(app_get):
|
||||||
"""Test that operation notification is created."""
|
"""Test that operation notification is created."""
|
||||||
|
|||||||
@ -109,7 +109,7 @@ def test_packages_get_actual_packages(cache):
|
|||||||
component.get_actual_packages()
|
component.get_actual_packages()
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.package.install')
|
@patch('freedombox.package.install')
|
||||||
def test_packages_setup(install):
|
def test_packages_setup(install):
|
||||||
"""Test setting up packages component."""
|
"""Test setting up packages component."""
|
||||||
|
|
||||||
@ -139,9 +139,9 @@ def test_packages_setup(install):
|
|||||||
install.assert_has_calls([call(['python3'], skip_recommends=False)])
|
install.assert_has_calls([call(['python3'], skip_recommends=False)])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.package.packages_installed')
|
@patch('freedombox.package.packages_installed')
|
||||||
@patch('plinth.package.uninstall')
|
@patch('freedombox.package.uninstall')
|
||||||
@patch('plinth.package.install')
|
@patch('freedombox.package.install')
|
||||||
def test_packages_setup_with_conflicts(install, uninstall, packages_installed):
|
def test_packages_setup_with_conflicts(install, uninstall, packages_installed):
|
||||||
"""Test setting up packages with conflicts."""
|
"""Test setting up packages with conflicts."""
|
||||||
packages_installed.return_value = ['exim4-base']
|
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)])
|
install.assert_has_calls([call(['bash'], skip_recommends=False)])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.package.refresh_package_lists')
|
@patch('freedombox.package.refresh_package_lists')
|
||||||
@patch('plinth.package.uninstall')
|
@patch('freedombox.package.uninstall')
|
||||||
def test_packages_uninstall(uninstall, _refresh_package_lists):
|
def test_packages_uninstall(uninstall, _refresh_package_lists):
|
||||||
"""Test uninstalling packages component."""
|
"""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)])
|
uninstall.assert_has_calls([call(['bash', 'dash'], purge=True)])
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.package.refresh_package_lists')
|
@patch('freedombox.package.refresh_package_lists')
|
||||||
@patch('plinth.package.uninstall')
|
@patch('freedombox.package.uninstall')
|
||||||
@patch('apt.Cache')
|
@patch('apt.Cache')
|
||||||
def test_packages_uninstall_exclusion(cache, uninstall,
|
def test_packages_uninstall_exclusion(cache, uninstall,
|
||||||
_refresh_package_lists):
|
_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_):
|
def test_packages_find_conflicts(packages_installed_):
|
||||||
"""Test finding conflicts."""
|
"""Test finding conflicts."""
|
||||||
packages_installed_.return_value = []
|
packages_installed_.return_value = []
|
||||||
@ -353,7 +353,7 @@ def test_packages_find_conflicts(packages_installed_):
|
|||||||
assert component.find_conflicts() == ['package1', 'package2']
|
assert component.find_conflicts() == ['package1', 'package2']
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.package.refresh_package_lists')
|
@patch('freedombox.package.refresh_package_lists')
|
||||||
@patch('apt.Cache')
|
@patch('apt.Cache')
|
||||||
@patch('pathlib.Path')
|
@patch('pathlib.Path')
|
||||||
def test_packages_is_available(path_class, cache, refresh_package_lists):
|
def test_packages_is_available(path_class, cache, refresh_package_lists):
|
||||||
|
|||||||
@ -49,7 +49,7 @@ def test_highlighting():
|
|||||||
assert _verify_active_menuitems(menu)
|
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):
|
def test_icon(resolve_static_path, tmp_path):
|
||||||
"""Test that the icon tag works for basic usage."""
|
"""Test that the icon tag works for basic usage."""
|
||||||
icon1 = tmp_path / 'icon1.svg'
|
icon1 = tmp_path / 'icon1.svg'
|
||||||
@ -60,7 +60,7 @@ def test_icon(resolve_static_path, tmp_path):
|
|||||||
'><cirlcle></circle></svg>')
|
'><cirlcle></circle></svg>')
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.web_server.resolve_static_path')
|
@patch('freedombox.web_server.resolve_static_path')
|
||||||
def test_icon_attributes(resolve_static_path, tmp_path):
|
def test_icon_attributes(resolve_static_path, tmp_path):
|
||||||
"""Test that the icon tag works with attributes."""
|
"""Test that the icon tag works with attributes."""
|
||||||
icon1 = tmp_path / 'icon1.svg'
|
icon1 = tmp_path / 'icon1.svg'
|
||||||
@ -78,8 +78,8 @@ def test_icon_attributes(resolve_static_path, tmp_path):
|
|||||||
'data-icon-name="icon1" ><cirlcle></circle></svg>')
|
'data-icon-name="icon1" ><cirlcle></circle></svg>')
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.utils.random_string')
|
@patch('freedombox.utils.random_string')
|
||||||
@patch('plinth.web_server.resolve_static_path')
|
@patch('freedombox.web_server.resolve_static_path')
|
||||||
def test_icon_auto_ids(resolve_static_path, random_string, tmp_path):
|
def test_icon_auto_ids(resolve_static_path, random_string, tmp_path):
|
||||||
"""Test that the icon tag works for implementing automatic IDs."""
|
"""Test that the icon tag works for implementing automatic IDs."""
|
||||||
random_string.return_value = 'randomvalue'
|
random_string.return_value = 'randomvalue'
|
||||||
@ -93,7 +93,7 @@ def test_icon_auto_ids(resolve_static_path, random_string, tmp_path):
|
|||||||
'<path id="randomvalue-bar"></path></svg>')
|
'<path id="randomvalue-bar"></path></svg>')
|
||||||
|
|
||||||
|
|
||||||
@patch('plinth.web_server.resolve_static_path')
|
@patch('freedombox.web_server.resolve_static_path')
|
||||||
def test_icon_xml_stripping(resolve_static_path, tmp_path):
|
def test_icon_xml_stripping(resolve_static_path, tmp_path):
|
||||||
"""Test that the icon tag strips the XML header."""
|
"""Test that the icon tag strips the XML header."""
|
||||||
icon2 = tmp_path / 'icon2.svg'
|
icon2 = tmp_path / 'icon2.svg'
|
||||||
|
|||||||
@ -65,7 +65,7 @@ def test_static_files_mount(mount, load_cfg):
|
|||||||
|
|
||||||
|
|
||||||
@patch('sys.modules')
|
@patch('sys.modules')
|
||||||
@patch('plinth.app.App.list')
|
@patch('freedombox.app.App.list')
|
||||||
def test_resolve_static_path(app_list, sys_modules, tmp_path):
|
def test_resolve_static_path(app_list, sys_modules, tmp_path):
|
||||||
"""Test that resolving a static path works as expected."""
|
"""Test that resolving a static path works as expected."""
|
||||||
app_list.return_value = []
|
app_list.return_value = []
|
||||||
|
|||||||
@ -714,7 +714,7 @@ class UninstallView(FormView):
|
|||||||
if self.has_backup_restore and form.cleaned_data['should_backup']:
|
if self.has_backup_restore and form.cleaned_data['should_backup']:
|
||||||
repository_id = form.cleaned_data['repository']
|
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)
|
repository = repository_module.get_instance(repository_id)
|
||||||
if repository.flags.get('mountable'):
|
if repository.flags.get('mountable'):
|
||||||
repository.mount()
|
repository.mount()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user