[CI] Format code with Black

This commit is contained in:
yunohost-bot 2023-03-01 00:47:18 +00:00
parent 28610669ed
commit 76ff5b1844
3 changed files with 72 additions and 29 deletions

View file

@ -534,7 +534,14 @@ def app_change_url(operation_logger, app, domain, path):
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
@ -857,8 +864,16 @@ def app_upgrade(app=[], url=None, file=None, force=False, no_safety_backup=False
else:
operation_logger.close()
logger.error(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))
logger.error(
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 !
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:
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))

View file

@ -548,37 +548,51 @@ class TestMockedAppUpgrade:
This class is here to test the logical workflow of app_upgrade and thus
mock nearly all side effects
"""
def setup_method(self, method):
self.apps_list = []
self.upgradable_apps_list = []
def _mock_app_upgrade(self, mocker):
# 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
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 =
mocker.patch("yunohost.app.app_info", side_effect=lambda app, full: {
"upgradable": "yes" if app in self.upgradable_apps_list else "no",
"manifest": {"id": app},
"version": "?",
})
mocker.patch(
"yunohost.app.app_info",
side_effect=lambda app, full: {
"upgradable": "yes" if app in self.upgradable_apps_list else "no",
"manifest": {"id": app},
"version": "?",
},
)
def custom_extract_app(app):
return ({
"version": "?",
"packaging_format": 1,
"id": app,
"notifications": {"PRE_UPGRADE": None, "POST_UPGRADE": None},
}, "MOCKED_BY_TEST")
return (
{
"version": "?",
"packaging_format": 1,
"id": app,
"notifications": {"PRE_UPGRADE": None, "POST_UPGRADE": None},
},
"MOCKED_BY_TEST",
)
# return (manifest, extracted_app_folder)
mocker.patch("yunohost.app._extract_app", side_effect=custom_extract_app)
# 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
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)
# manifest =
mocker.patch("yunohost.app.read_toml", return_value={
"arguments": {"install": []}
})
mocker.patch(
"yunohost.app.read_toml", return_value={"arguments": {"install": []}}
)
# 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 =
mocker.patch("yunohost.app._get_app_settings", return_value={})
# return nothing
@ -644,7 +661,12 @@ class TestMockedAppUpgrade:
app_upgrade()
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):
self._mock_app_upgrade(mocker)
@ -682,7 +704,10 @@ class TestMockedAppUpgrade:
raise Exception()
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):
app_upgrade()

View file

@ -322,17 +322,16 @@ class PermissionsResource(AppResource):
if "main" not in properties:
properties["main"] = self.default_perm_properties
for perm, infos in properties.items():
properties[perm] = copy.copy(self.default_perm_properties)
properties[perm].update(infos)
if properties[perm]["show_tile"] is None:
properties[perm]["show_tile"] = bool(properties[perm]["url"])
if (
properties["main"]["url"] is not None
and ( not isinstance(properties["main"].get("url"), str)
or properties["main"]["url"] != "/" )
if properties["main"]["url"] is not None and (
not isinstance(properties["main"].get("url"), str)
or properties["main"]["url"] != "/"
):
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/",