mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Improve stability of unit tests
This commit is contained in:
parent
8085b3a2c2
commit
8da5aa055d
2 changed files with 42 additions and 0 deletions
|
@ -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.domain import _get_maindomain, domain_add, domain_remove, domain_list
|
||||||
from yunohost.utils.error import YunohostError
|
from yunohost.utils.error import YunohostError
|
||||||
from yunohost.tests.test_permission import check_LDAP_db_integrity, check_permission_for_apps
|
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):
|
def setup_function(function):
|
||||||
|
@ -60,6 +61,33 @@ def clean():
|
||||||
os.system("systemctl reset-failed nginx") # Reset failed quota for service to avoid running into start-limit rate ?
|
os.system("systemctl reset-failed nginx") # Reset failed quota for service to avoid running into start-limit rate ?
|
||||||
os.system("systemctl start nginx")
|
os.system("systemctl start nginx")
|
||||||
|
|
||||||
|
# Clean permission
|
||||||
|
for permission_name in user_permission_list(short=True)["permissions"]:
|
||||||
|
if "legacy_app" in permission_name or \
|
||||||
|
"full_domain_app" in permission_name or \
|
||||||
|
"break_yo_system" in permission_name:
|
||||||
|
permission_delete(permission_name, force=True)
|
||||||
|
|
||||||
|
# Clean database
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app' \"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app__2'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app__2@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE legacy_app__3'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER legacy_app__3@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain__2'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain__2@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE full_domain__3'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER full_domain__3@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system__2'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system__2@localhost'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP DATABASE break_yo_system__3'\"")
|
||||||
|
os.system("bash -c \"mysql -u root --password=$(cat /etc/yunohost/mysql) 2>/dev/null <<< 'DROP USER break_yo_system__3@localhost'\"")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def check_LDAP_db_integrity_call():
|
def check_LDAP_db_integrity_call():
|
||||||
|
|
|
@ -14,6 +14,20 @@ from yunohost.domain import _get_maindomain
|
||||||
maindomain = _get_maindomain()
|
maindomain = _get_maindomain()
|
||||||
dummy_password = "test123Ynh"
|
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():
|
def clean_user_groups_permission():
|
||||||
for u in user_list()['users']:
|
for u in user_list()['users']:
|
||||||
|
|
Loading…
Add table
Reference in a new issue