71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
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 |