Skip to content

Commit 3d4b12d

Browse files
committed
Add integration tests and fix Speechmatics API client
- Add live integration tests that call real Speechmatics API - Fix client to use multipart/form-data format (required by API) - Add conftest.py with --run-integration flag support - Save real transcription outputs to fixtures for reference - Update unit tests for new multipart request format Integration tests: 9 tests, requires SPEECHMATICS_API_KEY env var Unit tests: 116 tests, 93% coverage
1 parent 5fd6b1f commit 3d4b12d

File tree

6 files changed

+2018
-4
lines changed

6 files changed

+2018
-4
lines changed

speechmatics_vcon_link/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def submit_job(
161161
SpeechmaticsAuthError: If API key is invalid
162162
SpeechmaticsError: If job submission fails
163163
"""
164+
import json as json_module
165+
164166
if config is None:
165167
config = TranscriptionConfig()
166168

@@ -176,9 +178,15 @@ def submit_job(
176178
logger.info(f"Submitting transcription job for: {audio_url}")
177179

178180
try:
181+
# Speechmatics API requires multipart/form-data
182+
# The config is sent as a JSON string in the 'config' field
183+
files = {
184+
'config': (None, json_module.dumps(job_config), 'application/json')
185+
}
186+
179187
response = self._session.post(
180188
url,
181-
json=job_config,
189+
files=files,
182190
timeout=self.timeout
183191
)
184192

@@ -202,7 +210,7 @@ def submit_job(
202210
except requests.HTTPError as e:
203211
error_detail = ""
204212
try:
205-
error_detail = e.response.json().get("detail", str(e))
213+
error_detail = e.response.json().get("message", str(e))
206214
except Exception:
207215
error_detail = str(e)
208216
raise SpeechmaticsError(f"Failed to submit job: {error_detail}") from e

tests/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Pytest configuration and fixtures for speechmatics_vcon_link tests."""
2+
3+
import pytest
4+
5+
6+
def pytest_addoption(parser):
7+
"""Add command line option for running integration tests."""
8+
parser.addoption(
9+
"--run-integration",
10+
action="store_true",
11+
default=False,
12+
help="Run integration tests that make real API calls",
13+
)
14+
15+
16+
def pytest_configure(config):
17+
"""Register custom markers."""
18+
config.addinivalue_line(
19+
"markers", "integration: mark test as integration test (requires --run-integration)"
20+
)
21+
22+
23+
def pytest_collection_modifyitems(config, items):
24+
"""Skip integration tests unless --run-integration is passed."""
25+
if config.getoption("--run-integration"):
26+
return
27+
28+
skip_integration = pytest.mark.skip(reason="Need --run-integration option to run")
29+
for item in items:
30+
if "integration" in item.keywords:
31+
item.add_marker(skip_integration)
32+

0 commit comments

Comments
 (0)