File size: 3,525 Bytes
9410704
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Tests for SpeechEngineClient and AsyncSpeechEngineClient wrapper methods."""

from unittest.mock import AsyncMock, MagicMock, patch

import pytest

from elevenlabs.speech_engine.client import AsyncSpeechEngineClient as AutogeneratedAsyncSpeechEngineClient
from elevenlabs.speech_engine.client import SpeechEngineClient as AutogeneratedSpeechEngineClient
from elevenlabs.speech_engine.resource import SpeechEngineResource
from elevenlabs.speech_engine_custom import AsyncSpeechEngineClient, SpeechEngineClient
from elevenlabs.types.speech_engine_config import SpeechEngineConfig
from elevenlabs.types.speech_engine_response import SpeechEngineResponse


def _make_sync_client() -> SpeechEngineClient:
    return SpeechEngineClient(client_wrapper=MagicMock())


def _make_async_client() -> AsyncSpeechEngineClient:
    return AsyncSpeechEngineClient(client_wrapper=MagicMock())


# ---------------------------------------------------------------------------
# Sync
# ---------------------------------------------------------------------------


def test_create_returns_resource() -> None:
    client = _make_sync_client()
    mock_response = MagicMock(spec=SpeechEngineResponse, speech_engine_id="seng_abc")

    with patch.object(AutogeneratedSpeechEngineClient, "create", return_value=mock_response):
        result = client.create(speech_engine=SpeechEngineConfig(ws_url="wss://test"))

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"


def test_get_returns_resource() -> None:
    client = _make_sync_client()

    with patch.object(AutogeneratedSpeechEngineClient, "get", return_value=None):
        result = client.get("seng_abc")

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"


def test_update_returns_resource() -> None:
    client = _make_sync_client()

    with patch.object(AutogeneratedSpeechEngineClient, "update", return_value=None):
        result = client.update("seng_abc", name="Renamed")

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"


# ---------------------------------------------------------------------------
# Async
# ---------------------------------------------------------------------------


@pytest.mark.asyncio
async def test_async_create_returns_resource() -> None:
    client = _make_async_client()
    mock_response = MagicMock(spec=SpeechEngineResponse, speech_engine_id="seng_abc")

    with patch.object(AutogeneratedAsyncSpeechEngineClient, "create", new_callable=AsyncMock, return_value=mock_response):
        result = await client.create(speech_engine=SpeechEngineConfig(ws_url="wss://test"))

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"


@pytest.mark.asyncio
async def test_async_get_returns_resource() -> None:
    client = _make_async_client()

    with patch.object(AutogeneratedAsyncSpeechEngineClient, "get", new_callable=AsyncMock, return_value=None):
        result = await client.get("seng_abc")

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"


@pytest.mark.asyncio
async def test_async_update_returns_resource() -> None:
    client = _make_async_client()

    with patch.object(AutogeneratedAsyncSpeechEngineClient, "update", new_callable=AsyncMock, return_value=None):
        result = await client.update("seng_abc", name="Renamed")

    assert isinstance(result, SpeechEngineResource)
    assert result.engine_id == "seng_abc"