restructuring

This commit is contained in:
2025-02-27 15:08:05 +01:00
parent fc67f0f23d
commit 31f2594cb0
26 changed files with 258 additions and 100 deletions

71
tests/test_server.py Normal file
View File

@@ -0,0 +1,71 @@
import pytest
import asyncio
from quart import jsonify
from auracast import multicast_server
@pytest.fixture
def client():
"""Fixture to create and return a Quart test client."""
yield multicast_server.app.test_client()
@pytest.mark.asyncio
async def test_initialize(client):
"""Tests the /init endpoint."""
#client = multicast_server.app.test_client()
response = await client.post('/init')
json_data = await response.get_json()
assert response.status_code == 200
assert json_data["status"] == "initialized"
@pytest.mark.asyncio
async def test_shutdown(client):
"""Tests the /shutdown endpoint."""
response = await client.post('/shutdown')
json_data = await response.get_json()
assert response.status_code == 200
assert json_data["status"] == "stopped"
@pytest.mark.asyncio
async def test_stop_audio(client):
"""Tests the /stop_audio endpoint."""
response = await client.post('/stop_audio')
json_data = await response.get_json()
assert response.status_code == 200
assert json_data["status"] == "stopped"
@pytest.mark.asyncio
async def test_send_audio(client):
"""Tests the /stream_lc3 endpoint."""
test_audio_data = {
"broadcast_de": read_lc3_file(big.audio_source),
"broadcast_fr": b"test_audio_data_fr"
}
response = await client.post('/stream_lc3', json=test_audio_data)
json_data = await response.get_json()
assert response.status_code == 200
assert json_data["status"] == "audio_sent"
# Ensure the audio data is correctly assigned
for key, val in multicast_server.big_conf.items():
if key in test_audio_data:
assert val.audio_source == test_audio_data[key]
else:
assert val.audio_source == b""
@pytest.mark.asyncio
async def test_get_status(client):
"""Tests the /status endpoint."""
response = await client.get('/status')
json_data = await response.get_json()
assert response.status_code == 200
assert "status" in json_data