mirror of https://github.com/akuker/RASCSI.git
Refactor tests to use global endpoint constants
This commit is contained in:
parent
79693949da
commit
6f65f24a75
|
@ -91,7 +91,7 @@
|
|||
<td class="name" align="center">{{ device.device_name }}</td>
|
||||
<td class="parameters">
|
||||
{% if "No Media" in device.status %}
|
||||
<form action="/scsi/attach_device" method="post">
|
||||
<form action="/scsi/attach" method="post">
|
||||
<input name="scsi_id" type="hidden" value="{{ device.id }}">
|
||||
<input name="unit" type="hidden" value="{{ device.unit }}">
|
||||
<input name="type" type="hidden" value="{{ device.device_type }}">
|
||||
|
@ -227,7 +227,7 @@
|
|||
<div>{{ type }}</div>
|
||||
</td>
|
||||
<td>
|
||||
<form action="/scsi/attach_device" method="post" class="device-attach">
|
||||
<form action="/scsi/attach" method="post" class="device-attach">
|
||||
<input name="type" type="hidden" value="{{ type }}">
|
||||
{% for key, value in device_types[type]["params"] | dictsort %}
|
||||
<label for="param_{{ type }}_{{ key }}">{{ key }}:</label>
|
||||
|
@ -444,7 +444,7 @@
|
|||
<input type="submit" value="{{ _("Extract") }}" title="{{ _("Extract") }}" onclick="processNotify('{{ _("Extracting all files...") }}')">
|
||||
</form>
|
||||
{% else %}
|
||||
<form action="/scsi/attach_device" method="post" class="file-attach">
|
||||
<form action="/scsi/attach" method="post" class="file-attach">
|
||||
<input name="file_name" type="hidden" value="{{ file['name'] }}">
|
||||
<label for="image_list_scsi_id_{{ file["name"] }}">{{ _("ID") }}</label>
|
||||
<select name="scsi_id" id="image_list_scsi_id_{{ file["name"] }}">
|
||||
|
|
|
@ -643,7 +643,7 @@ def log_level():
|
|||
return response(error=True, message=process["msg"])
|
||||
|
||||
|
||||
@APP.route("/scsi/attach_device", methods=["POST"])
|
||||
@APP.route("/scsi/attach", methods=["POST"])
|
||||
@login_required
|
||||
def attach_device():
|
||||
"""
|
||||
|
|
|
@ -8,6 +8,41 @@ FILE_SIZE_1_MIB = 1048576
|
|||
STATUS_SUCCESS = "success"
|
||||
STATUS_ERROR = "error"
|
||||
|
||||
ENV_ENDPOINT = "/env"
|
||||
HEALTHCHECK_ENDPOINT = "/healthcheck"
|
||||
PWA_FAVICON_ENDPOINT = "/pwa/favicon.ico"
|
||||
LOGIN_ENDPOINT = "/login"
|
||||
LOGOUT_ENDPOINT = "/logout"
|
||||
ATTACH_ENDPOINT = "/scsi/attach"
|
||||
DETACH_ENDPOINT = "/scsi/detach"
|
||||
DETACH_ALL_ENDPOINT = "/scsi/detach_all"
|
||||
EJECT_ENDPOINT = "/scsi/eject"
|
||||
RESERVE_ENDPOINT = "/scsi/reserve"
|
||||
RELEASE_ENDPOINT = "/scsi/release"
|
||||
INFO_ENDPOINT = "/scsi/info"
|
||||
CREATE_ENDPOINT = "/files/create"
|
||||
RENAME_ENDPOINT = "/files/rename"
|
||||
COPY_ENDPOINT = "/files/copy"
|
||||
DELETE_ENDPOINT = "/files/delete"
|
||||
DOWNLOAD_URL_ENDPOINT = "/files/download_url"
|
||||
DOWNLOAD_IMAGE_ENDPOINT = "/files/download_image"
|
||||
DOWNLOAD_CONFIG_ENDPOINT = "/files/download_config"
|
||||
EXTRACT_IMAGE_ENDPOINT = "/files/extract_image"
|
||||
UPLOAD_ENDPOINT = "/files/upload"
|
||||
CREATE_ISO_ENDPOINT = "/files/create_iso"
|
||||
DISKINFO_ENDPOINT = "/files/diskinfo"
|
||||
DRIVE_LIST_ENDPOINT = "/drive/list"
|
||||
DRIVE_CREATE_ENDPOINT = "/drive/create"
|
||||
DRIVE_CDROM_ENDPOINT = "/drive/cdrom"
|
||||
MANPAGE_ENDPOINT = "/sys/manpage?app=piscsi"
|
||||
LANGUAGE_ENDPOINT = "/language"
|
||||
LOG_LEVEL_ENDPOINT = "/logs/level"
|
||||
LOG_SHOW_ENDPOINT = "/logs/show"
|
||||
CONFIG_SAVE_ENDPOINT = "/config/save"
|
||||
CONFIG_ACTION_ENDPOINT = "/config/action"
|
||||
THEME_ENDPOINT = "/theme"
|
||||
SYS_RENAME_ENDPOINT = "/sys/rename"
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def create_test_image(request, http_client):
|
||||
|
@ -18,7 +53,7 @@ def create_test_image(request, http_client):
|
|||
file_name = f"{file_prefix}.{image_type}"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": image_type,
|
||||
|
@ -42,7 +77,7 @@ def create_test_image(request, http_client):
|
|||
|
||||
def delete():
|
||||
for image in images:
|
||||
response = http_client.post("/files/delete", data={"file_name": image["file_name"]})
|
||||
response = http_client.post(DELETE_ENDPOINT, data={"file_name": image["file_name"]})
|
||||
if response.status_code != 200 or response.json()["status"] != STATUS_SUCCESS:
|
||||
warnings.warn(
|
||||
f"Failed to auto-delete file created with create_test_image fixture: {image}"
|
||||
|
@ -71,7 +106,7 @@ def list_attached_images(http_client):
|
|||
@pytest.fixture(scope="function")
|
||||
def delete_file(http_client):
|
||||
def delete(file_name):
|
||||
response = http_client.post("/files/delete", data={"file_name": file_name})
|
||||
response = http_client.post(DELETE_ENDPOINT, data={"file_name": file_name})
|
||||
if response.status_code != 200 or response.json()["status"] != STATUS_SUCCESS:
|
||||
warnings.warn(f"Failed to delete file via delete_file fixture: {file_name}")
|
||||
|
||||
|
@ -81,7 +116,7 @@ def delete_file(http_client):
|
|||
@pytest.fixture(scope="function")
|
||||
def detach_devices(http_client):
|
||||
def detach():
|
||||
response = http_client.post("/scsi/detach_all")
|
||||
response = http_client.post(DETACH_ALL_ENDPOINT)
|
||||
if response.json()["status"] == STATUS_SUCCESS:
|
||||
return True
|
||||
raise Exception("Failed to detach SCSI devices")
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
from conftest import STATUS_SUCCESS, STATUS_ERROR
|
||||
from conftest import STATUS_SUCCESS, STATUS_ERROR, LOGIN_ENDPOINT, LOGOUT_ENDPOINT
|
||||
|
||||
|
||||
# route("/login", methods=["POST"])
|
||||
def test_login_with_valid_credentials(pytestconfig, http_client_unauthenticated):
|
||||
# Note: This test depends on the piscsi group existing and 'username' a member the group
|
||||
response = http_client_unauthenticated.post(
|
||||
"/login",
|
||||
LOGIN_ENDPOINT,
|
||||
data={
|
||||
"username": pytestconfig.getoption("piscsi_username"),
|
||||
"password": pytestconfig.getoption("piscsi_password"),
|
||||
|
@ -19,10 +18,9 @@ def test_login_with_valid_credentials(pytestconfig, http_client_unauthenticated)
|
|||
assert "env" in response_data["data"]
|
||||
|
||||
|
||||
# route("/login", methods=["POST"])
|
||||
def test_login_with_invalid_credentials(http_client_unauthenticated):
|
||||
response = http_client_unauthenticated.post(
|
||||
"/login",
|
||||
LOGIN_ENDPOINT,
|
||||
data={
|
||||
"username": "__INVALID_USER__",
|
||||
"password": "__INVALID_PASS__",
|
||||
|
@ -38,7 +36,6 @@ def test_login_with_invalid_credentials(http_client_unauthenticated):
|
|||
)
|
||||
|
||||
|
||||
# route("/logout")
|
||||
def test_logout(http_client):
|
||||
response = http_client.get("/logout")
|
||||
response = http_client.get(LOGOUT_ENDPOINT)
|
||||
assert response.status_code == 200
|
||||
|
|
|
@ -3,15 +3,21 @@ import pytest
|
|||
from conftest import (
|
||||
SCSI_ID,
|
||||
STATUS_SUCCESS,
|
||||
ATTACH_ENDPOINT,
|
||||
DETACH_ENDPOINT,
|
||||
DETACH_ALL_ENDPOINT,
|
||||
EJECT_ENDPOINT,
|
||||
RESERVE_ENDPOINT,
|
||||
RELEASE_ENDPOINT,
|
||||
INFO_ENDPOINT,
|
||||
)
|
||||
|
||||
|
||||
# route("/scsi/attach_device", methods=["POST"])
|
||||
def test_attach_device_with_image(http_client, create_test_image, detach_devices):
|
||||
test_image = create_test_image()
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
"scsi_id": SCSI_ID,
|
||||
|
@ -31,7 +37,6 @@ def test_attach_device_with_image(http_client, create_test_image, detach_devices
|
|||
detach_devices()
|
||||
|
||||
|
||||
# route("/scsi/attach_device", methods=["POST"])
|
||||
@pytest.mark.parametrize(
|
||||
"device_name,device_config",
|
||||
[
|
||||
|
@ -87,7 +92,7 @@ def test_attach_device(env, http_client, detach_devices, device_name, device_con
|
|||
device_config["unit"] = 0
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data=device_config,
|
||||
)
|
||||
|
||||
|
@ -103,12 +108,11 @@ def test_attach_device(env, http_client, detach_devices, device_name, device_con
|
|||
detach_devices()
|
||||
|
||||
|
||||
# route("/scsi/detach", methods=["POST"])
|
||||
def test_detach_device(http_client, create_test_image):
|
||||
test_image = create_test_image()
|
||||
|
||||
http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
"scsi_id": SCSI_ID,
|
||||
|
@ -118,7 +122,7 @@ def test_detach_device(http_client, create_test_image):
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/detach",
|
||||
DETACH_ENDPOINT,
|
||||
data={
|
||||
"scsi_id": SCSI_ID,
|
||||
"unit": 0,
|
||||
|
@ -132,7 +136,6 @@ def test_detach_device(http_client, create_test_image):
|
|||
assert response_data["messages"][0]["message"] == f"Detached SCSI ID {SCSI_ID} LUN 0"
|
||||
|
||||
|
||||
# route("/scsi/detach_all", methods=["POST"])
|
||||
def test_detach_all_devices(http_client, create_test_image, list_attached_images):
|
||||
test_images = []
|
||||
scsi_ids = [4, 5, 6]
|
||||
|
@ -142,7 +145,7 @@ def test_detach_all_devices(http_client, create_test_image, list_attached_images
|
|||
test_images.append(test_image)
|
||||
|
||||
http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
"scsi_id": scsi_id,
|
||||
|
@ -153,7 +156,7 @@ def test_detach_all_devices(http_client, create_test_image, list_attached_images
|
|||
|
||||
assert list_attached_images() == test_images
|
||||
|
||||
response = http_client.post("/scsi/detach_all")
|
||||
response = http_client.post(DETACH_ALL_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
assert response.status_code == 200
|
||||
|
@ -161,12 +164,11 @@ def test_detach_all_devices(http_client, create_test_image, list_attached_images
|
|||
assert list_attached_images() == []
|
||||
|
||||
|
||||
# route("/scsi/eject", methods=["POST"])
|
||||
def test_eject_device(http_client, create_test_image, detach_devices):
|
||||
test_image = create_test_image()
|
||||
|
||||
http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
"scsi_id": SCSI_ID,
|
||||
|
@ -176,7 +178,7 @@ def test_eject_device(http_client, create_test_image, detach_devices):
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/eject",
|
||||
EJECT_ENDPOINT,
|
||||
data={
|
||||
"scsi_id": SCSI_ID,
|
||||
"unit": 0,
|
||||
|
@ -193,12 +195,11 @@ def test_eject_device(http_client, create_test_image, detach_devices):
|
|||
detach_devices()
|
||||
|
||||
|
||||
# route("/scsi/info", methods=["POST"])
|
||||
def test_show_device_info(http_client, create_test_image, detach_devices):
|
||||
test_image = create_test_image()
|
||||
|
||||
http_client.post(
|
||||
"/scsi/attach_device",
|
||||
ATTACH_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
"scsi_id": SCSI_ID,
|
||||
|
@ -208,7 +209,7 @@ def test_show_device_info(http_client, create_test_image, detach_devices):
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/info",
|
||||
INFO_ENDPOINT,
|
||||
)
|
||||
|
||||
response_data = response.json()
|
||||
|
@ -222,13 +223,11 @@ def test_show_device_info(http_client, create_test_image, detach_devices):
|
|||
detach_devices()
|
||||
|
||||
|
||||
# route("/scsi/reserve", methods=["POST"])
|
||||
# route("/scsi/release", methods=["POST"])
|
||||
def test_reserve_and_release_device(http_client):
|
||||
scsi_id = 0
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/reserve",
|
||||
RESERVE_ENDPOINT,
|
||||
data={
|
||||
"scsi_id": scsi_id,
|
||||
"memo": "TEST",
|
||||
|
@ -242,7 +241,7 @@ def test_reserve_and_release_device(http_client):
|
|||
assert response_data["messages"][0]["message"] == f"Reserved SCSI ID {scsi_id}"
|
||||
|
||||
response = http_client.post(
|
||||
"/scsi/release",
|
||||
RELEASE_ENDPOINT,
|
||||
data={
|
||||
"scsi_id": scsi_id,
|
||||
},
|
||||
|
|
|
@ -5,16 +5,26 @@ import os
|
|||
from conftest import (
|
||||
FILE_SIZE_1_MIB,
|
||||
STATUS_SUCCESS,
|
||||
CREATE_ENDPOINT,
|
||||
RENAME_ENDPOINT,
|
||||
COPY_ENDPOINT,
|
||||
DELETE_ENDPOINT,
|
||||
DOWNLOAD_URL_ENDPOINT,
|
||||
DOWNLOAD_IMAGE_ENDPOINT,
|
||||
DOWNLOAD_CONFIG_ENDPOINT,
|
||||
EXTRACT_IMAGE_ENDPOINT,
|
||||
UPLOAD_ENDPOINT,
|
||||
CREATE_ISO_ENDPOINT,
|
||||
DISKINFO_ENDPOINT,
|
||||
)
|
||||
|
||||
|
||||
# route("/files/create", methods=["POST"])
|
||||
def test_create_file(http_client, list_files, delete_file):
|
||||
file_prefix = str(uuid.uuid4())
|
||||
file_name = f"{file_prefix}.hds"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": "hds",
|
||||
|
@ -34,13 +44,12 @@ def test_create_file(http_client, list_files, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/create", methods=["POST"])
|
||||
def test_create_file_with_properties(http_client, list_files, delete_file):
|
||||
file_prefix = str(uuid.uuid4())
|
||||
file_name = f"{file_prefix}.hds"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": "hds",
|
||||
|
@ -64,13 +73,12 @@ def test_create_file_with_properties(http_client, list_files, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/create", methods=["POST"])
|
||||
def test_create_file_and_format_hfs(http_client, list_files, delete_file):
|
||||
file_prefix = str(uuid.uuid4())
|
||||
file_name = f"{file_prefix}.hda"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": "hda",
|
||||
|
@ -91,7 +99,6 @@ def test_create_file_and_format_hfs(http_client, list_files, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/create", methods=["POST"])
|
||||
def test_create_file_and_format_fat(env, http_client, list_files, delete_file):
|
||||
if env["is_docker"]:
|
||||
pytest.skip("Test not supported in Docker environment.")
|
||||
|
@ -99,7 +106,7 @@ def test_create_file_and_format_fat(env, http_client, list_files, delete_file):
|
|||
file_name = f"{file_prefix}.hdr"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": "hdr",
|
||||
|
@ -120,13 +127,12 @@ def test_create_file_and_format_fat(env, http_client, list_files, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/rename", methods=["POST"])
|
||||
def test_rename_file(http_client, create_test_image, list_files, delete_file):
|
||||
original_file = create_test_image(auto_delete=False)
|
||||
renamed_file = f"{uuid.uuid4()}.rename"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/rename",
|
||||
RENAME_ENDPOINT,
|
||||
data={"file_name": original_file, "new_file_name": renamed_file},
|
||||
)
|
||||
|
||||
|
@ -141,13 +147,12 @@ def test_rename_file(http_client, create_test_image, list_files, delete_file):
|
|||
delete_file(renamed_file)
|
||||
|
||||
|
||||
# route("/files/copy", methods=["POST"])
|
||||
def test_copy_file(http_client, create_test_image, list_files, delete_file):
|
||||
original_file = create_test_image()
|
||||
copy_file = f"{uuid.uuid4()}.copy"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/copy",
|
||||
COPY_ENDPOINT,
|
||||
data={
|
||||
"file_name": original_file,
|
||||
"copy_file_name": copy_file,
|
||||
|
@ -167,11 +172,10 @@ def test_copy_file(http_client, create_test_image, list_files, delete_file):
|
|||
delete_file(copy_file)
|
||||
|
||||
|
||||
# route("/files/delete", methods=["POST"])
|
||||
def test_delete_file(http_client, create_test_image, list_files):
|
||||
file_name = create_test_image(auto_delete=False)
|
||||
|
||||
response = http_client.post("/files/delete", data={"file_name": file_name})
|
||||
response = http_client.post(DELETE_ENDPOINT, data={"file_name": file_name})
|
||||
|
||||
response_data = response.json()
|
||||
|
||||
|
@ -181,7 +185,6 @@ def test_delete_file(http_client, create_test_image, list_files):
|
|||
assert file_name not in list_files()
|
||||
|
||||
|
||||
# route("/files/extract_image", methods=["POST"])
|
||||
@pytest.mark.parametrize(
|
||||
"archive_file_name,image_file_name",
|
||||
[
|
||||
|
@ -205,7 +208,7 @@ def test_extract_file(
|
|||
)
|
||||
|
||||
http_client.post(
|
||||
"/files/download_url",
|
||||
DOWNLOAD_URL_ENDPOINT,
|
||||
data={
|
||||
"destination": "disk_images",
|
||||
"images_subdir": "",
|
||||
|
@ -214,7 +217,7 @@ def test_extract_file(
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/files/extract_image",
|
||||
EXTRACT_IMAGE_ENDPOINT,
|
||||
data={
|
||||
"archive_file": archive_file_name,
|
||||
"archive_members": image_file_name,
|
||||
|
@ -233,7 +236,6 @@ def test_extract_file(
|
|||
delete_file(image_file_name)
|
||||
|
||||
|
||||
# route("/files/upload", methods=["POST"])
|
||||
def test_upload_file(http_client, delete_file):
|
||||
file_name = f"{uuid.uuid4()}.test"
|
||||
|
||||
|
@ -267,7 +269,7 @@ def test_upload_file(http_client, delete_file):
|
|||
file_data = {"file": (file_name, file.read(chunk_size))}
|
||||
|
||||
response = http_client.post(
|
||||
"/files/upload",
|
||||
UPLOAD_ENDPOINT,
|
||||
data=form_data,
|
||||
files=file_data,
|
||||
)
|
||||
|
@ -283,11 +285,10 @@ def test_upload_file(http_client, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/download_image", methods=["POST"])
|
||||
def test_download_image(http_client, create_test_image):
|
||||
file_name = create_test_image()
|
||||
|
||||
response = http_client.post("/files/download_image", data={"file": file_name})
|
||||
response = http_client.post(DOWNLOAD_IMAGE_ENDPOINT, data={"file": file_name})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"] == "application/octet-stream"
|
||||
|
@ -295,13 +296,12 @@ def test_download_image(http_client, create_test_image):
|
|||
assert response.headers["content-length"] == str(FILE_SIZE_1_MIB)
|
||||
|
||||
|
||||
# route("/files/download_config", methods=["POST"])
|
||||
def test_download_properties(http_client, list_files, delete_file):
|
||||
file_prefix = str(uuid.uuid4())
|
||||
file_name = f"{file_prefix}.hds"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create",
|
||||
CREATE_ENDPOINT,
|
||||
data={
|
||||
"file_name": file_prefix,
|
||||
"type": "hds",
|
||||
|
@ -321,7 +321,7 @@ def test_download_properties(http_client, list_files, delete_file):
|
|||
)
|
||||
assert file_name in list_files()
|
||||
|
||||
response = http_client.post("/files/download_config", data={"file": f"{file_name}.properties"})
|
||||
response = http_client.post(DOWNLOAD_CONFIG_ENDPOINT, data={"file": f"{file_name}.properties"})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-type"] == "application/octet-stream"
|
||||
|
@ -331,7 +331,6 @@ def test_download_properties(http_client, list_files, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/download_url", methods=["POST"])
|
||||
def test_download_url_to_dir(env, httpserver, http_client, list_files, delete_file):
|
||||
file_name = str(uuid.uuid4())
|
||||
http_path = f"/images/{file_name}"
|
||||
|
@ -347,7 +346,7 @@ def test_download_url_to_dir(env, httpserver, http_client, list_files, delete_fi
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/files/download_url",
|
||||
DOWNLOAD_URL_ENDPOINT,
|
||||
data={
|
||||
"destination": "disk_images",
|
||||
"images_subdir": subdir,
|
||||
|
@ -369,7 +368,6 @@ def test_download_url_to_dir(env, httpserver, http_client, list_files, delete_fi
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/files/create_iso", methods=["POST"])
|
||||
def test_create_iso_from_url(
|
||||
httpserver,
|
||||
http_client,
|
||||
|
@ -392,7 +390,7 @@ def test_create_iso_from_url(
|
|||
)
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create_iso",
|
||||
CREATE_ISO_ENDPOINT,
|
||||
data={
|
||||
"type": ISO_TYPE,
|
||||
"url": url,
|
||||
|
@ -414,7 +412,6 @@ def test_create_iso_from_url(
|
|||
delete_file(iso_file_name)
|
||||
|
||||
|
||||
# route("/files/create_iso", methods=["POST"])
|
||||
def test_create_iso_from_local_file(
|
||||
http_client,
|
||||
create_test_image,
|
||||
|
@ -427,7 +424,7 @@ def test_create_iso_from_local_file(
|
|||
ISO_TYPE = "HFS"
|
||||
|
||||
response = http_client.post(
|
||||
"/files/create_iso",
|
||||
CREATE_ISO_ENDPOINT,
|
||||
data={
|
||||
"type": ISO_TYPE,
|
||||
"file": test_file_name,
|
||||
|
@ -449,12 +446,11 @@ def test_create_iso_from_local_file(
|
|||
delete_file(iso_file_name)
|
||||
|
||||
|
||||
# route("/files/diskinfo", methods=["POST"])
|
||||
def test_show_diskinfo(http_client, create_test_image):
|
||||
test_image = create_test_image()
|
||||
|
||||
response = http_client.post(
|
||||
"/files/diskinfo",
|
||||
DISKINFO_ENDPOINT,
|
||||
data={
|
||||
"file_name": test_image,
|
||||
},
|
||||
|
|
|
@ -3,10 +3,16 @@ import uuid
|
|||
from conftest import (
|
||||
FILE_SIZE_1_MIB,
|
||||
STATUS_SUCCESS,
|
||||
ENV_ENDPOINT,
|
||||
PWA_FAVICON_ENDPOINT,
|
||||
HEALTHCHECK_ENDPOINT,
|
||||
DRIVE_LIST_ENDPOINT,
|
||||
DRIVE_CREATE_ENDPOINT,
|
||||
DRIVE_CDROM_ENDPOINT,
|
||||
MANPAGE_ENDPOINT,
|
||||
)
|
||||
|
||||
|
||||
# route("/")
|
||||
def test_index(http_client):
|
||||
response = http_client.get("/")
|
||||
response_data = response.json()
|
||||
|
@ -16,9 +22,8 @@ def test_index(http_client):
|
|||
assert "devices" in response_data["data"]
|
||||
|
||||
|
||||
# route("/env")
|
||||
def test_get_env_info(http_client):
|
||||
response = http_client.get("/env")
|
||||
response = http_client.get(ENV_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
assert response.status_code == 200
|
||||
|
@ -26,17 +31,15 @@ def test_get_env_info(http_client):
|
|||
assert "running_env" in response_data["data"]
|
||||
|
||||
|
||||
# route("/pwa/<path:pwa_path>")
|
||||
def test_pwa_route(http_client):
|
||||
response = http_client.get("/pwa/favicon.ico")
|
||||
response = http_client.get(PWA_FAVICON_ENDPOINT)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["content-disposition"] == "inline; filename=favicon.ico"
|
||||
|
||||
|
||||
# route("/drive/list", methods=["GET"])
|
||||
def test_show_named_drive_presets(http_client):
|
||||
response = http_client.get("/drive/list")
|
||||
response = http_client.get(DRIVE_LIST_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
prev_drive = {"name": ""}
|
||||
|
@ -57,12 +60,11 @@ def test_show_named_drive_presets(http_client):
|
|||
assert "files" in response_data["data"]
|
||||
|
||||
|
||||
# route("/drive/cdrom", methods=["POST"])
|
||||
def test_create_cdrom_properties_file(env, http_client):
|
||||
file_name = f"{uuid.uuid4()}.iso"
|
||||
|
||||
response = http_client.post(
|
||||
"/drive/cdrom",
|
||||
DRIVE_CDROM_ENDPOINT,
|
||||
data={
|
||||
"drive_name": "Sony CDU-8012",
|
||||
"file_name": file_name,
|
||||
|
@ -78,13 +80,12 @@ def test_create_cdrom_properties_file(env, http_client):
|
|||
)
|
||||
|
||||
|
||||
# route("/drive/create", methods=["POST"])
|
||||
def test_create_image_with_properties_file(http_client, delete_file):
|
||||
file_prefix = str(uuid.uuid4())
|
||||
file_name = f"{file_prefix}.hds"
|
||||
|
||||
response = http_client.post(
|
||||
"/drive/create",
|
||||
DRIVE_CREATE_ENDPOINT,
|
||||
data={
|
||||
"drive_name": "Miniscribe M8425",
|
||||
"size": FILE_SIZE_1_MIB,
|
||||
|
@ -105,16 +106,14 @@ def test_create_image_with_properties_file(http_client, delete_file):
|
|||
delete_file(file_name)
|
||||
|
||||
|
||||
# route("/sys/manpage", methods=["POST"])
|
||||
def test_show_manpage(http_client):
|
||||
response = http_client.get("/sys/manpage?app=piscsi")
|
||||
response = http_client.get(MANPAGE_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "piscsi" in response_data["data"]["manpage"]
|
||||
|
||||
|
||||
# route("/healthcheck", methods=["GET"])
|
||||
def test_healthcheck(http_client):
|
||||
response = http_client.get("/healthcheck")
|
||||
response = http_client.get(HEALTHCHECK_ENDPOINT)
|
||||
assert response.status_code == 200
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
import pytest
|
||||
import uuid
|
||||
|
||||
from conftest import STATUS_SUCCESS
|
||||
from conftest import (
|
||||
STATUS_SUCCESS,
|
||||
ENV_ENDPOINT,
|
||||
LANGUAGE_ENDPOINT,
|
||||
LOG_LEVEL_ENDPOINT,
|
||||
LOG_SHOW_ENDPOINT,
|
||||
CONFIG_SAVE_ENDPOINT,
|
||||
CONFIG_ACTION_ENDPOINT,
|
||||
THEME_ENDPOINT,
|
||||
SYS_RENAME_ENDPOINT,
|
||||
RESERVE_ENDPOINT,
|
||||
)
|
||||
|
||||
|
||||
# route("/language", methods=["POST"])
|
||||
@pytest.mark.parametrize(
|
||||
"locale,confirm_message",
|
||||
[
|
||||
|
@ -18,7 +28,7 @@ from conftest import STATUS_SUCCESS
|
|||
)
|
||||
def test_set_language(http_client, locale, confirm_message):
|
||||
response = http_client.post(
|
||||
"/language",
|
||||
LANGUAGE_ENDPOINT,
|
||||
data={
|
||||
"locale": locale,
|
||||
},
|
||||
|
@ -31,11 +41,10 @@ def test_set_language(http_client, locale, confirm_message):
|
|||
assert response_data["messages"][0]["message"] == confirm_message
|
||||
|
||||
|
||||
# route("/logs/level", methods=["POST"])
|
||||
@pytest.mark.parametrize("level", ["trace", "debug", "info", "warn", "err", "off"])
|
||||
def test_set_log_level(http_client, level):
|
||||
response = http_client.post(
|
||||
"/logs/level",
|
||||
LOG_LEVEL_ENDPOINT,
|
||||
data={
|
||||
"level": level,
|
||||
},
|
||||
|
@ -49,17 +58,16 @@ def test_set_log_level(http_client, level):
|
|||
|
||||
# Cleanup
|
||||
http_client.post(
|
||||
"/logs/level",
|
||||
LOG_LEVEL_ENDPOINT,
|
||||
data={
|
||||
"level": "debug",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# route("/logs/show", methods=["POST"])
|
||||
def test_show_logs(http_client):
|
||||
response = http_client.post(
|
||||
"/logs/show",
|
||||
LOG_SHOW_ENDPOINT,
|
||||
data={
|
||||
"lines": 100,
|
||||
"scope": "piscsi",
|
||||
|
@ -73,8 +81,6 @@ def test_show_logs(http_client):
|
|||
assert response_data["data"]["scope"] == "piscsi"
|
||||
|
||||
|
||||
# route("/config/save", methods=["POST"])
|
||||
# route("/config/action", methods=["POST"])
|
||||
def test_save_load_and_delete_configs(env, http_client):
|
||||
config_name = str(uuid.uuid4())
|
||||
config_json_file = f"{config_name}.json"
|
||||
|
@ -86,7 +92,7 @@ def test_save_load_and_delete_configs(env, http_client):
|
|||
|
||||
# Save the initial state to a config
|
||||
response = http_client.post(
|
||||
"/config/save",
|
||||
CONFIG_SAVE_ENDPOINT,
|
||||
data={
|
||||
"name": config_name,
|
||||
},
|
||||
|
@ -104,7 +110,7 @@ def test_save_load_and_delete_configs(env, http_client):
|
|||
|
||||
# Modify the state
|
||||
http_client.post(
|
||||
"/scsi/reserve",
|
||||
RESERVE_ENDPOINT,
|
||||
data={
|
||||
"scsi_id": reserved_scsi_id,
|
||||
"memo": reservation_memo,
|
||||
|
@ -115,7 +121,7 @@ def test_save_load_and_delete_configs(env, http_client):
|
|||
|
||||
# Load the saved config
|
||||
response = http_client.post(
|
||||
"/config/action",
|
||||
CONFIG_ACTION_ENDPOINT,
|
||||
data={
|
||||
"name": config_json_file,
|
||||
"load": True,
|
||||
|
@ -135,7 +141,7 @@ def test_save_load_and_delete_configs(env, http_client):
|
|||
|
||||
# Delete the saved config
|
||||
response = http_client.post(
|
||||
"/config/action",
|
||||
CONFIG_ACTION_ENDPOINT,
|
||||
data={
|
||||
"name": config_json_file,
|
||||
"delete": True,
|
||||
|
@ -153,15 +159,13 @@ def test_save_load_and_delete_configs(env, http_client):
|
|||
assert config_json_file not in http_client.get("/").json()["data"]["config_files"]
|
||||
|
||||
|
||||
# route("/config/save", methods=["POST"])
|
||||
# route("/config/action", methods=["POST"])
|
||||
def test_download_configs(env, http_client, delete_file):
|
||||
def test_download_configs(env, http_client):
|
||||
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",
|
||||
CONFIG_SAVE_ENDPOINT,
|
||||
data={
|
||||
"name": config_name,
|
||||
},
|
||||
|
@ -172,7 +176,7 @@ def test_download_configs(env, http_client, delete_file):
|
|||
|
||||
# Download the saved config
|
||||
response = http_client.post(
|
||||
"/config/action",
|
||||
CONFIG_ACTION_ENDPOINT,
|
||||
data={
|
||||
"name": config_json_file,
|
||||
"send": True,
|
||||
|
@ -185,7 +189,7 @@ def test_download_configs(env, http_client, delete_file):
|
|||
|
||||
# Delete the saved config
|
||||
response = http_client.post(
|
||||
"/config/action",
|
||||
CONFIG_ACTION_ENDPOINT,
|
||||
data={
|
||||
"name": config_json_file,
|
||||
"delete": True,
|
||||
|
@ -196,7 +200,6 @@ def test_download_configs(env, http_client, delete_file):
|
|||
assert config_json_file not in http_client.get("/").json()["data"]["config_files"]
|
||||
|
||||
|
||||
# route("/theme", methods=["POST"])
|
||||
@pytest.mark.parametrize(
|
||||
"theme",
|
||||
[
|
||||
|
@ -206,7 +209,7 @@ def test_download_configs(env, http_client, delete_file):
|
|||
)
|
||||
def test_set_theme(http_client, theme):
|
||||
response = http_client.post(
|
||||
"/theme",
|
||||
THEME_ENDPOINT,
|
||||
data={
|
||||
"name": theme,
|
||||
},
|
||||
|
@ -219,7 +222,6 @@ def test_set_theme(http_client, theme):
|
|||
assert response_data["messages"][0]["message"] == f"Theme changed to '{theme}'."
|
||||
|
||||
|
||||
# route("/theme", methods=["GET"])
|
||||
@pytest.mark.parametrize(
|
||||
"theme",
|
||||
[
|
||||
|
@ -229,7 +231,7 @@ def test_set_theme(http_client, theme):
|
|||
)
|
||||
def test_set_theme_via_query_string(http_client, theme):
|
||||
response = http_client.get(
|
||||
"/theme",
|
||||
THEME_ENDPOINT,
|
||||
params={
|
||||
"name": theme,
|
||||
},
|
||||
|
@ -242,17 +244,16 @@ def test_set_theme_via_query_string(http_client, theme):
|
|||
assert response_data["messages"][0]["message"] == f"Theme changed to '{theme}'."
|
||||
|
||||
|
||||
# route("/sys/rename", methods=["POST"])
|
||||
def test_rename_system(env, http_client):
|
||||
new_name = "SYSTEM NAME TEST"
|
||||
|
||||
response = http_client.get("/env")
|
||||
response = http_client.get(ENV_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
old_name = response_data["data"]["system_name"]
|
||||
|
||||
response = http_client.post(
|
||||
"/sys/rename",
|
||||
SYS_RENAME_ENDPOINT,
|
||||
data={
|
||||
"system_name": new_name,
|
||||
},
|
||||
|
@ -264,13 +265,13 @@ def test_rename_system(env, http_client):
|
|||
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 = http_client.get(ENV_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
assert response_data["data"]["system_name"] == new_name
|
||||
|
||||
response = http_client.post(
|
||||
"/sys/rename",
|
||||
SYS_RENAME_ENDPOINT,
|
||||
data={
|
||||
"system_name": old_name,
|
||||
},
|
||||
|
@ -282,7 +283,7 @@ def test_rename_system(env, http_client):
|
|||
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 = http_client.get(ENV_ENDPOINT)
|
||||
response_data = response.json()
|
||||
|
||||
assert response_data["data"]["system_name"] == old_name
|
||||
|
|
Loading…
Reference in New Issue