mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
autopep8 --in-place -a -a -a -a -a -r data/ doc/ tests/ src/yunohost/tests/ src/yunohost/utils/ src/yunohost/data_migrations/
This commit is contained in:
parent
fa19c9480c
commit
ecbd63636b
25 changed files with 189 additions and 164 deletions
|
@ -15,15 +15,17 @@ THIS_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||
ACTIONSMAP_FILE = THIS_SCRIPT_DIR + '/yunohost.yml'
|
||||
BASH_COMPLETION_FILE = THIS_SCRIPT_DIR + '/../bash-completion.d/yunohost'
|
||||
|
||||
|
||||
def get_dict_actions(OPTION_SUBTREE, category):
|
||||
ACTIONS = [action for action in OPTION_SUBTREE[category]["actions"].keys()
|
||||
if not action.startswith('_')]
|
||||
if not action.startswith('_')]
|
||||
ACTIONS_STR = '{}'.format(' '.join(ACTIONS))
|
||||
|
||||
DICT = { "actions_str": ACTIONS_STR }
|
||||
DICT = {"actions_str": ACTIONS_STR}
|
||||
|
||||
return DICT
|
||||
|
||||
|
||||
with open(ACTIONSMAP_FILE, 'r') as stream:
|
||||
|
||||
# Getting the dictionary containning what actions are possible per category
|
||||
|
@ -40,10 +42,10 @@ with open(ACTIONSMAP_FILE, 'r') as stream:
|
|||
ACTIONS_DICT[category]["subcategories_str"] = ""
|
||||
|
||||
if "subcategories" in OPTION_TREE[category].keys():
|
||||
SUBCATEGORIES = [ subcategory for subcategory in OPTION_TREE[category]["subcategories"].keys() ]
|
||||
SUBCATEGORIES = [subcategory for subcategory in OPTION_TREE[category]["subcategories"].keys()]
|
||||
|
||||
SUBCATEGORIES_STR = '{}'.format(' '.join(SUBCATEGORIES))
|
||||
|
||||
|
||||
ACTIONS_DICT[category]["subcategories_str"] = SUBCATEGORIES_STR
|
||||
|
||||
for subcategory in SUBCATEGORIES:
|
||||
|
|
|
@ -63,10 +63,10 @@ class BaseSystemDiagnoser(Diagnoser):
|
|||
ynh_core_version = ynh_packages["yunohost"]["version"]
|
||||
consistent_versions = all(infos["version"][:3] == ynh_core_version[:3] for infos in ynh_packages.values())
|
||||
ynh_version_details = [("diagnosis_basesystem_ynh_single_version",
|
||||
{"package":package,
|
||||
{"package": package,
|
||||
"version": infos["version"],
|
||||
"repo": infos["repo"]}
|
||||
)
|
||||
)
|
||||
for package, infos in ynh_packages.items()]
|
||||
|
||||
yield dict(meta={"test": "ynh_versions"},
|
||||
|
@ -75,7 +75,6 @@ class BaseSystemDiagnoser(Diagnoser):
|
|||
summary="diagnosis_basesystem_ynh_main_version" if consistent_versions else "diagnosis_basesystem_ynh_inconsistent_versions",
|
||||
details=ynh_version_details)
|
||||
|
||||
|
||||
if self.is_vulnerable_to_meltdown():
|
||||
yield dict(meta={"test": "meltdown"},
|
||||
status="ERROR",
|
||||
|
|
|
@ -5,6 +5,7 @@ import os
|
|||
from yunohost.diagnosis import Diagnoser
|
||||
from yunohost.service import _get_services
|
||||
|
||||
|
||||
class PortsDiagnoser(Diagnoser):
|
||||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
|
|
|
@ -47,7 +47,6 @@ class MailDiagnoser(Diagnoser):
|
|||
status="SUCCESS",
|
||||
summary="diagnosis_mail_" + name + "_ok")
|
||||
|
||||
|
||||
def check_outgoing_port_25(self):
|
||||
"""
|
||||
Check outgoing port 25 is open and not blocked by router
|
||||
|
@ -64,7 +63,6 @@ class MailDiagnoser(Diagnoser):
|
|||
details=["diagnosis_mail_outgoing_port_25_blocked_details",
|
||||
"diagnosis_mail_outgoing_port_25_blocked_relay_vpn"])
|
||||
|
||||
|
||||
def check_ehlo(self):
|
||||
"""
|
||||
Check the server is reachable from outside and it's the good one
|
||||
|
@ -99,7 +97,6 @@ class MailDiagnoser(Diagnoser):
|
|||
summary="diagnosis_mail_ehlo_wrong",
|
||||
details=["diagnosis_mail_ehlo_wrong_details"])
|
||||
|
||||
|
||||
def check_fcrdns(self):
|
||||
"""
|
||||
Check the reverse DNS is well defined by doing a Forward-confirmed
|
||||
|
@ -148,7 +145,6 @@ class MailDiagnoser(Diagnoser):
|
|||
summary="diagnosis_mail_fcrdns_different_from_ehlo_domain",
|
||||
details=details)
|
||||
|
||||
|
||||
def check_blacklist(self):
|
||||
"""
|
||||
Check with dig onto blacklist DNS server
|
||||
|
@ -225,7 +221,6 @@ class MailDiagnoser(Diagnoser):
|
|||
status="SUCCESS",
|
||||
summary="diagnosis_mail_queue_ok")
|
||||
|
||||
|
||||
def get_ips_checked(self):
|
||||
outgoing_ipversions = []
|
||||
outgoing_ips = []
|
||||
|
@ -245,5 +240,6 @@ class MailDiagnoser(Diagnoser):
|
|||
outgoing_ips.append(global_ipv6)
|
||||
return (outgoing_ipversions, outgoing_ips)
|
||||
|
||||
|
||||
def main(args, env, loggers):
|
||||
return MailDiagnoser(args, env, loggers).diagnose()
|
||||
|
|
|
@ -5,6 +5,7 @@ import os
|
|||
from yunohost.diagnosis import Diagnoser
|
||||
from yunohost.service import service_status
|
||||
|
||||
|
||||
class ServicesDiagnoser(Diagnoser):
|
||||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
|
@ -36,5 +37,6 @@ class ServicesDiagnoser(Diagnoser):
|
|||
|
||||
yield item
|
||||
|
||||
|
||||
def main(args, env, loggers):
|
||||
return ServicesDiagnoser(args, env, loggers).diagnose()
|
||||
|
|
|
@ -7,6 +7,7 @@ import re
|
|||
|
||||
from yunohost.diagnosis import Diagnoser
|
||||
|
||||
|
||||
class SystemResourcesDiagnoser(Diagnoser):
|
||||
|
||||
id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
|
||||
|
@ -16,7 +17,7 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
def run(self):
|
||||
|
||||
MB = 1024**2
|
||||
GB = MB*1024
|
||||
GB = MB * 1024
|
||||
|
||||
#
|
||||
# RAM
|
||||
|
@ -79,7 +80,7 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
# N.B.: we do not use usage.total because we want
|
||||
# to take into account the 5% security margin
|
||||
# correctly (c.f. the doc of psutil ...)
|
||||
"total": human_size(usage.used+usage.free),
|
||||
"total": human_size(usage.used + usage.free),
|
||||
"free": human_size(usage.free),
|
||||
"free_percent": free_percent})
|
||||
|
||||
|
@ -96,7 +97,6 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
item["status"] = "SUCCESS"
|
||||
item["summary"] = "diagnosis_diskusage_ok"
|
||||
|
||||
|
||||
yield item
|
||||
|
||||
#
|
||||
|
@ -112,7 +112,6 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
summary="diagnosis_processes_killed_by_oom_reaper",
|
||||
data={"kills_summary": kills_summary})
|
||||
|
||||
|
||||
def recent_kills_by_oom_reaper(self):
|
||||
if not os.path.exists("/var/log/kern.log"):
|
||||
return []
|
||||
|
@ -145,7 +144,7 @@ class SystemResourcesDiagnoser(Diagnoser):
|
|||
|
||||
def human_size(bytes_):
|
||||
# Adapted from https://stackoverflow.com/a/1094933
|
||||
for unit in ['','ki','Mi','Gi','Ti','Pi','Ei','Zi']:
|
||||
for unit in ['', 'ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
|
||||
if abs(bytes_) < 1024.0:
|
||||
return "%s %sB" % (round_(bytes_), unit)
|
||||
bytes_ /= 1024.0
|
||||
|
@ -160,5 +159,6 @@ def round_(n):
|
|||
n = int(round(n))
|
||||
return n
|
||||
|
||||
|
||||
def main(args, env, loggers):
|
||||
return SystemResourcesDiagnoser(args, env, loggers).diagnose()
|
||||
|
|
|
@ -4,12 +4,13 @@ import os
|
|||
import glob
|
||||
import datetime
|
||||
|
||||
|
||||
def render(helpers):
|
||||
|
||||
data = { "helpers": helpers,
|
||||
"date": datetime.datetime.now().strftime("%m/%d/%Y"),
|
||||
"version": open("../debian/changelog").readlines()[0].split()[1].strip("()")
|
||||
}
|
||||
data = {"helpers": helpers,
|
||||
"date": datetime.datetime.now().strftime("%m/%d/%Y"),
|
||||
"version": open("../debian/changelog").readlines()[0].split()[1].strip("()")
|
||||
}
|
||||
|
||||
from jinja2 import Template
|
||||
from ansi2html import Ansi2HTMLConverter
|
||||
|
@ -22,13 +23,14 @@ def render(helpers):
|
|||
return conv.convert(shell, False)
|
||||
|
||||
template = open("helper_doc_template.html", "r").read()
|
||||
t = Template(template)
|
||||
t = Template(template)
|
||||
t.globals['now'] = datetime.datetime.utcnow
|
||||
result = t.render(data=data, convert=shell_to_html, shell_css=shell_css)
|
||||
open("helpers.html", "w").write(result)
|
||||
|
||||
##############################################################################
|
||||
|
||||
|
||||
class Parser():
|
||||
|
||||
def __init__(self, filename):
|
||||
|
@ -42,15 +44,15 @@ class Parser():
|
|||
self.blocks = []
|
||||
|
||||
current_reading = "void"
|
||||
current_block = { "name": None,
|
||||
"line": -1,
|
||||
"comments": [],
|
||||
"code": [] }
|
||||
current_block = {"name": None,
|
||||
"line": -1,
|
||||
"comments": [],
|
||||
"code": []}
|
||||
|
||||
for i, line in enumerate(self.file):
|
||||
|
||||
if line.startswith("#!/bin/bash"):
|
||||
continue
|
||||
continue
|
||||
|
||||
line = line.rstrip().replace("\t", " ")
|
||||
|
||||
|
@ -73,7 +75,7 @@ class Parser():
|
|||
elif line.strip() == "":
|
||||
# Well eh that was not an actual helper definition ... start over ?
|
||||
current_reading = "void"
|
||||
current_block = { "name": None,
|
||||
current_block = {"name": None,
|
||||
"line": -1,
|
||||
"comments": [],
|
||||
"code": []
|
||||
|
@ -101,10 +103,10 @@ class Parser():
|
|||
# (we ignore helpers containing [internal] ...)
|
||||
if not "[internal]" in current_block["comments"]:
|
||||
self.blocks.append(current_block)
|
||||
current_block = { "name": None,
|
||||
"line": -1,
|
||||
"comments": [],
|
||||
"code": [] }
|
||||
current_block = {"name": None,
|
||||
"line": -1,
|
||||
"comments": [],
|
||||
"code": []}
|
||||
else:
|
||||
current_block["code"].append(line)
|
||||
|
||||
|
@ -180,13 +182,14 @@ class Parser():
|
|||
b["usage"] = b["usage"].strip()
|
||||
|
||||
|
||||
|
||||
def is_global_comment(line):
|
||||
return line.startswith('#')
|
||||
|
||||
|
||||
def malformed_error(line_number):
|
||||
return "Malformed file line {} ?".format(line_number)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
helper_files = sorted(glob.glob("../data/helpers.d/*"))
|
||||
|
@ -204,5 +207,5 @@ def main():
|
|||
|
||||
render(helpers)
|
||||
|
||||
main()
|
||||
|
||||
main()
|
||||
|
|
|
@ -36,7 +36,7 @@ class MyMigration(Migration):
|
|||
raise YunohostError("migration_0017_not_enough_space", path="/var/lib/postgresql/")
|
||||
|
||||
self.runcmd("systemctl stop postgresql")
|
||||
self.runcmd("pg_dropcluster --stop 11 main || true") # We do not trigger an exception if the command fails because that probably means cluster 11 doesn't exists, which is fine because it's created during the pg_upgradecluster)
|
||||
self.runcmd("pg_dropcluster --stop 11 main || true") # We do not trigger an exception if the command fails because that probably means cluster 11 doesn't exists, which is fine because it's created during the pg_upgradecluster)
|
||||
self.runcmd("pg_upgradecluster -m upgrade 9.6 main")
|
||||
self.runcmd("pg_dropcluster --stop 9.6 main")
|
||||
self.runcmd("systemctl start postgresql")
|
||||
|
@ -63,4 +63,3 @@ class MyMigration(Migration):
|
|||
|
||||
out = out.strip().split("\n")
|
||||
return (returncode, out, err)
|
||||
|
||||
|
|
|
@ -106,4 +106,3 @@ class MyMigration(Migration):
|
|||
|
||||
out = out.strip().split("\n")
|
||||
return (returncode, out, err)
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ def clone_test_app(request):
|
|||
else:
|
||||
os.system("cd %s/apps && git pull > /dev/null 2>&1" % cwd)
|
||||
|
||||
|
||||
def get_test_apps_dir():
|
||||
cwd = os.path.split(os.path.realpath(__file__))[0]
|
||||
return os.path.join(cwd, "apps")
|
||||
|
||||
|
||||
@contextmanager
|
||||
def message(mocker, key, **kwargs):
|
||||
mocker.spy(m18n, "n")
|
||||
|
@ -38,7 +40,6 @@ def raiseYunohostError(mocker, key, **kwargs):
|
|||
assert e_info._excinfo[1].kwargs == kwargs
|
||||
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption("--yunodebug", action="store_true", default=False)
|
||||
|
||||
|
@ -56,12 +57,15 @@ def new_translate(self, key, *args, **kwargs):
|
|||
raise KeyError("Unable to retrieve key %s for default locale !" % key)
|
||||
|
||||
return old_translate(self, key, *args, **kwargs)
|
||||
|
||||
|
||||
moulinette.core.Translator.translate = new_translate
|
||||
|
||||
|
||||
def new_m18nn(self, key, *args, **kwargs):
|
||||
return self._namespaces[self._current_namespace].translate(key, *args, **kwargs)
|
||||
|
||||
|
||||
moulinette.core.Moulinette18n.n = new_m18nn
|
||||
|
||||
#
|
||||
|
|
|
@ -40,21 +40,21 @@ def test_parse_args_in_yunohost_format_empty():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string():
|
||||
questions = [{"name": "some_string", "type": "string",}]
|
||||
questions = [{"name": "some_string", "type": "string", }]
|
||||
answers = {"some_string": "some_value"}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string_default_type():
|
||||
questions = [{"name": "some_string",}]
|
||||
questions = [{"name": "some_string", }]
|
||||
answers = {"some_string": "some_value"}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string_no_input():
|
||||
questions = [{"name": "some_string",}]
|
||||
questions = [{"name": "some_string", }]
|
||||
answers = {}
|
||||
|
||||
with pytest.raises(YunohostError):
|
||||
|
@ -62,7 +62,7 @@ def test_parse_args_in_yunohost_format_string_no_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string_input():
|
||||
questions = [{"name": "some_string", "ask": "some question",}]
|
||||
questions = [{"name": "some_string", "ask": "some question", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
|
||||
|
@ -72,7 +72,7 @@ def test_parse_args_in_yunohost_format_string_input():
|
|||
|
||||
@pytest.mark.skip # that shit should work x(
|
||||
def test_parse_args_in_yunohost_format_string_input_no_ask():
|
||||
questions = [{"name": "some_string",}]
|
||||
questions = [{"name": "some_string", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
|
||||
|
@ -81,14 +81,14 @@ def test_parse_args_in_yunohost_format_string_input_no_ask():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string_no_input_optional():
|
||||
questions = [{"name": "some_string", "optional": True,}]
|
||||
questions = [{"name": "some_string", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("", "string")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_string_optional_with_input():
|
||||
questions = [{"name": "some_string", "ask": "some question", "optional": True,}]
|
||||
questions = [{"name": "some_string", "ask": "some question", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
|
||||
|
@ -98,7 +98,7 @@ def test_parse_args_in_yunohost_format_string_optional_with_input():
|
|||
|
||||
@pytest.mark.skip # this should work without ask
|
||||
def test_parse_args_in_yunohost_format_string_optional_with_input_without_ask():
|
||||
questions = [{"name": "some_string", "optional": True,}]
|
||||
questions = [{"name": "some_string", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
|
||||
|
@ -108,7 +108,7 @@ def test_parse_args_in_yunohost_format_string_optional_with_input_without_ask():
|
|||
|
||||
def test_parse_args_in_yunohost_format_string_no_input_default():
|
||||
questions = [
|
||||
{"name": "some_string", "ask": "some question", "default": "some_value",}
|
||||
{"name": "some_string", "ask": "some question", "default": "some_value", }
|
||||
]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_string": ("some_value", "string")})
|
||||
|
@ -117,7 +117,7 @@ def test_parse_args_in_yunohost_format_string_no_input_default():
|
|||
|
||||
def test_parse_args_in_yunohost_format_string_input_test_ask():
|
||||
ask_text = "some question"
|
||||
questions = [{"name": "some_string", "ask": ask_text,}]
|
||||
questions = [{"name": "some_string", "ask": ask_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -128,7 +128,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask():
|
|||
def test_parse_args_in_yunohost_format_string_input_test_ask_with_default():
|
||||
ask_text = "some question"
|
||||
default_text = "some example"
|
||||
questions = [{"name": "some_string", "ask": ask_text, "default": default_text,}]
|
||||
questions = [{"name": "some_string", "ask": ask_text, "default": default_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -140,7 +140,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_default():
|
|||
def test_parse_args_in_yunohost_format_string_input_test_ask_with_example():
|
||||
ask_text = "some question"
|
||||
example_text = "some example"
|
||||
questions = [{"name": "some_string", "ask": ask_text, "example": example_text,}]
|
||||
questions = [{"name": "some_string", "ask": ask_text, "example": example_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -153,7 +153,7 @@ def test_parse_args_in_yunohost_format_string_input_test_ask_with_example():
|
|||
def test_parse_args_in_yunohost_format_string_input_test_ask_with_help():
|
||||
ask_text = "some question"
|
||||
help_text = "some_help"
|
||||
questions = [{"name": "some_string", "ask": ask_text, "help": help_text,}]
|
||||
questions = [{"name": "some_string", "ask": ask_text, "help": help_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -188,7 +188,7 @@ def test_parse_args_in_yunohost_format_string_with_choice_bad():
|
|||
def test_parse_args_in_yunohost_format_string_with_choice_ask():
|
||||
ask_text = "some question"
|
||||
choices = ["fr", "en", "es", "it", "ru"]
|
||||
questions = [{"name": "some_string", "ask": ask_text, "choices": choices,}]
|
||||
questions = [{"name": "some_string", "ask": ask_text, "choices": choices, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="ru") as prompt:
|
||||
|
@ -214,14 +214,14 @@ def test_parse_args_in_yunohost_format_string_with_choice_default():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_password():
|
||||
questions = [{"name": "some_password", "type": "password",}]
|
||||
questions = [{"name": "some_password", "type": "password", }]
|
||||
answers = {"some_password": "some_value"}
|
||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_password_no_input():
|
||||
questions = [{"name": "some_password", "type": "password",}]
|
||||
questions = [{"name": "some_password", "type": "password", }]
|
||||
answers = {}
|
||||
|
||||
with pytest.raises(YunohostError):
|
||||
|
@ -229,7 +229,7 @@ def test_parse_args_in_yunohost_format_password_no_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_password_input():
|
||||
questions = [{"name": "some_password", "type": "password", "ask": "some question",}]
|
||||
questions = [{"name": "some_password", "type": "password", "ask": "some question", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||
|
||||
|
@ -239,7 +239,7 @@ def test_parse_args_in_yunohost_format_password_input():
|
|||
|
||||
@pytest.mark.skip # that shit should work x(
|
||||
def test_parse_args_in_yunohost_format_password_input_no_ask():
|
||||
questions = [{"name": "some_password", "type": "password",}]
|
||||
questions = [{"name": "some_password", "type": "password", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||
|
||||
|
@ -248,7 +248,7 @@ def test_parse_args_in_yunohost_format_password_input_no_ask():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_password_no_input_optional():
|
||||
questions = [{"name": "some_password", "type": "password", "optional": True,}]
|
||||
questions = [{"name": "some_password", "type": "password", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_password": ("", "password")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
@ -272,7 +272,7 @@ def test_parse_args_in_yunohost_format_password_optional_with_input():
|
|||
|
||||
@pytest.mark.skip # this should work without ask
|
||||
def test_parse_args_in_yunohost_format_password_optional_with_input_without_ask():
|
||||
questions = [{"name": "some_password", "type": "password", "optional": True,}]
|
||||
questions = [{"name": "some_password", "type": "password", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||
|
||||
|
@ -316,7 +316,7 @@ def test_parse_args_in_yunohost_format_password_no_input_example():
|
|||
|
||||
def test_parse_args_in_yunohost_format_password_input_test_ask():
|
||||
ask_text = "some question"
|
||||
questions = [{"name": "some_password", "type": "password", "ask": ask_text,}]
|
||||
questions = [{"name": "some_password", "type": "password", "ask": ask_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -365,14 +365,14 @@ def test_parse_args_in_yunohost_format_password_input_test_ask_with_help():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_path():
|
||||
questions = [{"name": "some_path", "type": "path",}]
|
||||
questions = [{"name": "some_path", "type": "path", }]
|
||||
answers = {"some_path": "some_value"}
|
||||
expected_result = OrderedDict({"some_path": ("some_value", "path")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_path_no_input():
|
||||
questions = [{"name": "some_path", "type": "path",}]
|
||||
questions = [{"name": "some_path", "type": "path", }]
|
||||
answers = {}
|
||||
|
||||
with pytest.raises(YunohostError):
|
||||
|
@ -380,7 +380,7 @@ def test_parse_args_in_yunohost_format_path_no_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_path_input():
|
||||
questions = [{"name": "some_path", "type": "path", "ask": "some question",}]
|
||||
questions = [{"name": "some_path", "type": "path", "ask": "some question", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_path": ("some_value", "path")})
|
||||
|
||||
|
@ -390,7 +390,7 @@ def test_parse_args_in_yunohost_format_path_input():
|
|||
|
||||
@pytest.mark.skip # that shit should work x(
|
||||
def test_parse_args_in_yunohost_format_path_input_no_ask():
|
||||
questions = [{"name": "some_path", "type": "path",}]
|
||||
questions = [{"name": "some_path", "type": "path", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_path": ("some_value", "path")})
|
||||
|
||||
|
@ -399,7 +399,7 @@ def test_parse_args_in_yunohost_format_path_input_no_ask():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_path_no_input_optional():
|
||||
questions = [{"name": "some_path", "type": "path", "optional": True,}]
|
||||
questions = [{"name": "some_path", "type": "path", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_path": ("", "path")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
@ -407,7 +407,7 @@ def test_parse_args_in_yunohost_format_path_no_input_optional():
|
|||
|
||||
def test_parse_args_in_yunohost_format_path_optional_with_input():
|
||||
questions = [
|
||||
{"name": "some_path", "ask": "some question", "type": "path", "optional": True,}
|
||||
{"name": "some_path", "ask": "some question", "type": "path", "optional": True, }
|
||||
]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_path": ("some_value", "path")})
|
||||
|
@ -418,7 +418,7 @@ def test_parse_args_in_yunohost_format_path_optional_with_input():
|
|||
|
||||
@pytest.mark.skip # this should work without ask
|
||||
def test_parse_args_in_yunohost_format_path_optional_with_input_without_ask():
|
||||
questions = [{"name": "some_path", "type": "path", "optional": True,}]
|
||||
questions = [{"name": "some_path", "type": "path", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_path": ("some_value", "path")})
|
||||
|
||||
|
@ -442,7 +442,7 @@ def test_parse_args_in_yunohost_format_path_no_input_default():
|
|||
|
||||
def test_parse_args_in_yunohost_format_path_input_test_ask():
|
||||
ask_text = "some question"
|
||||
questions = [{"name": "some_path", "type": "path", "ask": ask_text,}]
|
||||
questions = [{"name": "some_path", "type": "path", "ask": ask_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value="some_value") as prompt:
|
||||
|
@ -454,7 +454,7 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_default():
|
|||
ask_text = "some question"
|
||||
default_text = "some example"
|
||||
questions = [
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "default": default_text,}
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "default": default_text, }
|
||||
]
|
||||
answers = {}
|
||||
|
||||
|
@ -468,7 +468,7 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_example():
|
|||
ask_text = "some question"
|
||||
example_text = "some example"
|
||||
questions = [
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "example": example_text,}
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "example": example_text, }
|
||||
]
|
||||
answers = {}
|
||||
|
||||
|
@ -483,7 +483,7 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_help():
|
|||
ask_text = "some question"
|
||||
help_text = "some_help"
|
||||
questions = [
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "help": help_text,}
|
||||
{"name": "some_path", "type": "path", "ask": ask_text, "help": help_text, }
|
||||
]
|
||||
answers = {}
|
||||
|
||||
|
@ -494,89 +494,89 @@ def test_parse_args_in_yunohost_format_path_input_test_ask_with_help():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
answers = {"some_boolean": "y"}
|
||||
expected_result = OrderedDict({"some_boolean": (1, "boolean")})
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_all_yes():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
expected_result = OrderedDict({"some_boolean": (1, "boolean")})
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "y"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "y"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "Y"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "Y"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "yes"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "yes"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "Yes"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "YES"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "YES"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "1"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "1"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": 1}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": 1}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": True}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": True}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_all_no():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
expected_result = OrderedDict({"some_boolean": (0, "boolean")})
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "n"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "n"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "N"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "N"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "no"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "no"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "No"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": "0"}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": "0"}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": 0}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": 0}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
assert (
|
||||
_parse_args_in_yunohost_format({"some_boolean": False}, questions)
|
||||
== expected_result
|
||||
_parse_args_in_yunohost_format({"some_boolean": False}, questions) ==
|
||||
expected_result
|
||||
)
|
||||
|
||||
|
||||
# XXX apparently boolean are always False (0) by default, I'm not sure what to think about that
|
||||
def test_parse_args_in_yunohost_format_boolean_no_input():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
answers = {}
|
||||
|
||||
expected_result = OrderedDict({"some_boolean": (0, "boolean")})
|
||||
|
@ -584,7 +584,7 @@ def test_parse_args_in_yunohost_format_boolean_no_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_bad_input():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
answers = {"some_boolean": "stuff"}
|
||||
|
||||
with pytest.raises(YunohostError):
|
||||
|
@ -592,7 +592,7 @@ def test_parse_args_in_yunohost_format_boolean_bad_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_input():
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "ask": "some question",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "ask": "some question", }]
|
||||
answers = {}
|
||||
|
||||
expected_result = OrderedDict({"some_boolean": (1, "boolean")})
|
||||
|
@ -606,7 +606,7 @@ def test_parse_args_in_yunohost_format_boolean_input():
|
|||
|
||||
@pytest.mark.skip # we should work
|
||||
def test_parse_args_in_yunohost_format_boolean_input_no_ask():
|
||||
questions = [{"name": "some_boolean", "type": "boolean",}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_boolean": ("some_value", "boolean")})
|
||||
|
||||
|
@ -615,7 +615,7 @@ def test_parse_args_in_yunohost_format_boolean_input_no_ask():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_no_input_optional():
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "optional": True,}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_boolean": (0, "boolean")}) # default to false
|
||||
assert _parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||
|
@ -638,7 +638,7 @@ def test_parse_args_in_yunohost_format_boolean_optional_with_input():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_boolean_optional_with_input_without_ask():
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "optional": True,}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "optional": True, }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_boolean": (0, "boolean")})
|
||||
|
||||
|
@ -677,7 +677,7 @@ def test_parse_args_in_yunohost_format_boolean_bad_default():
|
|||
|
||||
def test_parse_args_in_yunohost_format_boolean_input_test_ask():
|
||||
ask_text = "some question"
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "ask": ask_text,}]
|
||||
questions = [{"name": "some_boolean", "type": "boolean", "ask": ask_text, }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(msignals, "prompt", return_value=0) as prompt:
|
||||
|
@ -704,7 +704,7 @@ def test_parse_args_in_yunohost_format_boolean_input_test_ask_with_default():
|
|||
|
||||
|
||||
def test_parse_args_in_yunohost_format_domain_empty():
|
||||
questions = [{"name": "some_domain", "type": "domain",}]
|
||||
questions = [{"name": "some_domain", "type": "domain", }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(
|
||||
|
@ -719,7 +719,7 @@ def test_parse_args_in_yunohost_format_domain_empty():
|
|||
def test_parse_args_in_yunohost_format_domain():
|
||||
main_domain = "my_main_domain.com"
|
||||
domains = [main_domain]
|
||||
questions = [{"name": "some_domain", "type": "domain",}]
|
||||
questions = [{"name": "some_domain", "type": "domain", }]
|
||||
|
||||
answers = {"some_domain": main_domain}
|
||||
expected_result = OrderedDict({"some_domain": (main_domain, "domain")})
|
||||
|
@ -735,7 +735,7 @@ def test_parse_args_in_yunohost_format_domain_two_domains():
|
|||
other_domain = "some_other_domain.tld"
|
||||
domains = [main_domain, other_domain]
|
||||
|
||||
questions = [{"name": "some_domain", "type": "domain",}]
|
||||
questions = [{"name": "some_domain", "type": "domain", }]
|
||||
answers = {"some_domain": other_domain}
|
||||
expected_result = OrderedDict({"some_domain": (other_domain, "domain")})
|
||||
|
||||
|
@ -758,7 +758,7 @@ def test_parse_args_in_yunohost_format_domain_two_domains_wrong_answer():
|
|||
other_domain = "some_other_domain.tld"
|
||||
domains = [main_domain, other_domain]
|
||||
|
||||
questions = [{"name": "some_domain", "type": "domain",}]
|
||||
questions = [{"name": "some_domain", "type": "domain", }]
|
||||
answers = {"some_domain": "doesnt_exist.pouet"}
|
||||
|
||||
with patch.object(
|
||||
|
@ -774,7 +774,7 @@ def test_parse_args_in_yunohost_format_domain_two_domains_default_no_ask():
|
|||
other_domain = "some_other_domain.tld"
|
||||
domains = [main_domain, other_domain]
|
||||
|
||||
questions = [{"name": "some_domain", "type": "domain",}]
|
||||
questions = [{"name": "some_domain", "type": "domain", }]
|
||||
answers = {}
|
||||
expected_result = OrderedDict({"some_domain": (main_domain, "domain")})
|
||||
|
||||
|
@ -831,7 +831,7 @@ def test_parse_args_in_yunohost_format_user_empty():
|
|||
}
|
||||
}
|
||||
|
||||
questions = [{"name": "some_user", "type": "user",}]
|
||||
questions = [{"name": "some_user", "type": "user", }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(user, "user_list", return_value={"users": users}):
|
||||
|
@ -852,7 +852,7 @@ def test_parse_args_in_yunohost_format_user():
|
|||
}
|
||||
}
|
||||
|
||||
questions = [{"name": "some_user", "type": "user",}]
|
||||
questions = [{"name": "some_user", "type": "user", }]
|
||||
answers = {"some_user": username}
|
||||
|
||||
expected_result = OrderedDict({"some_user": (username, "user")})
|
||||
|
@ -883,7 +883,7 @@ def test_parse_args_in_yunohost_format_user_two_users():
|
|||
},
|
||||
}
|
||||
|
||||
questions = [{"name": "some_user", "type": "user",}]
|
||||
questions = [{"name": "some_user", "type": "user", }]
|
||||
answers = {"some_user": other_user}
|
||||
expected_result = OrderedDict({"some_user": (other_user, "user")})
|
||||
|
||||
|
@ -919,7 +919,7 @@ def test_parse_args_in_yunohost_format_user_two_users_wrong_answer():
|
|||
},
|
||||
}
|
||||
|
||||
questions = [{"name": "some_user", "type": "user",}]
|
||||
questions = [{"name": "some_user", "type": "user", }]
|
||||
answers = {"some_user": "doesnt_exist.pouet"}
|
||||
|
||||
with patch.object(user, "user_list", return_value={"users": users}):
|
||||
|
@ -1002,7 +1002,7 @@ def test_parse_args_in_yunohost_format_app_empty():
|
|||
}
|
||||
]
|
||||
|
||||
questions = [{"name": "some_app", "type": "app",}]
|
||||
questions = [{"name": "some_app", "type": "app", }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(app, "app_list", return_value={"apps": apps}):
|
||||
|
@ -1012,7 +1012,7 @@ def test_parse_args_in_yunohost_format_app_empty():
|
|||
|
||||
def test_parse_args_in_yunohost_format_app_no_apps():
|
||||
apps = []
|
||||
questions = [{"name": "some_app", "type": "app",}]
|
||||
questions = [{"name": "some_app", "type": "app", }]
|
||||
answers = {}
|
||||
|
||||
with patch.object(app, "app_list", return_value={"apps": apps}):
|
||||
|
@ -1041,7 +1041,7 @@ def test_parse_args_in_yunohost_format_app():
|
|||
}
|
||||
]
|
||||
|
||||
questions = [{"name": "some_app", "type": "app",}]
|
||||
questions = [{"name": "some_app", "type": "app", }]
|
||||
answers = {"some_app": app_name}
|
||||
|
||||
expected_result = OrderedDict({"some_app": (app_name, "app")})
|
||||
|
@ -1072,7 +1072,7 @@ def test_parse_args_in_yunohost_format_app_two_apps():
|
|||
},
|
||||
]
|
||||
|
||||
questions = [{"name": "some_app", "type": "app",}]
|
||||
questions = [{"name": "some_app", "type": "app", }]
|
||||
answers = {"some_app": other_app}
|
||||
expected_result = OrderedDict({"some_app": (other_app, "app")})
|
||||
|
||||
|
@ -1112,7 +1112,7 @@ def test_parse_args_in_yunohost_format_app_two_apps_wrong_answer():
|
|||
},
|
||||
]
|
||||
|
||||
questions = [{"name": "some_app", "type": "app",}]
|
||||
questions = [{"name": "some_app", "type": "app", }]
|
||||
answers = {"some_app": "doesnt_exist"}
|
||||
|
||||
with pytest.raises(YunohostError):
|
||||
|
|
|
@ -37,10 +37,12 @@ DUMMY_APP_CATALOG = """{
|
|||
}
|
||||
"""
|
||||
|
||||
|
||||
class AnyStringWith(str):
|
||||
def __eq__(self, other):
|
||||
return self in other
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
|
||||
# Clear apps catalog cache
|
||||
|
@ -165,6 +167,7 @@ def test_apps_catalog_update_404(mocker):
|
|||
_update_apps_catalog()
|
||||
m18n.n.assert_any_call("apps_catalog_failed_to_download")
|
||||
|
||||
|
||||
def test_apps_catalog_update_timeout(mocker):
|
||||
|
||||
# Initialize ...
|
||||
|
@ -237,7 +240,6 @@ def test_apps_catalog_load_with_empty_cache(mocker):
|
|||
m18n.n.assert_any_call("apps_catalog_obsolete_cache")
|
||||
m18n.n.assert_any_call("apps_catalog_update_success")
|
||||
|
||||
|
||||
# Cache shouldn't be empty anymore empty
|
||||
assert glob.glob(APPS_CATALOG_CACHE + "/*")
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ from yunohost.hook import CUSTOM_HOOK_FOLDER
|
|||
# Get main domain
|
||||
maindomain = ""
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
|
||||
global maindomain
|
||||
|
@ -32,7 +33,7 @@ def setup_function(function):
|
|||
|
||||
assert len(backup_list()["archives"]) == 0
|
||||
|
||||
markers = [m.name for m in function.__dict__.get("pytestmark",[])]
|
||||
markers = [m.name for m in function.__dict__.get("pytestmark", [])]
|
||||
|
||||
if "with_wordpress_archive_from_2p4" in markers:
|
||||
add_archive_wordpress_from_2p4()
|
||||
|
@ -75,7 +76,7 @@ def teardown_function(function):
|
|||
delete_all_backups()
|
||||
uninstall_test_apps_if_needed()
|
||||
|
||||
markers = [m.name for m in function.__dict__.get("pytestmark",[])]
|
||||
markers = [m.name for m in function.__dict__.get("pytestmark", [])]
|
||||
|
||||
if "clean_opt_dir" in markers:
|
||||
shutil.rmtree("/opt/test_backup_output_directory")
|
||||
|
@ -90,6 +91,7 @@ def check_LDAP_db_integrity_call():
|
|||
yield
|
||||
check_LDAP_db_integrity()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def check_permission_for_apps_call():
|
||||
check_permission_for_apps()
|
||||
|
@ -100,6 +102,7 @@ def check_permission_for_apps_call():
|
|||
# Helpers #
|
||||
#
|
||||
|
||||
|
||||
def app_is_installed(app):
|
||||
|
||||
if app == "permissions_app":
|
||||
|
@ -184,22 +187,22 @@ def add_archive_wordpress_from_2p4():
|
|||
|
||||
os.system("mkdir -p /home/yunohost.backup/archives")
|
||||
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.info.json") + \
|
||||
" /home/yunohost.backup/archives/backup_wordpress_from_2p4.info.json")
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.info.json")
|
||||
+ " /home/yunohost.backup/archives/backup_wordpress_from_2p4.info.json")
|
||||
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.tar.gz") + \
|
||||
" /home/yunohost.backup/archives/backup_wordpress_from_2p4.tar.gz")
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_wordpress_from_2p4/backup.tar.gz")
|
||||
+ " /home/yunohost.backup/archives/backup_wordpress_from_2p4.tar.gz")
|
||||
|
||||
|
||||
def add_archive_system_from_2p4():
|
||||
|
||||
os.system("mkdir -p /home/yunohost.backup/archives")
|
||||
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.info.json") + \
|
||||
" /home/yunohost.backup/archives/backup_system_from_2p4.info.json")
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.info.json")
|
||||
+ " /home/yunohost.backup/archives/backup_system_from_2p4.info.json")
|
||||
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.tar.gz") + \
|
||||
" /home/yunohost.backup/archives/backup_system_from_2p4.tar.gz")
|
||||
os.system("cp " + os.path.join(get_test_apps_dir(), "backup_system_from_2p4/backup.tar.gz")
|
||||
+ " /home/yunohost.backup/archives/backup_system_from_2p4.tar.gz")
|
||||
|
||||
#
|
||||
# System backup #
|
||||
|
@ -309,7 +312,7 @@ def test_backup_script_failure_handling(monkeypatch, mocker):
|
|||
# with the expected error message key
|
||||
monkeypatch.setattr("yunohost.backup.hook_exec", custom_hook_exec)
|
||||
|
||||
with message(mocker, 'backup_app_failed', app='backup_recommended_app'):
|
||||
with message(mocker, 'backup_app_failed', app='backup_recommended_app'):
|
||||
with raiseYunohostError(mocker, 'backup_nothings_done'):
|
||||
backup_create(system=None, apps=["backup_recommended_app"])
|
||||
|
||||
|
@ -499,6 +502,7 @@ def test_backup_and_restore_with_ynh_restore(mocker):
|
|||
|
||||
_test_backup_and_restore_app(mocker, "backup_recommended_app")
|
||||
|
||||
|
||||
@pytest.mark.with_permission_app_installed
|
||||
def test_backup_and_restore_permission_app(mocker):
|
||||
|
||||
|
@ -548,7 +552,7 @@ def _test_backup_and_restore_app(mocker, app):
|
|||
# Uninstall the app
|
||||
app_remove(app)
|
||||
assert not app_is_installed(app)
|
||||
assert app+".main" not in user_permission_list()['permissions']
|
||||
assert app + ".main" not in user_permission_list()['permissions']
|
||||
|
||||
# Restore the app
|
||||
with message(mocker, "restore_complete"):
|
||||
|
@ -559,7 +563,7 @@ def _test_backup_and_restore_app(mocker, app):
|
|||
|
||||
# Check permission
|
||||
per_list = user_permission_list()['permissions']
|
||||
assert app+".main" in per_list
|
||||
assert app + ".main" in per_list
|
||||
|
||||
#
|
||||
# Some edge cases #
|
||||
|
@ -577,6 +581,7 @@ def test_restore_archive_with_no_json(mocker):
|
|||
with raiseYunohostError(mocker, 'backup_archive_cant_retrieve_info_json'):
|
||||
backup_restore(name="badbackup", force=True)
|
||||
|
||||
|
||||
@pytest.mark.with_wordpress_archive_from_2p4
|
||||
def test_restore_archive_with_bad_archive(mocker):
|
||||
|
||||
|
@ -605,9 +610,9 @@ def test_restore_archive_with_custom_hook(mocker):
|
|||
# Restore system with custom hook
|
||||
with message(mocker, "restore_complete"):
|
||||
backup_restore(name=backup_list()["archives"][0],
|
||||
system=[],
|
||||
apps=None,
|
||||
force=True)
|
||||
system=[],
|
||||
apps=None,
|
||||
force=True)
|
||||
|
||||
os.system("rm %s/99-yolo" % custom_restore_hook_folder)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from yunohost.utils.error import YunohostError
|
|||
# Get main domain
|
||||
maindomain = ""
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
global maindomain
|
||||
maindomain = _get_maindomain()
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import socket
|
||||
import requests
|
||||
import pytest
|
||||
import os
|
||||
|
@ -6,9 +7,9 @@ from conftest import message, raiseYunohostError, get_test_apps_dir
|
|||
|
||||
from yunohost.app import app_install, app_remove, app_change_url, app_map, _installed_apps
|
||||
from yunohost.user import user_list, user_create, user_delete, \
|
||||
user_group_list, user_group_delete
|
||||
user_group_list, user_group_delete
|
||||
from yunohost.permission import user_permission_update, user_permission_list, user_permission_reset, \
|
||||
permission_create, permission_delete, permission_url
|
||||
permission_create, permission_delete, permission_url
|
||||
from yunohost.domain import _get_maindomain
|
||||
|
||||
# Get main domain
|
||||
|
@ -17,10 +18,10 @@ dummy_password = "test123Ynh"
|
|||
|
||||
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
||||
# Mainly used for 'can_access_webpage' function
|
||||
import socket
|
||||
|
||||
prv_getaddrinfo = socket.getaddrinfo
|
||||
|
||||
|
||||
def clean_user_groups_permission():
|
||||
for u in user_list()['users']:
|
||||
user_delete(u)
|
||||
|
@ -44,6 +45,7 @@ def setup_function(function):
|
|||
# Dirty patch of DNS resolution. Force the DNS to 127.0.0.1 address even if dnsmasq have the public address.
|
||||
# Mainly used for 'can_access_webpage' function
|
||||
dns_cache = {(maindomain, 443, 0, 1): [(2, 1, 6, '', ('127.0.0.1', 443))]}
|
||||
|
||||
def new_getaddrinfo(*args):
|
||||
try:
|
||||
return dns_cache[args]
|
||||
|
@ -55,7 +57,7 @@ def setup_function(function):
|
|||
|
||||
user_create("alice", "Alice", "White", "alice@" + maindomain, dummy_password)
|
||||
user_create("bob", "Bob", "Snow", "bob@" + maindomain, dummy_password)
|
||||
permission_create("wiki.main", url="/", allowed=["all_users"] , sync_perm=False)
|
||||
permission_create("wiki.main", url="/", allowed=["all_users"], sync_perm=False)
|
||||
permission_create("blog.main", allowed=["all_users"], sync_perm=False)
|
||||
user_permission_update("blog.main", remove="all_users", add="alice")
|
||||
|
||||
|
@ -397,6 +399,7 @@ def test_permission_redefine_url():
|
|||
res = user_permission_list(full=True)['permissions']
|
||||
assert res["blog.main"]["url"] == "/pwet"
|
||||
|
||||
|
||||
def test_permission_remove_url():
|
||||
permission_url("blog.main", url=None)
|
||||
|
||||
|
@ -489,9 +492,9 @@ def test_permission_app_propagation_on_ssowat():
|
|||
# alice gotta be allowed on the main permission to access the admin tho
|
||||
user_permission_update("permissions_app.main", remove="bob", add="all_users")
|
||||
|
||||
assert not can_access_webpage(app_webroot+"/admin", logged_as=None)
|
||||
assert can_access_webpage(app_webroot+"/admin", logged_as="alice")
|
||||
assert not can_access_webpage(app_webroot+"/admin", logged_as="bob")
|
||||
assert not can_access_webpage(app_webroot + "/admin", logged_as=None)
|
||||
assert can_access_webpage(app_webroot + "/admin", logged_as="alice")
|
||||
assert not can_access_webpage(app_webroot + "/admin", logged_as="bob")
|
||||
|
||||
|
||||
def test_permission_legacy_app_propagation_on_ssowat():
|
||||
|
|
|
@ -9,6 +9,7 @@ TEST_DOMAIN_NGINX_CONFIG = "/etc/nginx/conf.d/%s.conf" % TEST_DOMAIN
|
|||
TEST_DOMAIN_DNSMASQ_CONFIG = "/etc/dnsmasq.d/%s" % TEST_DOMAIN
|
||||
SSHD_CONFIG = "/etc/ssh/sshd_config"
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
|
||||
_force_clear_hashes([TEST_DOMAIN_NGINX_CONFIG])
|
||||
|
@ -169,7 +170,7 @@ def test_stale_hashes_if_file_manually_deleted():
|
|||
# ... Anyway, the proper way to write these tests would be to use a dummy
|
||||
# regen-conf hook just for tests but meh I'm lazy
|
||||
#
|
||||
#def test_stale_hashes_if_file_manually_modified():
|
||||
# def test_stale_hashes_if_file_manually_modified():
|
||||
# """
|
||||
# Same as other test, but manually delete the file in between and check
|
||||
# behavior
|
||||
|
|
|
@ -64,11 +64,13 @@ def test_service_add():
|
|||
service_add("dummyservice", description="A dummy service to run tests")
|
||||
assert "dummyservice" in service_status().keys()
|
||||
|
||||
|
||||
def test_service_add_real_service():
|
||||
|
||||
service_add("networking")
|
||||
assert "networking" in service_status().keys()
|
||||
|
||||
|
||||
def test_service_remove():
|
||||
|
||||
service_add("dummyservice", description="A dummy service to run tests")
|
||||
|
|
|
@ -13,6 +13,7 @@ DEFAULTS["example.int"] = {"type": "int", "default": 42}
|
|||
DEFAULTS["example.string"] = {"type": "string", "default": "yolo swag"}
|
||||
DEFAULTS["example.enum"] = {"type": "enum", "default": "a", "choices": ["a", "b", "c"]}
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
os.system("mv /etc/yunohost/settings.json /etc/yunohost/settings.json.saved")
|
||||
|
||||
|
@ -69,6 +70,7 @@ def test_settings_set():
|
|||
settings_set("example.bool", "on")
|
||||
assert settings_get("example.bool") is True
|
||||
|
||||
|
||||
def test_settings_set_int():
|
||||
settings_set("example.int", 21)
|
||||
assert settings_get("example.int") == 21
|
||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
|||
from conftest import message, raiseYunohostError
|
||||
|
||||
from yunohost.user import user_list, user_info, user_create, user_delete, user_update, \
|
||||
user_group_list, user_group_create, user_group_delete, user_group_update
|
||||
user_group_list, user_group_create, user_group_delete, user_group_update
|
||||
from yunohost.domain import _get_maindomain
|
||||
from yunohost.tests.test_permission import check_LDAP_db_integrity
|
||||
|
||||
|
@ -25,7 +25,7 @@ def setup_function(function):
|
|||
|
||||
global maindomain
|
||||
maindomain = _get_maindomain()
|
||||
|
||||
|
||||
user_create("alice", "Alice", "White", "alice@" + maindomain, "test123Ynh")
|
||||
user_create("bob", "Bob", "Snow", "bob@" + maindomain, "test123Ynh")
|
||||
user_create("jack", "Jack", "Black", "jack@" + maindomain, "test123Ynh")
|
||||
|
|
|
@ -33,8 +33,8 @@ class YunohostError(MoulinetteError):
|
|||
"""
|
||||
|
||||
def __init__(self, key, raw_msg=False, *args, **kwargs):
|
||||
self.key = key # Saving the key is useful for unit testing
|
||||
self.kwargs = kwargs # Saving the key is useful for unit testing
|
||||
self.key = key # Saving the key is useful for unit testing
|
||||
self.kwargs = kwargs # Saving the key is useful for unit testing
|
||||
if raw_msg:
|
||||
msg = key
|
||||
else:
|
||||
|
|
|
@ -29,19 +29,20 @@ from yunohost.utils.error import YunohostError
|
|||
# to avoid re-authenticating in case we call _get_ldap_authenticator multiple times
|
||||
_ldap_interface = None
|
||||
|
||||
|
||||
def _get_ldap_interface():
|
||||
|
||||
global _ldap_interface
|
||||
|
||||
if _ldap_interface is None:
|
||||
|
||||
conf = { "vendor": "ldap",
|
||||
"name": "as-root",
|
||||
"parameters": { 'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi',
|
||||
'base_dn': 'dc=yunohost,dc=org',
|
||||
'user_rdn': 'gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth' },
|
||||
"extra": {}
|
||||
}
|
||||
conf = {"vendor": "ldap",
|
||||
"name": "as-root",
|
||||
"parameters": {'uri': 'ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi',
|
||||
'base_dn': 'dc=yunohost,dc=org',
|
||||
'user_rdn': 'gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth'},
|
||||
"extra": {}
|
||||
}
|
||||
|
||||
try:
|
||||
_ldap_interface = ldap.Authenticator(**conf)
|
||||
|
@ -82,4 +83,5 @@ def _destroy_ldap_interface():
|
|||
if _ldap_interface is not None:
|
||||
del _ldap_interface
|
||||
|
||||
|
||||
atexit.register(_destroy_ldap_interface)
|
||||
|
|
|
@ -58,6 +58,7 @@ def get_public_ip_from_remote_server(protocol=4):
|
|||
|
||||
# If we are indeed connected in ipv4 or ipv6, we should find a default route
|
||||
routes = check_output("ip -%s route show table all" % protocol).split("\n")
|
||||
|
||||
def is_default_route(r):
|
||||
# Typically the default route starts with "default"
|
||||
# But of course IPv6 is more complex ... e.g. on internet cube there's
|
||||
|
|
|
@ -10,6 +10,7 @@ from yunohost.utils.error import YunohostError
|
|||
|
||||
logger = logging.getLogger('yunohost.utils.yunopaste')
|
||||
|
||||
|
||||
def yunopaste(data):
|
||||
|
||||
paste_server = "https://paste.yunohost.org"
|
||||
|
@ -44,7 +45,6 @@ def anonymize(data):
|
|||
data = data.replace(domain.replace(".", "%2e"), redact.replace(".", "%2e"))
|
||||
return data
|
||||
|
||||
|
||||
# First, let's replace every occurence of the main domain by "domain.tld"
|
||||
# This should cover a good fraction of the info leaked
|
||||
main_domain = _get_maindomain()
|
||||
|
|
|
@ -13,6 +13,6 @@ for locale_file in locale_files:
|
|||
|
||||
print(locale_file)
|
||||
this_locale = json.loads(open(locale_folder + locale_file).read(), object_pairs_hook=OrderedDict)
|
||||
this_locale_fixed = {k:v for k, v in this_locale.items() if k in reference}
|
||||
this_locale_fixed = {k: v for k, v in this_locale.items() if k in reference}
|
||||
|
||||
json.dump(this_locale_fixed, open(locale_folder + locale_file, "w"), indent=4, ensure_ascii=False)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import yaml
|
||||
|
||||
|
||||
def test_yaml_syntax():
|
||||
yaml.load(open("data/actionsmap/yunohost.yml"))
|
||||
|
|
Loading…
Add table
Reference in a new issue