mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-17 19:30:44 +00:00
Improve Web UI integration tests (#939)
* Remove deprecated critital log level from test * Move drive_properties back into template data sets * Move properties data integrity checks to test code * Streamline the drive formatting logic
This commit is contained in:
parent
6bbaa956ed
commit
4b109a70b0
@ -13,7 +13,7 @@
|
|||||||
<th scope="col">{{ _("Description") }}</th>
|
<th scope="col">{{ _("Description") }}</th>
|
||||||
<th scope="col">{{ _("Action") }}</th>
|
<th scope="col">{{ _("Action") }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for hd in env['drive_properties']['hd_conf']|sort(attribute='name') %}
|
{% for hd in drive_properties['hd_conf']|sort(attribute='name') %}
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
{% if hd.url != "" %}
|
{% if hd.url != "" %}
|
||||||
@ -48,7 +48,7 @@
|
|||||||
<th scope="col">{{ _("Description") }}</th>
|
<th scope="col">{{ _("Description") }}</th>
|
||||||
<th scope="col">{{ _("Action") }}</th>
|
<th scope="col">{{ _("Action") }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for cd in env['drive_properties']['cd_conf']|sort(attribute='name') %}
|
{% for cd in drive_properties['cd_conf']|sort(attribute='name') %}
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
{% if cd.url != "" %}
|
{% if cd.url != "" %}
|
||||||
@ -88,7 +88,7 @@
|
|||||||
<th scope="col">{{ _("Description") }}</th>
|
<th scope="col">{{ _("Description") }}</th>
|
||||||
<th scope="col">{{ _("Action") }}</th>
|
<th scope="col">{{ _("Action") }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for rm in env['drive_properties']['rm_conf']|sort(attribute='name') %}
|
{% for rm in drive_properties['rm_conf']|sort(attribute='name') %}
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center">
|
<td align="center">
|
||||||
{% if rm.url != "" %}
|
{% if rm.url != "" %}
|
||||||
|
@ -392,21 +392,21 @@
|
|||||||
{{ _("None") }}
|
{{ _("None") }}
|
||||||
</option>
|
</option>
|
||||||
{% if type == "SCCD" %}
|
{% if type == "SCCD" %}
|
||||||
{% for drive in env["drive_properties"]["cd_conf"] | sort(attribute='name') %}
|
{% for drive in drive_properties["cd_conf"] | sort(attribute='name') %}
|
||||||
<option value="{{ drive.name }}">
|
<option value="{{ drive.name }}">
|
||||||
{{ drive.name }}
|
{{ drive.name }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if type == "SCRM" %}
|
{% if type == "SCRM" %}
|
||||||
{% for drive in env["drive_properties"]["rm_conf"] | sort(attribute='name') %}
|
{% for drive in drive_properties["rm_conf"] | sort(attribute='name') %}
|
||||||
<option value="{{ drive.name }}">
|
<option value="{{ drive.name }}">
|
||||||
{{ drive.name }}
|
{{ drive.name }}
|
||||||
</option>
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if type == "SCMO" %}
|
{% if type == "SCMO" %}
|
||||||
{% for drive in env["drive_properties"]["mo_conf"] | sort(attribute='name') %}
|
{% for drive in drive_properties["mo_conf"] | sort(attribute='name') %}
|
||||||
<option value="{{ drive.name }}">
|
<option value="{{ drive.name }}">
|
||||||
{{ drive.name }}
|
{{ drive.name }}
|
||||||
</option>
|
</option>
|
||||||
@ -581,7 +581,7 @@
|
|||||||
<option value="">
|
<option value="">
|
||||||
{{ _("None") }}
|
{{ _("None") }}
|
||||||
</option>
|
</option>
|
||||||
{% for drive in env["drive_properties"]["hd_conf"] | sort(attribute='name') %}
|
{% for drive in drive_properties["hd_conf"] | sort(attribute='name') %}
|
||||||
<option value="{{ drive.name }}">
|
<option value="{{ drive.name }}">
|
||||||
{{ drive.name }}
|
{{ drive.name }}
|
||||||
</option>
|
</option>
|
||||||
|
@ -98,7 +98,6 @@ def get_env_info():
|
|||||||
"cd_suffixes": tuple(server_info["sccd"]),
|
"cd_suffixes": tuple(server_info["sccd"]),
|
||||||
"rm_suffixes": tuple(server_info["scrm"]),
|
"rm_suffixes": tuple(server_info["scrm"]),
|
||||||
"mo_suffixes": tuple(server_info["scmo"]),
|
"mo_suffixes": tuple(server_info["scmo"]),
|
||||||
"drive_properties": format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -249,6 +248,7 @@ def index():
|
|||||||
image_suffixes_to_create=image_suffixes_to_create,
|
image_suffixes_to_create=image_suffixes_to_create,
|
||||||
valid_image_suffixes=valid_image_suffixes,
|
valid_image_suffixes=valid_image_suffixes,
|
||||||
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
|
max_file_size=int(int(MAX_FILE_SIZE) / 1024 / 1024),
|
||||||
|
drive_properties=format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]),
|
||||||
RESERVATIONS=RESERVATIONS,
|
RESERVATIONS=RESERVATIONS,
|
||||||
CFG_DIR=CFG_DIR,
|
CFG_DIR=CFG_DIR,
|
||||||
AFP_DIR=AFP_DIR,
|
AFP_DIR=AFP_DIR,
|
||||||
@ -278,6 +278,7 @@ def drive_list():
|
|||||||
return response(
|
return response(
|
||||||
template="drives.html",
|
template="drives.html",
|
||||||
files=file_cmd.list_images()["files"],
|
files=file_cmd.list_images()["files"],
|
||||||
|
drive_properties=format_drive_properties(APP.config["RASCSI_DRIVE_PROPERTIES"]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,29 +153,25 @@ def format_drive_properties(drive_properties):
|
|||||||
cd_conf = []
|
cd_conf = []
|
||||||
rm_conf = []
|
rm_conf = []
|
||||||
mo_conf = []
|
mo_conf = []
|
||||||
FORMAT_FILTER = "{:,.2f}"
|
|
||||||
|
|
||||||
for device in drive_properties:
|
for device in drive_properties:
|
||||||
# Add fallback device names, since other code relies on this data for display
|
# Fallback for when the properties data is corrupted, to avoid crashing the web app.
|
||||||
if not device["name"]:
|
# The integration tests will catch this scenario, but relies on the web app not crashing.
|
||||||
if device["product"]:
|
if not device.get("name"):
|
||||||
device["name"] = device["product"]
|
device["name"] = ""
|
||||||
else:
|
|
||||||
device["name"] = "Unknown Device"
|
|
||||||
if device["device_type"] == "SCHD":
|
|
||||||
device["secure_name"] = secure_filename(device["name"])
|
device["secure_name"] = secure_filename(device["name"])
|
||||||
device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024)
|
|
||||||
|
if device.get("size"):
|
||||||
|
device["size_mb"] = f'{device["size"] / 1024 / 1024:,.2f}'
|
||||||
|
|
||||||
|
if device["device_type"] == "SCHD":
|
||||||
hd_conf.append(device)
|
hd_conf.append(device)
|
||||||
elif device["device_type"] == "SCCD":
|
elif device["device_type"] == "SCCD":
|
||||||
device["size_mb"] = _("N/A")
|
|
||||||
cd_conf.append(device)
|
cd_conf.append(device)
|
||||||
elif device["device_type"] == "SCRM":
|
elif device["device_type"] == "SCRM":
|
||||||
device["secure_name"] = secure_filename(device["name"])
|
|
||||||
device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024)
|
|
||||||
rm_conf.append(device)
|
rm_conf.append(device)
|
||||||
elif device["device_type"] == "SCMO":
|
elif device["device_type"] == "SCMO":
|
||||||
device["secure_name"] = secure_filename(device["name"])
|
|
||||||
device["size_mb"] = FORMAT_FILTER.format(device["size"] / 1024 / 1024)
|
|
||||||
mo_conf.append(device)
|
mo_conf.append(device)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -193,21 +189,7 @@ def get_properties_by_drive_name(drives, drive_name):
|
|||||||
drives.sort(key=lambda item: item.get("name"))
|
drives.sort(key=lambda item: item.get("name"))
|
||||||
|
|
||||||
drive_props = None
|
drive_props = None
|
||||||
prev_drive = {"name": ""}
|
|
||||||
for drive in drives:
|
for drive in drives:
|
||||||
# TODO: Make this check into an integration test
|
|
||||||
if "name" not in drive:
|
|
||||||
logging.warning(
|
|
||||||
"Device without a name exists in the drive properties database. This is a bug."
|
|
||||||
)
|
|
||||||
break
|
|
||||||
# TODO: Make this check into an integration test
|
|
||||||
if drive["name"] == prev_drive["name"]:
|
|
||||||
logging.warning(
|
|
||||||
"Device with duplicate name \"%s\" in drive properties database. This is a bug.",
|
|
||||||
drive["name"],
|
|
||||||
)
|
|
||||||
prev_drive = drive
|
|
||||||
if drive["name"] == drive_name:
|
if drive["name"] == drive_name:
|
||||||
drive_props = drive
|
drive_props = drive
|
||||||
|
|
||||||
|
@ -39,6 +39,19 @@ def test_show_named_drive_presets(http_client):
|
|||||||
response = http_client.get("/drive/list")
|
response = http_client.get("/drive/list")
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|
||||||
|
prev_drive = {"name": ""}
|
||||||
|
for drive in (
|
||||||
|
response_data["data"]["drive_properties"]["hd_conf"]
|
||||||
|
+ response_data["data"]["drive_properties"]["cd_conf"]
|
||||||
|
+ response_data["data"]["drive_properties"]["rm_conf"]
|
||||||
|
+ response_data["data"]["drive_properties"]["mo_conf"]
|
||||||
|
):
|
||||||
|
# Test that the named drive has a name
|
||||||
|
assert drive["name"] != ""
|
||||||
|
# Test that "name" is unique for each named drive
|
||||||
|
assert drive["name"] != prev_drive["name"]
|
||||||
|
prev_drive = drive
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response_data["status"] == STATUS_SUCCESS
|
assert response_data["status"] == STATUS_SUCCESS
|
||||||
assert "files" in response_data["data"]
|
assert "files" in response_data["data"]
|
||||||
|
@ -31,7 +31,7 @@ def test_set_language(http_client, locale, confirm_message):
|
|||||||
|
|
||||||
|
|
||||||
# route("/logs/level", methods=["POST"])
|
# route("/logs/level", methods=["POST"])
|
||||||
@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "critical", "off"])
|
@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "off"])
|
||||||
def test_set_log_level(http_client, level):
|
def test_set_log_level(http_client, level):
|
||||||
response = http_client.post(
|
response = http_client.post(
|
||||||
"/logs/level",
|
"/logs/level",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user