mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #863 from YunoHost/fix_unit_test
Fix unit test and improve test stability
This commit is contained in:
commit
1289d32b7d
4 changed files with 45 additions and 31 deletions
|
@ -23,15 +23,18 @@ def is_boolean(value):
|
|||
arg -- The string to check
|
||||
|
||||
Returns:
|
||||
Boolean
|
||||
(is_boolean, boolean_value)
|
||||
|
||||
"""
|
||||
if isinstance(value, bool):
|
||||
return True
|
||||
return True, value
|
||||
elif isinstance(value, basestring):
|
||||
return str(value).lower() in ['true', 'on', 'yes', 'false', 'off', 'no']
|
||||
if str(value).lower() in ['true', 'on', 'yes', 'false', 'off', 'no']:
|
||||
return True, str(value).lower() in ['true', 'on', 'yes']
|
||||
else:
|
||||
return False, None
|
||||
else:
|
||||
return False
|
||||
return False, None
|
||||
|
||||
|
||||
# a settings entry is in the form of:
|
||||
|
@ -114,7 +117,10 @@ def settings_set(key, value):
|
|||
key_type = settings[key]["type"]
|
||||
|
||||
if key_type == "bool":
|
||||
if not is_boolean(value):
|
||||
boolean_value = is_boolean(value)
|
||||
if boolean_value[0]:
|
||||
value = boolean_value[1]
|
||||
else:
|
||||
raise YunohostError('global_settings_bad_type_for_setting', setting=key,
|
||||
received_type=type(value).__name__, expected_type=key_type)
|
||||
elif key_type == "int":
|
||||
|
|
|
@ -13,6 +13,7 @@ from yunohost.app import app_install, app_remove, app_ssowatconf, _is_installed,
|
|||
from yunohost.domain import _get_maindomain, domain_add, domain_remove, domain_list
|
||||
from yunohost.utils.error import YunohostError
|
||||
from yunohost.tests.test_permission import check_LDAP_db_integrity, check_permission_for_apps
|
||||
from yunohost.permission import user_permission_list, permission_delete
|
||||
|
||||
|
||||
def setup_function(function):
|
||||
|
@ -29,37 +30,30 @@ def clean():
|
|||
os.system("mkdir -p /etc/ssowat/")
|
||||
app_ssowatconf()
|
||||
|
||||
# Gotta first remove break yo system
|
||||
# because some remaining stuff might
|
||||
# make the other app_remove crashs ;P
|
||||
if _is_installed("break_yo_system"):
|
||||
app_remove("break_yo_system")
|
||||
test_apps = ["break_yo_system", "legacy_app", "legacy_app__2", "full_domain_app"]
|
||||
|
||||
if _is_installed("legacy_app"):
|
||||
app_remove("legacy_app")
|
||||
for test_app in test_apps:
|
||||
|
||||
if _is_installed("full_domain_app"):
|
||||
app_remove("full_domain_app")
|
||||
if _is_installed(test_app):
|
||||
app_remove(test_app)
|
||||
|
||||
to_remove = []
|
||||
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*legacy*")
|
||||
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*full_domain*")
|
||||
to_remove += glob.glob("/etc/nginx/conf.d/*.d/*break_yo_system*")
|
||||
for filepath in to_remove:
|
||||
os.remove(filepath)
|
||||
for filepath in glob.glob("/etc/nginx/conf.d/*.d/*%s*" % test_app):
|
||||
os.remove(filepath)
|
||||
for folderpath in glob.glob("/etc/yunohost/apps/*%s*" % test_app):
|
||||
shutil.rmtree(folderpath, ignore_errors=True)
|
||||
for folderpath in glob.glob("/var/www/*%s*" % test_app):
|
||||
shutil.rmtree(folderpath, ignore_errors=True)
|
||||
|
||||
to_remove = []
|
||||
to_remove += glob.glob("/etc/yunohost/apps/*legacy_app*")
|
||||
to_remove += glob.glob("/etc/yunohost/apps/*full_domain_app*")
|
||||
to_remove += glob.glob("/etc/yunohost/apps/*break_yo_system*")
|
||||
to_remove += glob.glob("/var/www/*legacy*")
|
||||
to_remove += glob.glob("/var/www/*full_domain*")
|
||||
for folderpath in to_remove:
|
||||
shutil.rmtree(folderpath, ignore_errors=True)
|
||||
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE %s' \"" % test_app)
|
||||
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER %s@localhost'\"" % test_app)
|
||||
|
||||
os.system("systemctl reset-failed nginx") # Reset failed quota for service to avoid running into start-limit rate ?
|
||||
os.system("systemctl start nginx")
|
||||
|
||||
# Clean permissions
|
||||
for permission_name in user_permission_list(short=True)["permissions"]:
|
||||
if any(test_app in permission_name for test_app in test_apps):
|
||||
permission_delete(permission_name, force=True)
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def check_LDAP_db_integrity_call():
|
||||
|
@ -74,7 +68,7 @@ def check_permission_for_apps_call():
|
|||
yield
|
||||
check_permission_for_apps()
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@pytest.fixture(scope="module")
|
||||
def secondary_domain(request):
|
||||
|
||||
if "example.test" not in domain_list()["domains"]:
|
||||
|
|
|
@ -31,8 +31,8 @@ DUMMY_APP_CATALOG = """{
|
|||
"bar": {"id": "bar", "level": 7, "category": "swag", "manifest":{"description": "Bar"}}
|
||||
},
|
||||
"categories": [
|
||||
{"id": "yolo", "description": "YoLo", "title": "Yolo"},
|
||||
{"id": "swag", "description": "sWaG", "title": "Swag"}
|
||||
{"id": "yolo", "description": "YoLo", "title": {"en": "Yolo"}},
|
||||
{"id": "swag", "description": "sWaG", "title": {"en": "Swag"}}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
|
|
@ -14,6 +14,20 @@ from yunohost.domain import _get_maindomain
|
|||
maindomain = _get_maindomain()
|
||||
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
|
||||
dns_cache = {(maindomain, 443, 0, 1): [(2, 1, 6, '', ('127.0.0.1', 443))]}
|
||||
prv_getaddrinfo = socket.getaddrinfo
|
||||
def new_getaddrinfo(*args):
|
||||
try:
|
||||
return dns_cache[args]
|
||||
except KeyError:
|
||||
res = prv_getaddrinfo(*args)
|
||||
dns_cache[args] = res
|
||||
return res
|
||||
socket.getaddrinfo = new_getaddrinfo
|
||||
|
||||
|
||||
def clean_user_groups_permission():
|
||||
for u in user_list()['users']:
|
||||
|
|
Loading…
Add table
Reference in a new issue