mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Refactor tests
This commit is contained in:
parent
5e3dadbfe3
commit
bb2d868fa9
2 changed files with 58 additions and 52 deletions
|
|
@ -3,6 +3,7 @@ import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import pathlib
|
||||||
|
|
||||||
distro = sys.argv[1]
|
distro = sys.argv[1]
|
||||||
if distro == "ubuntu":
|
if distro == "ubuntu":
|
||||||
|
|
@ -327,10 +328,10 @@ if distro == "ubuntu":
|
||||||
# Checking Removing test
|
# Checking Removing test
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
os.path.exists("/usr/share/bunkerweb")
|
pathlib.Path("/usr/share/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/tmp/bunkerweb")
|
or pathlib.Path("/var/tmp/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/cache/bunkerweb")
|
or pathlib.Path("/var/cache/bunkerweb").is_dir()
|
||||||
or os.path.exists("/usr/bin/bwcli")
|
or pathlib.Path("/usr/bin/bwcli").is_file()
|
||||||
):
|
):
|
||||||
test_results["Removing test"] = "KO"
|
test_results["Removing test"] = "KO"
|
||||||
else:
|
else:
|
||||||
|
|
@ -387,7 +388,10 @@ if distro == "ubuntu":
|
||||||
print("❌ /etc/bunkerweb found.")
|
print("❌ /etc/bunkerweb found.")
|
||||||
# Checking Purging test
|
# Checking Purging test
|
||||||
try:
|
try:
|
||||||
if os.path.isdir("/var/lib/bunkerweb") or os.path.isdir("/etc/bunkerweb"):
|
if (
|
||||||
|
pathlib.Path("/var/lib/bunkerweb").is_dir()
|
||||||
|
or pathlib.Path("/etc/bunkerweb").is_dir()
|
||||||
|
):
|
||||||
test_results["Purging test"] = "KO"
|
test_results["Purging test"] = "KO"
|
||||||
else:
|
else:
|
||||||
test_results["Purging test"] = "OK"
|
test_results["Purging test"] = "OK"
|
||||||
|
|
@ -853,10 +857,10 @@ elif distro == "debian":
|
||||||
# Checking Removing test
|
# Checking Removing test
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
os.path.exists("/usr/share/bunkerweb")
|
pathlib.Path("/usr/share/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/tmp/bunkerweb")
|
or pathlib.Path("/var/tmp/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/cache/bunkerweb")
|
or pathlib.Path("/var/cache/bunkerweb").is_dir()
|
||||||
or os.path.exists("/usr/bin/bwcli")
|
or pathlib.Path("/usr/bin/bwcli").is_file()
|
||||||
):
|
):
|
||||||
test_results["Removing test"] = "KO"
|
test_results["Removing test"] = "KO"
|
||||||
else:
|
else:
|
||||||
|
|
@ -913,7 +917,10 @@ elif distro == "debian":
|
||||||
print("❌ /etc/bunkerweb found.")
|
print("❌ /etc/bunkerweb found.")
|
||||||
# Checking Purging test
|
# Checking Purging test
|
||||||
try:
|
try:
|
||||||
if os.path.isdir("/var/lib/bunkerweb") or os.path.isdir("/etc/bunkerweb"):
|
if (
|
||||||
|
pathlib.Path("/var/lib/bunkerweb").is_dir()
|
||||||
|
or pathlib.Path("/etc/bunkerweb").is_dir()
|
||||||
|
):
|
||||||
test_results["Purging test"] = "KO"
|
test_results["Purging test"] = "KO"
|
||||||
else:
|
else:
|
||||||
test_results["Purging test"] = "OK"
|
test_results["Purging test"] = "OK"
|
||||||
|
|
@ -1418,12 +1425,12 @@ elif distro == "fedora":
|
||||||
# Checking Removing test
|
# Checking Removing test
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
os.path.exists("/usr/share/bunkerweb")
|
pathlib.Path("/usr/share/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/tmp/bunkerweb")
|
or pathlib.Path("/var/tmp/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/cache/bunkerweb")
|
or pathlib.Path("/var/cache/bunkerweb").is_dir()
|
||||||
or os.path.exists("/usr/bin/bwcli")
|
or pathlib.Path("/usr/bin/bwcli").is_file()
|
||||||
or os.path.isdir("/var/lib/bunkerweb")
|
or pathlib.Path("/var/lib/bunkerweb").is_dir()
|
||||||
or os.path.isdir("/etc/bunkerweb")
|
or pathlib.Path("/etc/bunkerweb").is_dir()
|
||||||
):
|
):
|
||||||
test_results["Removing test"] = "KO"
|
test_results["Removing test"] = "KO"
|
||||||
else:
|
else:
|
||||||
|
|
@ -1958,12 +1965,12 @@ elif distro == "rhel":
|
||||||
# Checking Removing test
|
# Checking Removing test
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
os.path.exists("/usr/share/bunkerweb")
|
pathlib.Path("/usr/share/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/tmp/bunkerweb")
|
or pathlib.Path("/var/tmp/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/cache/bunkerweb")
|
or pathlib.Path("/var/cache/bunkerweb").is_dir()
|
||||||
or os.path.exists("/usr/bin/bwcli")
|
or pathlib.Path("/usr/bin/bwcli").is_file()
|
||||||
or os.path.isdir("/var/lib/bunkerweb")
|
or pathlib.Path("/var/lib/bunkerweb").is_dir()
|
||||||
or os.path.isdir("/etc/bunkerweb")
|
or pathlib.Path("/etc/bunkerweb").is_dir()
|
||||||
):
|
):
|
||||||
test_results["Removing test"] = "KO"
|
test_results["Removing test"] = "KO"
|
||||||
else:
|
else:
|
||||||
|
|
@ -2481,12 +2488,12 @@ elif distro == "centos":
|
||||||
# Checking Removing test
|
# Checking Removing test
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
os.path.exists("/usr/share/bunkerweb")
|
pathlib.Path("/usr/share/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/tmp/bunkerweb")
|
or pathlib.Path("/var/tmp/bunkerweb").is_dir()
|
||||||
or os.path.exists("/var/cache/bunkerweb")
|
or pathlib.Path("/var/cache/bunkerweb").is_dir()
|
||||||
or os.path.exists("/usr/bin/bwcli")
|
or pathlib.Path("/usr/bin/bwcli").is_file()
|
||||||
or os.path.isdir("/var/lib/bunkerweb")
|
or pathlib.Path("/var/lib/bunkerweb").is_dir()
|
||||||
or os.path.isdir("/etc/bunkerweb")
|
or pathlib.Path("/etc/bunkerweb").is_dir()
|
||||||
):
|
):
|
||||||
test_results["Removing test"] = "KO"
|
test_results["Removing test"] = "KO"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from os import getcwd, listdir
|
from os import listdir
|
||||||
from os.path import join
|
from os.path import join
|
||||||
|
from pathlib import Path
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
@ -23,9 +24,9 @@ from selenium.common.exceptions import (
|
||||||
try:
|
try:
|
||||||
ready = False
|
ready = False
|
||||||
retries = 0
|
retries = 0
|
||||||
while ready is False:
|
while not ready:
|
||||||
with suppress(RequestException):
|
with suppress(RequestException):
|
||||||
status_code = get("http://www.example.com:8080/admin").status_code
|
status_code = get("http://www.example.com/admin").status_code
|
||||||
|
|
||||||
if status_code > 500:
|
if status_code > 500:
|
||||||
print("An error occurred with the server, exiting ...", flush=True)
|
print("An error occurred with the server, exiting ...", flush=True)
|
||||||
|
|
@ -36,7 +37,7 @@ try:
|
||||||
if retries > 10:
|
if retries > 10:
|
||||||
print("UI took too long to be ready, exiting ...", flush=True)
|
print("UI took too long to be ready, exiting ...", flush=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
elif ready is False:
|
elif not ready:
|
||||||
retries += 1
|
retries += 1
|
||||||
print("Waiting for UI to be ready, retrying in 5s ...", flush=True)
|
print("Waiting for UI to be ready, retrying in 5s ...", flush=True)
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
@ -44,7 +45,7 @@ try:
|
||||||
print("UI is ready, starting tests ...", flush=True)
|
print("UI is ready, starting tests ...", flush=True)
|
||||||
|
|
||||||
firefox_options = Options()
|
firefox_options = Options()
|
||||||
firefox_options.add_argument("--headless")
|
# firefox_options.add_argument("--headless")
|
||||||
|
|
||||||
print("Starting Firefox ...", flush=True)
|
print("Starting Firefox ...", flush=True)
|
||||||
|
|
||||||
|
|
@ -54,11 +55,11 @@ try:
|
||||||
try:
|
try:
|
||||||
return WebDriverWait(driver, 4).until(
|
return WebDriverWait(driver, 4).until(
|
||||||
EC.presence_of_element_located((by, _id))
|
EC.presence_of_element_located((by, _id))
|
||||||
if multiple is False
|
if not multiple
|
||||||
else EC.presence_of_all_elements_located((by, _id))
|
else EC.presence_of_all_elements_located((by, _id))
|
||||||
)
|
)
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
if error is True:
|
if error:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
print(
|
print(
|
||||||
|
|
@ -68,7 +69,7 @@ try:
|
||||||
|
|
||||||
def assert_button_click(driver, button: Union[str, WebElement]):
|
def assert_button_click(driver, button: Union[str, WebElement]):
|
||||||
clicked = False
|
clicked = False
|
||||||
while clicked is False:
|
while not clicked:
|
||||||
with suppress(ElementClickInterceptedException):
|
with suppress(ElementClickInterceptedException):
|
||||||
if isinstance(button, str):
|
if isinstance(button, str):
|
||||||
button = safe_get_element(driver, By.XPATH, button)
|
button = safe_get_element(driver, By.XPATH, button)
|
||||||
|
|
@ -97,7 +98,7 @@ try:
|
||||||
)
|
)
|
||||||
break
|
break
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
if error is True:
|
if error:
|
||||||
print("Messages list not found, exiting ...", flush=True)
|
print("Messages list not found, exiting ...", flush=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
error = True
|
error = True
|
||||||
|
|
@ -109,7 +110,7 @@ try:
|
||||||
is_in = True
|
is_in = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if is_in is False:
|
if not is_in:
|
||||||
print(
|
print(
|
||||||
f'Message "{message}" not found in one of the messages in the list, exiting ...',
|
f'Message "{message}" not found in one of the messages in the list, exiting ...',
|
||||||
flush=True,
|
flush=True,
|
||||||
|
|
@ -147,7 +148,7 @@ try:
|
||||||
print(f"{name.title()} page didn't load in time, exiting ...", flush=True)
|
print(f"{name.title()} page didn't load in time, exiting ...", flush=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if message is True:
|
if message:
|
||||||
print(
|
print(
|
||||||
f"{name.title()} page loaded successfully",
|
f"{name.title()} page loaded successfully",
|
||||||
flush=True,
|
flush=True,
|
||||||
|
|
@ -155,7 +156,7 @@ try:
|
||||||
|
|
||||||
with webdriver.Firefox(
|
with webdriver.Firefox(
|
||||||
service=Service("./geckodriver")
|
service=Service("./geckodriver")
|
||||||
if "geckodriver" in listdir(getcwd())
|
if "geckodriver" in listdir(Path.cwd())
|
||||||
else None,
|
else None,
|
||||||
options=firefox_options,
|
options=firefox_options,
|
||||||
) as driver:
|
) as driver:
|
||||||
|
|
@ -163,9 +164,9 @@ try:
|
||||||
driver.maximize_window()
|
driver.maximize_window()
|
||||||
driver_wait = WebDriverWait(driver, 15)
|
driver_wait = WebDriverWait(driver, 15)
|
||||||
|
|
||||||
print("Navigating to http://www.example.com:8080/admin ...", flush=True)
|
print("Navigating to http://www.example.com/admin ...", flush=True)
|
||||||
|
|
||||||
driver.get("http://www.example.com:8080/admin")
|
driver.get("http://www.example.com/admin")
|
||||||
|
|
||||||
### LOGIN PAGE
|
### LOGIN PAGE
|
||||||
|
|
||||||
|
|
@ -182,7 +183,7 @@ try:
|
||||||
flush=True,
|
flush=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
driver.get("http://www.example.com:8080/admin/home")
|
driver.get("http://www.example.com/admin/home")
|
||||||
|
|
||||||
print("Waiting for toast ...", flush=True)
|
print("Waiting for toast ...", flush=True)
|
||||||
|
|
||||||
|
|
@ -663,9 +664,9 @@ try:
|
||||||
|
|
||||||
ready = False
|
ready = False
|
||||||
retries = 0
|
retries = 0
|
||||||
while ready is False:
|
while not ready:
|
||||||
with suppress(RequestException):
|
with suppress(RequestException):
|
||||||
status_code = get("http://app1.example.com:8080/").status_code
|
status_code = get("http://app1.example.com/").status_code
|
||||||
|
|
||||||
if status_code > 500:
|
if status_code > 500:
|
||||||
print("The service is not working, exiting ...", flush=True)
|
print("The service is not working, exiting ...", flush=True)
|
||||||
|
|
@ -676,7 +677,7 @@ try:
|
||||||
if retries > 10:
|
if retries > 10:
|
||||||
print("The service took too long to be ready, exiting ...", flush=True)
|
print("The service took too long to be ready, exiting ...", flush=True)
|
||||||
exit(1)
|
exit(1)
|
||||||
elif ready is False:
|
elif not ready:
|
||||||
retries += 1
|
retries += 1
|
||||||
print(
|
print(
|
||||||
"Waiting for the service to be ready, retrying in 5s ...",
|
"Waiting for the service to be ready, retrying in 5s ...",
|
||||||
|
|
@ -783,9 +784,7 @@ try:
|
||||||
|
|
||||||
sleep(5)
|
sleep(5)
|
||||||
|
|
||||||
driver.execute_script(
|
driver.execute_script(f"window.open('http://www.example.com/hello','_blank');")
|
||||||
f"window.open('http://www.example.com:8080/hello','_blank');"
|
|
||||||
)
|
|
||||||
driver.switch_to.window(driver.window_handles[1])
|
driver.switch_to.window(driver.window_handles[1])
|
||||||
driver.switch_to.default_content()
|
driver.switch_to.default_content()
|
||||||
|
|
||||||
|
|
@ -866,7 +865,7 @@ try:
|
||||||
|
|
||||||
safe_get_element(
|
safe_get_element(
|
||||||
driver, By.XPATH, "//input[@type='file' and @name='file']"
|
driver, By.XPATH, "//input[@type='file' and @name='file']"
|
||||||
).send_keys(join(getcwd(), "test.zip"))
|
).send_keys(join(Path.cwd(), "test.zip"))
|
||||||
|
|
||||||
access_page(
|
access_page(
|
||||||
driver,
|
driver,
|
||||||
|
|
@ -885,7 +884,7 @@ try:
|
||||||
|
|
||||||
safe_get_element(
|
safe_get_element(
|
||||||
driver, By.XPATH, "//input[@type='file' and @name='file']"
|
driver, By.XPATH, "//input[@type='file' and @name='file']"
|
||||||
).send_keys(join(getcwd(), "discord.zip"))
|
).send_keys(join(Path.cwd(), "discord.zip"))
|
||||||
|
|
||||||
access_page(
|
access_page(
|
||||||
driver,
|
driver,
|
||||||
|
|
@ -1239,7 +1238,7 @@ try:
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
|
|
||||||
resp = get(
|
resp = get(
|
||||||
"http://www.example.com:8080/admin/jobs/download?job_name=mmdb-country&file_name=country.mmdb"
|
"http://www.example.com/admin/jobs/download?job_name=mmdb-country&file_name=country.mmdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue