2022-09-24 02:10:01 +00:00
|
|
|
|
import pytest
|
|
|
|
|
import uuid
|
|
|
|
|
|
2022-10-15 02:30:08 +00:00
|
|
|
|
from conftest import STATUS_SUCCESS
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/language", methods=["POST"])
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"locale,confirm_message",
|
|
|
|
|
[
|
|
|
|
|
("de", "Webinterface-Sprache auf Deutsch geändert"),
|
|
|
|
|
("es", "Se ha cambiado el lenguaje de la Interfaz Web a español"),
|
2023-02-09 03:40:33 +00:00
|
|
|
|
("fr", "Langue de l’interface web changée en français"),
|
2022-09-24 02:10:01 +00:00
|
|
|
|
("sv", "Bytte webbgränssnittets språk till svenska"),
|
|
|
|
|
("en", "Changed Web Interface language to English"),
|
2022-12-22 20:15:10 +00:00
|
|
|
|
("zh", "Web 界面语言已更改为 中文"),
|
2022-09-24 02:10:01 +00:00
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_set_language(http_client, locale, confirm_message):
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/language",
|
|
|
|
|
data={
|
|
|
|
|
"locale": locale,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == confirm_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/logs/level", methods=["POST"])
|
2022-10-25 15:51:04 +00:00
|
|
|
|
@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "off"])
|
2022-09-24 02:10:01 +00:00
|
|
|
|
def test_set_log_level(http_client, level):
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/logs/level",
|
|
|
|
|
data={
|
|
|
|
|
"level": level,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == f"Log level set to {level}"
|
|
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
|
http_client.post(
|
|
|
|
|
"/logs/level",
|
|
|
|
|
data={
|
|
|
|
|
"level": "debug",
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/logs/show", methods=["POST"])
|
|
|
|
|
def test_show_logs(http_client):
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/logs/show",
|
|
|
|
|
data={
|
|
|
|
|
"lines": 100,
|
2022-12-05 17:58:23 +00:00
|
|
|
|
"scope": "piscsi",
|
2022-09-24 02:10:01 +00:00
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
2022-09-27 00:44:41 +00:00
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
2022-09-24 02:10:01 +00:00
|
|
|
|
assert response.status_code == 200
|
2022-09-27 00:44:41 +00:00
|
|
|
|
assert response_data["data"]["lines"] == "100"
|
2022-12-05 17:58:23 +00:00
|
|
|
|
assert response_data["data"]["scope"] == "piscsi"
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/config/save", methods=["POST"])
|
2023-01-28 22:34:34 +00:00
|
|
|
|
# route("/config/action", methods=["POST"])
|
2022-10-15 02:30:08 +00:00
|
|
|
|
def test_save_load_and_delete_configs(env, http_client):
|
2022-09-24 02:10:01 +00:00
|
|
|
|
config_name = str(uuid.uuid4())
|
|
|
|
|
config_json_file = f"{config_name}.json"
|
|
|
|
|
reserved_scsi_id = 0
|
|
|
|
|
reservation_memo = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
# Confirm the initial state
|
|
|
|
|
assert http_client.get("/").json()["data"]["RESERVATIONS"][0] == ""
|
|
|
|
|
|
|
|
|
|
# Save the initial state to a config
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/config/save",
|
|
|
|
|
data={
|
|
|
|
|
"name": config_name,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == (
|
2022-10-15 02:30:08 +00:00
|
|
|
|
f"File created: {env['cfg_dir']}/{config_json_file}"
|
2022-09-24 02:10:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert config_json_file in http_client.get("/").json()["data"]["config_files"]
|
|
|
|
|
|
|
|
|
|
# Modify the state
|
|
|
|
|
http_client.post(
|
|
|
|
|
"/scsi/reserve",
|
|
|
|
|
data={
|
|
|
|
|
"scsi_id": reserved_scsi_id,
|
|
|
|
|
"memo": reservation_memo,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert http_client.get("/").json()["data"]["RESERVATIONS"][0] == reservation_memo
|
|
|
|
|
|
|
|
|
|
# Load the saved config
|
|
|
|
|
response = http_client.post(
|
2023-01-28 22:34:34 +00:00
|
|
|
|
"/config/action",
|
2022-09-24 02:10:01 +00:00
|
|
|
|
data={
|
|
|
|
|
"name": config_json_file,
|
|
|
|
|
"load": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == (
|
2022-10-14 16:12:57 +00:00
|
|
|
|
f"Loaded configurations from: {config_json_file}"
|
2022-09-24 02:10:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Confirm the application has returned to its initial state
|
|
|
|
|
assert http_client.get("/").json()["data"]["RESERVATIONS"][0] == ""
|
|
|
|
|
|
|
|
|
|
# Delete the saved config
|
|
|
|
|
response = http_client.post(
|
2023-01-28 22:34:34 +00:00
|
|
|
|
"/config/action",
|
2022-09-24 02:10:01 +00:00
|
|
|
|
data={
|
|
|
|
|
"name": config_json_file,
|
|
|
|
|
"delete": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == (
|
2022-10-15 02:30:08 +00:00
|
|
|
|
f"File deleted: {env['cfg_dir']}/{config_json_file}"
|
2022-09-24 02:10:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert config_json_file not in http_client.get("/").json()["data"]["config_files"]
|
2022-11-14 17:32:15 +00:00
|
|
|
|
|
|
|
|
|
|
2023-01-28 22:34:34 +00:00
|
|
|
|
# route("/config/save", methods=["POST"])
|
|
|
|
|
# route("/config/action", methods=["POST"])
|
|
|
|
|
def test_download_configs(env, http_client, delete_file):
|
|
|
|
|
config_name = str(uuid.uuid4())
|
|
|
|
|
config_json_file = f"{config_name}.json"
|
|
|
|
|
|
|
|
|
|
# Save the initial state to a config
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/config/save",
|
|
|
|
|
data={
|
|
|
|
|
"name": config_name,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert config_json_file in http_client.get("/").json()["data"]["config_files"]
|
|
|
|
|
|
|
|
|
|
# Download the saved config
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/config/action",
|
|
|
|
|
data={
|
|
|
|
|
"name": config_json_file,
|
|
|
|
|
"send": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response.headers["content-type"] == "application/json"
|
|
|
|
|
assert response.headers["content-disposition"] == f"attachment; filename={config_json_file}"
|
|
|
|
|
|
|
|
|
|
# Delete the saved config
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/config/action",
|
|
|
|
|
data={
|
|
|
|
|
"name": config_json_file,
|
|
|
|
|
"delete": True,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert config_json_file not in http_client.get("/").json()["data"]["config_files"]
|
|
|
|
|
|
|
|
|
|
|
2022-11-14 17:32:15 +00:00
|
|
|
|
# route("/theme", methods=["POST"])
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"theme",
|
|
|
|
|
[
|
|
|
|
|
"modern",
|
|
|
|
|
"classic",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_set_theme(http_client, theme):
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/theme",
|
|
|
|
|
data={
|
2022-11-18 00:21:18 +00:00
|
|
|
|
"name": theme,
|
2022-11-14 17:32:15 +00:00
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == f"Theme changed to '{theme}'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/theme", methods=["GET"])
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"theme",
|
|
|
|
|
[
|
|
|
|
|
"modern",
|
|
|
|
|
"classic",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_set_theme_via_query_string(http_client, theme):
|
|
|
|
|
response = http_client.get(
|
|
|
|
|
"/theme",
|
|
|
|
|
params={
|
2022-11-18 00:21:18 +00:00
|
|
|
|
"name": theme,
|
2022-11-14 17:32:15 +00:00
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == f"Theme changed to '{theme}'."
|
2022-11-20 18:20:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# route("/sys/rename", methods=["POST"])
|
|
|
|
|
def test_rename_system(env, http_client):
|
|
|
|
|
new_name = "SYSTEM NAME TEST"
|
|
|
|
|
|
|
|
|
|
response = http_client.get("/env")
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
old_name = response_data["data"]["system_name"]
|
|
|
|
|
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/sys/rename",
|
|
|
|
|
data={
|
|
|
|
|
"system_name": new_name,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == f"System name changed to '{new_name}'."
|
|
|
|
|
|
|
|
|
|
response = http_client.get("/env")
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response_data["data"]["system_name"] == new_name
|
|
|
|
|
|
|
|
|
|
response = http_client.post(
|
|
|
|
|
"/sys/rename",
|
|
|
|
|
data={
|
|
|
|
|
"system_name": old_name,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
|
assert response_data["messages"][0]["message"] == f"System name changed to '{old_name}'."
|
|
|
|
|
|
|
|
|
|
response = http_client.get("/env")
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
|
|
assert response_data["data"]["system_name"] == old_name
|