openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/containers/files/test_content.py
116lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from openai import OpenAI, AsyncOpenAI |
| 11 | |
| 12 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 13 | |
| 14 | |
| 15 | class TestContent: |
| 16 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 17 | |
| 18 | @parametrize |
| 19 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 20 | content = client.containers.files.content.retrieve( |
| 21 | file_id="file_id", |
| 22 | container_id="container_id", |
| 23 | ) |
| 24 | assert content is None |
| 25 | |
| 26 | @parametrize |
| 27 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 28 | response = client.containers.files.content.with_raw_response.retrieve( |
| 29 | file_id="file_id", |
| 30 | container_id="container_id", |
| 31 | ) |
| 32 | |
| 33 | assert response.is_closed is True |
| 34 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 35 | content = response.parse() |
| 36 | assert content is None |
| 37 | |
| 38 | @parametrize |
| 39 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 40 | with client.containers.files.content.with_streaming_response.retrieve( |
| 41 | file_id="file_id", |
| 42 | container_id="container_id", |
| 43 | ) as response: |
| 44 | assert not response.is_closed |
| 45 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 46 | |
| 47 | content = response.parse() |
| 48 | assert content is None |
| 49 | |
| 50 | assert cast(Any, response.is_closed) is True |
| 51 | |
| 52 | @parametrize |
| 53 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 54 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"): |
| 55 | client.containers.files.content.with_raw_response.retrieve( |
| 56 | file_id="file_id", |
| 57 | container_id="", |
| 58 | ) |
| 59 | |
| 60 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 61 | client.containers.files.content.with_raw_response.retrieve( |
| 62 | file_id="", |
| 63 | container_id="container_id", |
| 64 | ) |
| 65 | |
| 66 | |
| 67 | class TestAsyncContent: |
| 68 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 69 | |
| 70 | @parametrize |
| 71 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 72 | content = await async_client.containers.files.content.retrieve( |
| 73 | file_id="file_id", |
| 74 | container_id="container_id", |
| 75 | ) |
| 76 | assert content is None |
| 77 | |
| 78 | @parametrize |
| 79 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 80 | response = await async_client.containers.files.content.with_raw_response.retrieve( |
| 81 | file_id="file_id", |
| 82 | container_id="container_id", |
| 83 | ) |
| 84 | |
| 85 | assert response.is_closed is True |
| 86 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 87 | content = response.parse() |
| 88 | assert content is None |
| 89 | |
| 90 | @parametrize |
| 91 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 92 | async with async_client.containers.files.content.with_streaming_response.retrieve( |
| 93 | file_id="file_id", |
| 94 | container_id="container_id", |
| 95 | ) as response: |
| 96 | assert not response.is_closed |
| 97 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 98 | |
| 99 | content = await response.parse() |
| 100 | assert content is None |
| 101 | |
| 102 | assert cast(Any, response.is_closed) is True |
| 103 | |
| 104 | @parametrize |
| 105 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 106 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"): |
| 107 | await async_client.containers.files.content.with_raw_response.retrieve( |
| 108 | file_id="file_id", |
| 109 | container_id="", |
| 110 | ) |
| 111 | |
| 112 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 113 | await async_client.containers.files.content.with_raw_response.retrieve( |
| 114 | file_id="", |
| 115 | container_id="container_id", |
| 116 | ) |
| 117 | |