|
|
import app as app |
|
|
from unittest.mock import patch, MagicMock |
|
|
|
|
|
@patch("app.client_gr.chat.completions.create") |
|
|
def test_translate_transcript(mock_create): |
|
|
|
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock(message=MagicMock(content="This is the translated text."))] |
|
|
) |
|
|
|
|
|
spanish_input = "Hola, ¿cómo estás?" |
|
|
|
|
|
|
|
|
result = app.translate_transcript(spanish_input) |
|
|
|
|
|
|
|
|
assert result == "This is the translated text." |
|
|
mock_create.assert_called_once() |
|
|
|
|
|
@patch("app.client_gr.chat.completions.create") |
|
|
def test_run_quality_check(mock_create): |
|
|
|
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock(message=MagicMock(content="Fluency: 9/10, Accuracy: 10/10"))] |
|
|
) |
|
|
spanish_input = "Hola, ¿cómo estás?" |
|
|
english_input = "Hello, how are you?" |
|
|
|
|
|
|
|
|
result = app.run_quality_check(spanish_input, english_input) |
|
|
|
|
|
assert result == "Fluency: 9/10, Accuracy: 10/10" |
|
|
mock_create.assert_called_once() |
|
|
|
|
|
@patch("app.client_el.text_to_speech.convert") |
|
|
def test_generate_dub(mock_create): |
|
|
|
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock( |
|
|
message=MagicMock( |
|
|
content="This is the generated audio stream." |
|
|
) |
|
|
)]) |
|
|
|
|
|
input_text = "Hello there!" |
|
|
result = app.generate_dub(input_text) |
|
|
|
|
|
assert result == "This is the generated audio stream." |
|
|
mock_create.assert_called_once() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch("app.client_gr.chat.completions.create") |
|
|
def test_translate_transcript_empty_input(mock_create): |
|
|
|
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock(message=MagicMock(content=""))] |
|
|
) |
|
|
|
|
|
spanish_input = "" |
|
|
|
|
|
|
|
|
result = app.translate_transcript(spanish_input) |
|
|
|
|
|
|
|
|
assert result == "" |
|
|
mock_create.assert_called_once() |
|
|
|
|
|
@patch("app.client_gr.chat.completions.create") |
|
|
def test_run_quality_check_incomplete(mock_create): |
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock(message=MagicMock(content=""))] |
|
|
) |
|
|
spanish_input = "Hola, ¿cómo estás?" |
|
|
english_input = "" |
|
|
|
|
|
|
|
|
result = app.run_quality_check(spanish_input, english_input) |
|
|
|
|
|
assert result == "" |
|
|
mock_create.assert_called_once() |
|
|
|
|
|
@patch("app.client_el.text_to_speech.convert") |
|
|
def test_generate_dub_empty_text(mock_create): |
|
|
mock_create.return_value = MagicMock( |
|
|
choices=[MagicMock(message=MagicMock(content=""))]) |
|
|
|
|
|
result = app.generate_dub("") |
|
|
assert result == "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch("app.client_gr.chat.completions.create") |
|
|
def test_translate_transcript_exception(mock_create): |
|
|
mock_create.side_effect = Exception("API error") |
|
|
spanish_input = "Hola, ¿cómo estás?" |
|
|
|
|
|
|
|
|
with patch("builtins.print") as mock_print: |
|
|
result = app.translate_transcript(spanish_input) |
|
|
assert result is None |
|
|
mock_print.assert_called_once_with("API error") |