openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/audio/test_translations.py
85lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from openai import OpenAI, AsyncOpenAI |
| 10 | from tests.utils import assert_matches_type |
| 11 | from openai._client import OpenAI, AsyncOpenAI |
| 12 | from openai.types.audio import Translation |
| 13 | |
| 14 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 15 | api_key = "My API Key" |
| 16 | |
| 17 | |
| 18 | class TestTranslations: |
| 19 | strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 20 | loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 21 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 22 | |
| 23 | @parametrize |
| 24 | def test_method_create(self, client: OpenAI) -> None: |
| 25 | translation = client.audio.translations.create( |
| 26 | file=b"raw file contents", |
| 27 | model="whisper-1", |
| 28 | ) |
| 29 | assert_matches_type(Translation, translation, path=["response"]) |
| 30 | |
| 31 | @parametrize |
| 32 | def test_method_create_with_all_params(self, client: OpenAI) -> None: |
| 33 | translation = client.audio.translations.create( |
| 34 | file=b"raw file contents", |
| 35 | model="whisper-1", |
| 36 | prompt="string", |
| 37 | response_format="string", |
| 38 | temperature=0, |
| 39 | ) |
| 40 | assert_matches_type(Translation, translation, path=["response"]) |
| 41 | |
| 42 | @parametrize |
| 43 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 44 | response = client.audio.translations.with_raw_response.create( |
| 45 | file=b"raw file contents", |
| 46 | model="whisper-1", |
| 47 | ) |
| 48 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 49 | translation = response.parse() |
| 50 | assert_matches_type(Translation, translation, path=["response"]) |
| 51 | |
| 52 | |
| 53 | class TestAsyncTranslations: |
| 54 | strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True) |
| 55 | loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False) |
| 56 | parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"]) |
| 57 | |
| 58 | @parametrize |
| 59 | async def test_method_create(self, client: AsyncOpenAI) -> None: |
| 60 | translation = await client.audio.translations.create( |
| 61 | file=b"raw file contents", |
| 62 | model="whisper-1", |
| 63 | ) |
| 64 | assert_matches_type(Translation, translation, path=["response"]) |
| 65 | |
| 66 | @parametrize |
| 67 | async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None: |
| 68 | translation = await client.audio.translations.create( |
| 69 | file=b"raw file contents", |
| 70 | model="whisper-1", |
| 71 | prompt="string", |
| 72 | response_format="string", |
| 73 | temperature=0, |
| 74 | ) |
| 75 | assert_matches_type(Translation, translation, path=["response"]) |
| 76 | |
| 77 | @parametrize |
| 78 | async def test_raw_response_create(self, client: AsyncOpenAI) -> None: |
| 79 | response = await client.audio.translations.with_raw_response.create( |
| 80 | file=b"raw file contents", |
| 81 | model="whisper-1", |
| 82 | ) |
| 83 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 84 | translation = response.parse() |
| 85 | assert_matches_type(Translation, translation, path=["response"]) |
| 86 | |