mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[CI] Format code with Black
This commit is contained in:
parent
28610669ed
commit
76ff5b1844
3 changed files with 72 additions and 29 deletions
27
src/app.py
27
src/app.py
|
@ -534,7 +534,14 @@ def app_change_url(operation_logger, app, domain, path):
|
||||||
hook_callback("post_app_change_url", env=env_dict)
|
hook_callback("post_app_change_url", env=env_dict)
|
||||||
|
|
||||||
|
|
||||||
def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False, continue_on_failure=False):
|
def app_upgrade(
|
||||||
|
app=[],
|
||||||
|
url=None,
|
||||||
|
file=None,
|
||||||
|
force=False,
|
||||||
|
no_safety_backup=False,
|
||||||
|
continue_on_failure=False,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Upgrade app
|
Upgrade app
|
||||||
|
|
||||||
|
@ -857,8 +864,16 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
|
|
||||||
else:
|
else:
|
||||||
operation_logger.close()
|
operation_logger.close()
|
||||||
logger.error(m18n.n("app_failed_to_upgrade_but_continue", failed_app=app_instance_name, operation_logger_name=operation_logger.name))
|
logger.error(
|
||||||
failed_to_upgrade_apps.append((app_instance_name, operation_logger.name))
|
m18n.n(
|
||||||
|
"app_failed_to_upgrade_but_continue",
|
||||||
|
failed_app=app_instance_name,
|
||||||
|
operation_logger_name=operation_logger.name,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
failed_to_upgrade_apps.append(
|
||||||
|
(app_instance_name, operation_logger.name)
|
||||||
|
)
|
||||||
|
|
||||||
# Otherwise we're good and keep going !
|
# Otherwise we're good and keep going !
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
@ -923,7 +938,11 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
|
||||||
if failed_to_upgrade_apps:
|
if failed_to_upgrade_apps:
|
||||||
apps = ""
|
apps = ""
|
||||||
for app_id, operation_logger_name in failed_to_upgrade_apps:
|
for app_id, operation_logger_name in failed_to_upgrade_apps:
|
||||||
apps += m18n.n("apps_failed_to_upgrade_line", app_id=app_id, operation_logger_name=operation_logger_name)
|
apps += m18n.n(
|
||||||
|
"apps_failed_to_upgrade_line",
|
||||||
|
app_id=app_id,
|
||||||
|
operation_logger_name=operation_logger_name,
|
||||||
|
)
|
||||||
|
|
||||||
logger.warning(m18n.n("apps_failed_to_upgrade", apps=apps))
|
logger.warning(m18n.n("apps_failed_to_upgrade", apps=apps))
|
||||||
|
|
||||||
|
|
|
@ -548,37 +548,51 @@ class TestMockedAppUpgrade:
|
||||||
This class is here to test the logical workflow of app_upgrade and thus
|
This class is here to test the logical workflow of app_upgrade and thus
|
||||||
mock nearly all side effects
|
mock nearly all side effects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
self.apps_list = []
|
self.apps_list = []
|
||||||
self.upgradable_apps_list = []
|
self.upgradable_apps_list = []
|
||||||
|
|
||||||
def _mock_app_upgrade(self, mocker):
|
def _mock_app_upgrade(self, mocker):
|
||||||
# app list
|
# app list
|
||||||
self._installed_apps = mocker.patch("yunohost.app._installed_apps", side_effect=lambda: self.apps_list)
|
self._installed_apps = mocker.patch(
|
||||||
|
"yunohost.app._installed_apps", side_effect=lambda: self.apps_list
|
||||||
|
)
|
||||||
|
|
||||||
# just check if an app is really installed
|
# just check if an app is really installed
|
||||||
mocker.patch("yunohost.app._is_installed", side_effect=lambda app: app in self.apps_list)
|
mocker.patch(
|
||||||
|
"yunohost.app._is_installed", side_effect=lambda app: app in self.apps_list
|
||||||
|
)
|
||||||
|
|
||||||
# app_dict =
|
# app_dict =
|
||||||
mocker.patch("yunohost.app.app_info", side_effect=lambda app, full: {
|
mocker.patch(
|
||||||
|
"yunohost.app.app_info",
|
||||||
|
side_effect=lambda app, full: {
|
||||||
"upgradable": "yes" if app in self.upgradable_apps_list else "no",
|
"upgradable": "yes" if app in self.upgradable_apps_list else "no",
|
||||||
"manifest": {"id": app},
|
"manifest": {"id": app},
|
||||||
"version": "?",
|
"version": "?",
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def custom_extract_app(app):
|
def custom_extract_app(app):
|
||||||
return ({
|
return (
|
||||||
|
{
|
||||||
"version": "?",
|
"version": "?",
|
||||||
"packaging_format": 1,
|
"packaging_format": 1,
|
||||||
"id": app,
|
"id": app,
|
||||||
"notifications": {"PRE_UPGRADE": None, "POST_UPGRADE": None},
|
"notifications": {"PRE_UPGRADE": None, "POST_UPGRADE": None},
|
||||||
}, "MOCKED_BY_TEST")
|
},
|
||||||
|
"MOCKED_BY_TEST",
|
||||||
|
)
|
||||||
|
|
||||||
# return (manifest, extracted_app_folder)
|
# return (manifest, extracted_app_folder)
|
||||||
mocker.patch("yunohost.app._extract_app", side_effect=custom_extract_app)
|
mocker.patch("yunohost.app._extract_app", side_effect=custom_extract_app)
|
||||||
|
|
||||||
# for [(name, passed, values, err), ...] in
|
# for [(name, passed, values, err), ...] in
|
||||||
mocker.patch("yunohost.app._check_manifest_requirements", return_value=[(None, True, None, None)])
|
mocker.patch(
|
||||||
|
"yunohost.app._check_manifest_requirements",
|
||||||
|
return_value=[(None, True, None, None)],
|
||||||
|
)
|
||||||
|
|
||||||
# raise on failure
|
# raise on failure
|
||||||
mocker.patch("yunohost.app._assert_system_is_sane_for_app", return_value=True)
|
mocker.patch("yunohost.app._assert_system_is_sane_for_app", return_value=True)
|
||||||
|
@ -593,12 +607,15 @@ class TestMockedAppUpgrade:
|
||||||
mocker.patch("os.path.exists", side_effect=custom_os_path_exists)
|
mocker.patch("os.path.exists", side_effect=custom_os_path_exists)
|
||||||
|
|
||||||
# manifest =
|
# manifest =
|
||||||
mocker.patch("yunohost.app.read_toml", return_value={
|
mocker.patch(
|
||||||
"arguments": {"install": []}
|
"yunohost.app.read_toml", return_value={"arguments": {"install": []}}
|
||||||
})
|
)
|
||||||
|
|
||||||
# install_failed, failure_message_with_debug_instructions =
|
# install_failed, failure_message_with_debug_instructions =
|
||||||
self.hook_exec_with_script_debug_if_failure = mocker.patch("yunohost.hook.hook_exec_with_script_debug_if_failure", return_value=(False, ""))
|
self.hook_exec_with_script_debug_if_failure = mocker.patch(
|
||||||
|
"yunohost.hook.hook_exec_with_script_debug_if_failure",
|
||||||
|
return_value=(False, ""),
|
||||||
|
)
|
||||||
# settings =
|
# settings =
|
||||||
mocker.patch("yunohost.app._get_app_settings", return_value={})
|
mocker.patch("yunohost.app._get_app_settings", return_value={})
|
||||||
# return nothing
|
# return nothing
|
||||||
|
@ -644,7 +661,12 @@ class TestMockedAppUpgrade:
|
||||||
app_upgrade()
|
app_upgrade()
|
||||||
|
|
||||||
self.hook_exec_with_script_debug_if_failure.assert_called_once()
|
self.hook_exec_with_script_debug_if_failure.assert_called_once()
|
||||||
assert self.hook_exec_with_script_debug_if_failure.call_args.kwargs["env"]["YNH_APP_ID"] == "some_app"
|
assert (
|
||||||
|
self.hook_exec_with_script_debug_if_failure.call_args.kwargs["env"][
|
||||||
|
"YNH_APP_ID"
|
||||||
|
]
|
||||||
|
== "some_app"
|
||||||
|
)
|
||||||
|
|
||||||
def test_app_upgrade_continue_on_failure(self, mocker):
|
def test_app_upgrade_continue_on_failure(self, mocker):
|
||||||
self._mock_app_upgrade(mocker)
|
self._mock_app_upgrade(mocker)
|
||||||
|
@ -682,7 +704,10 @@ class TestMockedAppUpgrade:
|
||||||
raise Exception()
|
raise Exception()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
mocker.patch("yunohost.app._assert_system_is_sane_for_app", side_effect=_assert_system_is_sane_for_app)
|
mocker.patch(
|
||||||
|
"yunohost.app._assert_system_is_sane_for_app",
|
||||||
|
side_effect=_assert_system_is_sane_for_app,
|
||||||
|
)
|
||||||
|
|
||||||
with pytest.raises(YunohostError):
|
with pytest.raises(YunohostError):
|
||||||
app_upgrade()
|
app_upgrade()
|
||||||
|
|
|
@ -329,10 +329,9 @@ class PermissionsResource(AppResource):
|
||||||
if properties[perm]["show_tile"] is None:
|
if properties[perm]["show_tile"] is None:
|
||||||
properties[perm]["show_tile"] = bool(properties[perm]["url"])
|
properties[perm]["show_tile"] = bool(properties[perm]["url"])
|
||||||
|
|
||||||
if (
|
if properties["main"]["url"] is not None and (
|
||||||
properties["main"]["url"] is not None
|
not isinstance(properties["main"].get("url"), str)
|
||||||
and ( not isinstance(properties["main"].get("url"), str)
|
or properties["main"]["url"] != "/"
|
||||||
or properties["main"]["url"] != "/" )
|
|
||||||
):
|
):
|
||||||
raise YunohostError(
|
raise YunohostError(
|
||||||
"URL for the 'main' permission should be '/' for webapps (or left undefined for non-webapps). Note that / refers to the install url of the app, i.e $domain.tld/$path/",
|
"URL for the 'main' permission should be '/' for webapps (or left undefined for non-webapps). Note that / refers to the install url of the app, i.e $domain.tld/$path/",
|
||||||
|
|
Loading…
Add table
Reference in a new issue