Skip to content

Commit 5a1a659

Browse files
SDK regeneration
1 parent ad93815 commit 5a1a659

28 files changed

+1094
-2
lines changed

.fern/metadata.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"exported_filename": "client.py"
1111
},
1212
"use_typeddict_requests": true,
13-
"should_generate_websocket_clients": true
13+
"should_generate_websocket_clients": true,
14+
"enable_wire_tests": true
1415
}
1516
}

poetry.lock

Lines changed: 175 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ pytest-asyncio = "^0.23.5"
5050
pytest-xdist = "^3.6.1"
5151
python-dateutil = "^2.9.0"
5252
types-python-dateutil = "^2.9.0.20240316"
53+
requests = "^2.31.0"
54+
types-requests = "^2.31.0"
5355
ruff = "==0.11.5"
5456

5557
[tool.pytest.ini_options]

tests/wire/__init__.py

Whitespace-only changes.

tests/wire/conftest.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""
2+
Pytest configuration for wire tests.
3+
4+
This module manages the WireMock container lifecycle for integration tests.
5+
It is compatible with pytest-xdist parallelization by ensuring only the
6+
controller process (or the single process in non-xdist runs) starts and
7+
stops the WireMock container.
8+
"""
9+
10+
import os
11+
import subprocess
12+
from typing import Any, Dict, Optional
13+
14+
import pytest
15+
import requests
16+
17+
from deepgram.client import DeepgramApi
18+
19+
20+
def _compose_file() -> str:
21+
"""Returns the path to the docker-compose file for WireMock."""
22+
test_dir = os.path.dirname(__file__)
23+
project_root = os.path.abspath(os.path.join(test_dir, "..", ".."))
24+
wiremock_dir = os.path.join(project_root, "wiremock")
25+
return os.path.join(wiremock_dir, "docker-compose.test.yml")
26+
27+
28+
def _start_wiremock() -> None:
29+
"""Starts the WireMock container using docker-compose."""
30+
compose_file = _compose_file()
31+
print("\nStarting WireMock container...")
32+
try:
33+
subprocess.run(
34+
["docker", "compose", "-f", compose_file, "up", "-d", "--wait"],
35+
check=True,
36+
capture_output=True,
37+
text=True,
38+
)
39+
print("WireMock container is ready")
40+
except subprocess.CalledProcessError as e:
41+
print(f"Failed to start WireMock: {e.stderr}")
42+
raise
43+
44+
45+
def _stop_wiremock() -> None:
46+
"""Stops and removes the WireMock container."""
47+
compose_file = _compose_file()
48+
print("\nStopping WireMock container...")
49+
subprocess.run(
50+
["docker", "compose", "-f", compose_file, "down", "-v"],
51+
check=False,
52+
capture_output=True,
53+
)
54+
55+
56+
def _is_xdist_worker(config: pytest.Config) -> bool:
57+
"""
58+
Determines if the current process is an xdist worker.
59+
60+
In pytest-xdist, worker processes have a 'workerinput' attribute
61+
on the config object, while the controller process does not.
62+
"""
63+
return hasattr(config, "workerinput")
64+
65+
66+
def pytest_configure(config: pytest.Config) -> None:
67+
"""
68+
Pytest hook that runs during test session setup.
69+
70+
Starts WireMock container only from the controller process (xdist)
71+
or the single process (non-xdist). This ensures only one container
72+
is started regardless of the number of worker processes.
73+
"""
74+
if not _is_xdist_worker(config):
75+
_start_wiremock()
76+
77+
78+
def pytest_unconfigure(config: pytest.Config) -> None:
79+
"""
80+
Pytest hook that runs during test session teardown.
81+
82+
Stops WireMock container only from the controller process (xdist)
83+
or the single process (non-xdist). This ensures the container is
84+
cleaned up after all workers have finished.
85+
"""
86+
if not _is_xdist_worker(config):
87+
_stop_wiremock()
88+
89+
90+
def get_client(test_id: str) -> DeepgramApi:
91+
"""
92+
Creates a configured client instance for wire tests.
93+
94+
Args:
95+
test_id: Unique identifier for the test, used for request tracking.
96+
97+
Returns:
98+
A configured client instance with all required auth parameters.
99+
"""
100+
return DeepgramApi(
101+
base_url="http://localhost:8080",
102+
headers={"X-Test-Id": test_id},
103+
api_key="test_api_key",
104+
)
105+
106+
107+
def verify_request_count(
108+
test_id: str,
109+
method: str,
110+
url_path: str,
111+
query_params: Optional[Dict[str, str]],
112+
expected: int,
113+
) -> None:
114+
"""Verifies the number of requests made to WireMock filtered by test ID for concurrency safety"""
115+
wiremock_admin_url = "http://localhost:8080/__admin"
116+
request_body: Dict[str, Any] = {
117+
"method": method,
118+
"urlPath": url_path,
119+
"headers": {"X-Test-Id": {"equalTo": test_id}},
120+
}
121+
if query_params:
122+
query_parameters = {k: {"equalTo": v} for k, v in query_params.items()}
123+
request_body["queryParameters"] = query_parameters
124+
response = requests.post(f"{wiremock_admin_url}/requests/find", json=request_body)
125+
assert response.status_code == 200, "Failed to query WireMock requests"
126+
result = response.json()
127+
requests_found = len(result.get("requests", []))
128+
assert requests_found == expected, f"Expected {expected} requests, found {requests_found}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .conftest import get_client, verify_request_count
2+
3+
4+
def test_agent_v1_settings_think_models_list_() -> None:
5+
"""Test list endpoint with WireMock"""
6+
test_id = "agent.v1.settings.think.models.list_.0"
7+
client = get_client(test_id)
8+
client.agent.v1.settings.think.models.list()
9+
verify_request_count(test_id, "GET", "/v1/agent/settings/think/models", None, 1)

tests/wire/test_auth_v1_tokens.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from .conftest import get_client, verify_request_count
2+
3+
4+
def test_auth_v1_tokens_grant() -> None:
5+
"""Test grant endpoint with WireMock"""
6+
test_id = "auth.v1.tokens.grant.0"
7+
client = get_client(test_id)
8+
client.auth.v1.tokens.grant()
9+
verify_request_count(test_id, "POST", "/v1/auth/grant", None, 1)

tests/wire/test_listen_v1_media.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from .conftest import get_client, verify_request_count
2+
3+
4+
def test_listen_v1_media_transcribe_url() -> None:
5+
"""Test transcribeUrl endpoint with WireMock"""
6+
test_id = "listen.v1.media.transcribe_url.0"
7+
client = get_client(test_id)
8+
client.listen.v1.media.transcribe_url(
9+
callback="callback",
10+
callback_method="POST",
11+
extra=["extra"],
12+
sentiment=True,
13+
summarize="v2",
14+
tag=["tag"],
15+
topics=True,
16+
custom_topic=["custom_topic"],
17+
custom_topic_mode="extended",
18+
intents=True,
19+
custom_intent=["custom_intent"],
20+
custom_intent_mode="extended",
21+
detect_entities=True,
22+
detect_language=True,
23+
diarize=True,
24+
dictation=True,
25+
encoding="linear16",
26+
filler_words=True,
27+
keywords=["keywords"],
28+
language="language",
29+
measurements=True,
30+
model="nova-3",
31+
multichannel=True,
32+
numerals=True,
33+
paragraphs=True,
34+
profanity_filter=True,
35+
punctuate=True,
36+
redact="redact",
37+
replace=["replace"],
38+
search=["search"],
39+
smart_format=True,
40+
utterances=True,
41+
utt_split=1.1,
42+
version="latest",
43+
mip_opt_out=True,
44+
url="https://dpgr.am/spacewalk.wav",
45+
)
46+
verify_request_count(
47+
test_id,
48+
"POST",
49+
"/v1/listen",
50+
{
51+
"callback": "callback",
52+
"callback_method": "POST",
53+
"extra": "extra",
54+
"sentiment": "true",
55+
"summarize": "v2",
56+
"tag": "tag",
57+
"topics": "true",
58+
"custom_topic": "custom_topic",
59+
"custom_topic_mode": "extended",
60+
"intents": "true",
61+
"custom_intent": "custom_intent",
62+
"custom_intent_mode": "extended",
63+
"detect_entities": "true",
64+
"detect_language": "true",
65+
"diarize": "true",
66+
"dictation": "true",
67+
"encoding": "linear16",
68+
"filler_words": "true",
69+
"keywords": "keywords",
70+
"language": "language",
71+
"measurements": "true",
72+
"model": "nova-3",
73+
"multichannel": "true",
74+
"numerals": "true",
75+
"paragraphs": "true",
76+
"profanity_filter": "true",
77+
"punctuate": "true",
78+
"redact": "redact",
79+
"replace": "replace",
80+
"search": "search",
81+
"smart_format": "true",
82+
"utterances": "true",
83+
"utt_split": "1.1",
84+
"version": "latest",
85+
"mip_opt_out": "true",
86+
},
87+
1,
88+
)
89+
90+
91+
def test_listen_v1_media_transcribe_file() -> None:
92+
"""Test transcribeFile endpoint with WireMock"""
93+
test_id = "listen.v1.media.transcribe_file.0"
94+
client = get_client(test_id)
95+
client.listen.v1.media.transcribe_url()
96+
verify_request_count(test_id, "POST", "/v1/listen", None, 1)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from .conftest import get_client, verify_request_count
2+
3+
4+
def test_manage_v1_models_list_() -> None:
5+
"""Test list endpoint with WireMock"""
6+
test_id = "manage.v1.models.list_.0"
7+
client = get_client(test_id)
8+
client.manage.v1.models.list(include_outdated=True)
9+
verify_request_count(test_id, "GET", "/v1/models", {"include_outdated": "true"}, 1)
10+
11+
12+
def test_manage_v1_models_get() -> None:
13+
"""Test get endpoint with WireMock"""
14+
test_id = "manage.v1.models.get.0"
15+
client = get_client(test_id)
16+
client.manage.v1.models.get(model_id="af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291")
17+
verify_request_count(test_id, "GET", "/v1/models/af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291", None, 1)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from .conftest import get_client, verify_request_count
2+
3+
4+
def test_manage_v1_projects_list_() -> None:
5+
"""Test list endpoint with WireMock"""
6+
test_id = "manage.v1.projects.list_.0"
7+
client = get_client(test_id)
8+
client.manage.v1.projects.list()
9+
verify_request_count(test_id, "GET", "/v1/projects", None, 1)
10+
11+
12+
def test_manage_v1_projects_get() -> None:
13+
"""Test get endpoint with WireMock"""
14+
test_id = "manage.v1.projects.get.0"
15+
client = get_client(test_id)
16+
client.manage.v1.projects.get(project_id="123456-7890-1234-5678-901234", limit=1.1, page=1.1)
17+
verify_request_count(
18+
test_id, "GET", "/v1/projects/123456-7890-1234-5678-901234", {"limit": "1.1", "page": "1.1"}, 1
19+
)
20+
21+
22+
def test_manage_v1_projects_delete() -> None:
23+
"""Test delete endpoint with WireMock"""
24+
test_id = "manage.v1.projects.delete.0"
25+
client = get_client(test_id)
26+
client.manage.v1.projects.delete(project_id="123456-7890-1234-5678-901234")
27+
verify_request_count(test_id, "DELETE", "/v1/projects/123456-7890-1234-5678-901234", None, 1)
28+
29+
30+
def test_manage_v1_projects_update() -> None:
31+
"""Test update endpoint with WireMock"""
32+
test_id = "manage.v1.projects.update.0"
33+
client = get_client(test_id)
34+
client.manage.v1.projects.update(project_id="123456-7890-1234-5678-901234")
35+
verify_request_count(test_id, "PATCH", "/v1/projects/123456-7890-1234-5678-901234", None, 1)
36+
37+
38+
def test_manage_v1_projects_leave() -> None:
39+
"""Test leave endpoint with WireMock"""
40+
test_id = "manage.v1.projects.leave.0"
41+
client = get_client(test_id)
42+
client.manage.v1.projects.leave(project_id="123456-7890-1234-5678-901234")
43+
verify_request_count(test_id, "DELETE", "/v1/projects/123456-7890-1234-5678-901234/leave", None, 1)

0 commit comments

Comments
 (0)