# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

import os
from typing import Any, cast

import pytest

from telnyx import Telnyx, AsyncTelnyx
from tests.utils import assert_matches_type
from telnyx.pagination import SyncDefaultFlatPagination, AsyncDefaultFlatPagination
from telnyx.types.ai.assistants import (
    AssistantTest,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")


class TestTests:
    parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_create(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_create_with_all_params(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
            description="description",
            max_duration_seconds=1,
            telnyx_conversation_channel="web_chat",
            test_suite="test_suite",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_create(self, client: Telnyx) -> None:
        response = client.ai.assistants.tests.with_raw_response.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_create(self, client: Telnyx) -> None:
        with client.ai.assistants.tests.with_streaming_response.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_retrieve(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.retrieve(
            "test_id",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_retrieve(self, client: Telnyx) -> None:
        response = client.ai.assistants.tests.with_raw_response.retrieve(
            "test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_retrieve(self, client: Telnyx) -> None:
        with client.ai.assistants.tests.with_streaming_response.retrieve(
            "test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_path_params_retrieve(self, client: Telnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            client.ai.assistants.tests.with_raw_response.retrieve(
                "",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_update(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.update(
            test_id="test_id",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_update_with_all_params(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.update(
            test_id="test_id",
            description="description",
            destination="x",
            instructions="x",
            max_duration_seconds=1,
            name="x",
            rubric=[
                {
                    "criteria": "criteria",
                    "name": "name",
                }
            ],
            telnyx_conversation_channel="phone_call",
            test_suite="test_suite",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_update(self, client: Telnyx) -> None:
        response = client.ai.assistants.tests.with_raw_response.update(
            test_id="test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_update(self, client: Telnyx) -> None:
        with client.ai.assistants.tests.with_streaming_response.update(
            test_id="test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_path_params_update(self, client: Telnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            client.ai.assistants.tests.with_raw_response.update(
                test_id="",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_list(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.list()
        assert_matches_type(SyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_list_with_all_params(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.list(
            destination="destination",
            page_number=0,
            page_size=0,
            telnyx_conversation_channel="telnyx_conversation_channel",
            test_suite="test_suite",
        )
        assert_matches_type(SyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_list(self, client: Telnyx) -> None:
        response = client.ai.assistants.tests.with_raw_response.list()

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = response.parse()
        assert_matches_type(SyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_list(self, client: Telnyx) -> None:
        with client.ai.assistants.tests.with_streaming_response.list() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = response.parse()
            assert_matches_type(SyncDefaultFlatPagination[AssistantTest], test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_method_delete(self, client: Telnyx) -> None:
        test = client.ai.assistants.tests.delete(
            "test_id",
        )
        assert test is None

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_raw_response_delete(self, client: Telnyx) -> None:
        response = client.ai.assistants.tests.with_raw_response.delete(
            "test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = response.parse()
        assert test is None

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_streaming_response_delete(self, client: Telnyx) -> None:
        with client.ai.assistants.tests.with_streaming_response.delete(
            "test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = response.parse()
            assert test is None

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    def test_path_params_delete(self, client: Telnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            client.ai.assistants.tests.with_raw_response.delete(
                "",
            )


class TestAsyncTests:
    parametrize = pytest.mark.parametrize(
        "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
    )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_create(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_create_with_all_params(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
            description="description",
            max_duration_seconds=1,
            telnyx_conversation_channel="web_chat",
            test_suite="test_suite",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_create(self, async_client: AsyncTelnyx) -> None:
        response = await async_client.ai.assistants.tests.with_raw_response.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = await response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_create(self, async_client: AsyncTelnyx) -> None:
        async with async_client.ai.assistants.tests.with_streaming_response.create(
            destination="+15551234567",
            instructions="Act as a frustrated customer who received a damaged product. Ask for a refund and escalate if not satisfied with the initial response.",
            name="Customer Support Bot Test",
            rubric=[
                {
                    "criteria": "Assistant responds within 30 seconds",
                    "name": "Response Time",
                },
                {
                    "criteria": "Provides correct product information",
                    "name": "Accuracy",
                },
            ],
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = await response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_retrieve(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.retrieve(
            "test_id",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_retrieve(self, async_client: AsyncTelnyx) -> None:
        response = await async_client.ai.assistants.tests.with_raw_response.retrieve(
            "test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = await response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_retrieve(self, async_client: AsyncTelnyx) -> None:
        async with async_client.ai.assistants.tests.with_streaming_response.retrieve(
            "test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = await response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_path_params_retrieve(self, async_client: AsyncTelnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            await async_client.ai.assistants.tests.with_raw_response.retrieve(
                "",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_update(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.update(
            test_id="test_id",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_update_with_all_params(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.update(
            test_id="test_id",
            description="description",
            destination="x",
            instructions="x",
            max_duration_seconds=1,
            name="x",
            rubric=[
                {
                    "criteria": "criteria",
                    "name": "name",
                }
            ],
            telnyx_conversation_channel="phone_call",
            test_suite="test_suite",
        )
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_update(self, async_client: AsyncTelnyx) -> None:
        response = await async_client.ai.assistants.tests.with_raw_response.update(
            test_id="test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = await response.parse()
        assert_matches_type(AssistantTest, test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_update(self, async_client: AsyncTelnyx) -> None:
        async with async_client.ai.assistants.tests.with_streaming_response.update(
            test_id="test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = await response.parse()
            assert_matches_type(AssistantTest, test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_path_params_update(self, async_client: AsyncTelnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            await async_client.ai.assistants.tests.with_raw_response.update(
                test_id="",
            )

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_list(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.list()
        assert_matches_type(AsyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_list_with_all_params(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.list(
            destination="destination",
            page_number=0,
            page_size=0,
            telnyx_conversation_channel="telnyx_conversation_channel",
            test_suite="test_suite",
        )
        assert_matches_type(AsyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_list(self, async_client: AsyncTelnyx) -> None:
        response = await async_client.ai.assistants.tests.with_raw_response.list()

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = await response.parse()
        assert_matches_type(AsyncDefaultFlatPagination[AssistantTest], test, path=["response"])

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_list(self, async_client: AsyncTelnyx) -> None:
        async with async_client.ai.assistants.tests.with_streaming_response.list() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = await response.parse()
            assert_matches_type(AsyncDefaultFlatPagination[AssistantTest], test, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_method_delete(self, async_client: AsyncTelnyx) -> None:
        test = await async_client.ai.assistants.tests.delete(
            "test_id",
        )
        assert test is None

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_raw_response_delete(self, async_client: AsyncTelnyx) -> None:
        response = await async_client.ai.assistants.tests.with_raw_response.delete(
            "test_id",
        )

        assert response.is_closed is True
        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
        test = await response.parse()
        assert test is None

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_streaming_response_delete(self, async_client: AsyncTelnyx) -> None:
        async with async_client.ai.assistants.tests.with_streaming_response.delete(
            "test_id",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            test = await response.parse()
            assert test is None

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip(reason="Prism tests are disabled")
    @parametrize
    async def test_path_params_delete(self, async_client: AsyncTelnyx) -> None:
        with pytest.raises(ValueError, match=r"Expected a non-empty value for `test_id` but received ''"):
            await async_client.ai.assistants.tests.with_raw_response.delete(
                "",
            )
