Spaces:
Running
Running
File size: 4,088 Bytes
3e08670 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | """
Tests unitaires pour l'API MMS ASR/TTS
"""
import pytest
import json
import io
from flask import Flask
import sys
from pathlib import Path
# Importe l'app
sys.path.insert(0, str(Path(__file__).parent))
# Note: Pour les tests complets, il faudrait utiliser une version mockée
# des modèles ou des fixtures avec des modèles minimalistes
@pytest.fixture
def client():
"""Crée un client Flask pour les tests"""
from app_v2 import app
app.config['TESTING'] = True
with app.test_client() as client:
yield client
class TestAPI:
"""Tests des endpoints"""
def test_health(self, client):
"""Test le endpoint /health"""
response = client.get('/health')
assert response.status_code == 200
data = response.get_json()
assert 'status' in data
assert data['status'] == 'healthy'
def test_index(self, client):
"""Test le endpoint racine"""
response = client.get('/')
assert response.status_code == 200
data = response.get_json()
assert 'name' in data
assert 'endpoints' in data
def test_supported_languages(self, client):
"""Test le endpoint /supported-languages"""
response = client.get('/supported-languages')
assert response.status_code == 200
data = response.get_json()
assert 'asr' in data
assert 'tts' in data
assert 'eng' in data['tts']['languages']
def test_models_info(self, client):
"""Test le endpoint /models-info"""
response = client.get('/models-info')
assert response.status_code == 200
data = response.get_json()
assert 'asr' in data
assert 'tts' in data
def test_tts_missing_text(self, client):
"""Test TTS sans texte"""
response = client.post('/tts',
data=json.dumps({}),
content_type='application/json'
)
assert response.status_code == 400
data = response.get_json()
assert 'error' in data
def test_tts_empty_text(self, client):
"""Test TTS avec texte vide"""
response = client.post('/tts',
data=json.dumps({'text': ' '}),
content_type='application/json'
)
assert response.status_code == 400
def test_asr_missing_file(self, client):
"""Test ASR sans fichier"""
response = client.post('/asr')
assert response.status_code == 400
data = response.get_json()
assert 'error' in data
def test_404(self, client):
"""Test endpoint inexistant"""
response = client.get('/nonexistent')
assert response.status_code == 404
class TestLanguageMapping:
"""Tests du mapping des langues"""
def test_supported_languages(self):
"""Vérifie que les langues documentées sont configurées"""
from app_v2 import LANGUAGE_MAPPING
expected_languages = ['beh', 'bba', 'ddn', 'ewe', 'gej', 'tbz', 'yor', 'eng']
for lang in expected_languages:
assert lang in LANGUAGE_MAPPING, f"Langue {lang} manquante"
def test_language_mapping_format(self):
"""Vérifie le format du mapping des langues"""
from app_v2 import LANGUAGE_MAPPING
for lang, model_id in LANGUAGE_MAPPING.items():
assert isinstance(lang, str)
assert isinstance(model_id, str)
assert model_id.startswith('facebook/mms-tts-')
class TestConfig:
"""Tests de configuration"""
def test_sample_rate(self):
"""Test que SAMPLE_RATE est correct"""
from app_v2 import SAMPLE_RATE
assert SAMPLE_RATE == 16000
def test_max_audio_length(self):
"""Test que MAX_AUDIO_LENGTH est raisonnable"""
from app_v2 import MAX_AUDIO_LENGTH
assert 10 <= MAX_AUDIO_LENGTH <= 120
def test_max_text_length(self):
"""Test que MAX_TEXT_LENGTH est raisonnable"""
from app_v2 import MAX_TEXT_LENGTH
assert 100 <= MAX_TEXT_LENGTH <= 5000
if __name__ == '__main__':
pytest.main([__file__, '-v'])
|