2022-09-24 02:10:01 +00:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
from conftest import (
|
|
|
|
FILE_SIZE_1_MIB,
|
|
|
|
STATUS_SUCCESS,
|
2023-12-08 01:38:24 +00:00
|
|
|
ENV_ENDPOINT,
|
|
|
|
PWA_FAVICON_ENDPOINT,
|
|
|
|
HEALTHCHECK_ENDPOINT,
|
|
|
|
DRIVE_LIST_ENDPOINT,
|
|
|
|
DRIVE_CREATE_ENDPOINT,
|
|
|
|
DRIVE_CDROM_ENDPOINT,
|
|
|
|
MANPAGE_ENDPOINT,
|
2022-09-24 02:10:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_index(http_client):
|
|
|
|
response = http_client.get("/")
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
assert "devices" in response_data["data"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_env_info(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(ENV_ENDPOINT)
|
2022-09-24 02:10:01 +00:00
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
|
|
|
assert "running_env" in response_data["data"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_pwa_route(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(PWA_FAVICON_ENDPOINT)
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response.headers["content-disposition"] == "inline; filename=favicon.ico"
|
|
|
|
|
|
|
|
|
|
|
|
def test_show_named_drive_presets(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(DRIVE_LIST_ENDPOINT)
|
2022-09-24 02:10:01 +00:00
|
|
|
response_data = response.json()
|
|
|
|
|
2022-10-25 15:51:04 +00:00
|
|
|
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
|
|
|
|
|
2022-09-24 02:10:01 +00:00
|
|
|
assert response.status_code == 200
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
2022-10-09 20:50:20 +00:00
|
|
|
assert "files" in response_data["data"]
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
|
2022-10-15 02:30:08 +00:00
|
|
|
def test_create_cdrom_properties_file(env, http_client):
|
2022-09-24 02:10:01 +00:00
|
|
|
file_name = f"{uuid.uuid4()}.iso"
|
|
|
|
|
|
|
|
response = http_client.post(
|
2023-12-08 01:38:24 +00:00
|
|
|
DRIVE_CDROM_ENDPOINT,
|
2022-09-24 02:10:01 +00:00
|
|
|
data={
|
2022-10-06 21:04:41 +00:00
|
|
|
"drive_name": "Sony CDU-8012",
|
2022-09-24 02:10:01 +00:00
|
|
|
"file_name": file_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']}/{file_name}.properties"
|
2022-09-24 02:10:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-12-08 01:38:24 +00:00
|
|
|
DRIVE_CREATE_ENDPOINT,
|
2022-09-24 02:10:01 +00:00
|
|
|
data={
|
2022-10-06 21:04:41 +00:00
|
|
|
"drive_name": "Miniscribe M8425",
|
2022-09-24 02:10:01 +00:00
|
|
|
"size": FILE_SIZE_1_MIB,
|
|
|
|
"file_name": file_prefix,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert response_data["status"] == STATUS_SUCCESS
|
2022-10-24 02:05:29 +00:00
|
|
|
assert (
|
|
|
|
response_data["messages"][0]["message"]
|
|
|
|
== f"Image file with properties created: {file_name}"
|
|
|
|
)
|
2022-09-24 02:10:01 +00:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
delete_file(file_name)
|
2022-10-03 19:46:18 +00:00
|
|
|
|
2022-10-15 02:30:08 +00:00
|
|
|
|
2022-10-03 19:46:18 +00:00
|
|
|
def test_show_manpage(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(MANPAGE_ENDPOINT)
|
2022-10-03 19:46:18 +00:00
|
|
|
response_data = response.json()
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
2022-12-05 17:58:23 +00:00
|
|
|
assert "piscsi" in response_data["data"]["manpage"]
|
2022-12-04 14:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_healthcheck(http_client):
|
2023-12-08 01:38:24 +00:00
|
|
|
response = http_client.get(HEALTHCHECK_ENDPOINT)
|
2022-12-04 14:31:57 +00:00
|
|
|
assert response.status_code == 200
|