# 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 ali_test_2 import AliTest2, AsyncAliTest2
from tests.utils import assert_matches_type
from ali_test_2.types.api import (
    V2AccessTokensResponse,
    V2RetrieveCategoriesResponse,
    V2RetrieveAppVersionsResponse,
)

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


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

    @pytest.mark.skip()
    @parametrize
    def test_method_access_tokens(self, client: AliTest2) -> None:
        v2 = client.api.v2.access_tokens(
            code="code",
            grant_type="authorizationCode",
        )
        assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_method_access_tokens_with_all_params(self, client: AliTest2) -> None:
        v2 = client.api.v2.access_tokens(
            code="code",
            grant_type="authorizationCode",
            email="email",
            scope="customer",
            transfer_email="transferEmail",
            transfer_order_confirmation="transferOrderConfirmation",
        )
        assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_access_tokens(self, client: AliTest2) -> None:
        response = client.api.v2.with_raw_response.access_tokens(
            code="code",
            grant_type="authorizationCode",
        )

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

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_access_tokens(self, client: AliTest2) -> None:
        with client.api.v2.with_streaming_response.access_tokens(
            code="code",
            grant_type="authorizationCode",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = response.parse()
            assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    def test_method_login(self, client: AliTest2) -> None:
        v2 = client.api.v2.login(
            email="dev@stainless.com",
        )
        assert v2 is None

    @pytest.mark.skip()
    @parametrize
    def test_method_login_with_all_params(self, client: AliTest2) -> None:
        v2 = client.api.v2.login(
            email="dev@stainless.com",
            source="CUSTOMER_SUPPORT_CHAT",
        )
        assert v2 is None

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_login(self, client: AliTest2) -> None:
        response = client.api.v2.with_raw_response.login(
            email="dev@stainless.com",
        )

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

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_login(self, client: AliTest2) -> None:
        with client.api.v2.with_streaming_response.login(
            email="dev@stainless.com",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = response.parse()
            assert v2 is None

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    def test_method_retrieve_app_versions(self, client: AliTest2) -> None:
        v2 = client.api.v2.retrieve_app_versions()
        assert_matches_type(V2RetrieveAppVersionsResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_retrieve_app_versions(self, client: AliTest2) -> None:
        response = client.api.v2.with_raw_response.retrieve_app_versions()

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

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_retrieve_app_versions(self, client: AliTest2) -> None:
        with client.api.v2.with_streaming_response.retrieve_app_versions() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = response.parse()
            assert_matches_type(V2RetrieveAppVersionsResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    def test_method_retrieve_categories(self, client: AliTest2) -> None:
        v2 = client.api.v2.retrieve_categories()
        assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_method_retrieve_categories_with_all_params(self, client: AliTest2) -> None:
        v2 = client.api.v2.retrieve_categories(
            name="name",
            type="PRIMARY",
        )
        assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    def test_raw_response_retrieve_categories(self, client: AliTest2) -> None:
        response = client.api.v2.with_raw_response.retrieve_categories()

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

    @pytest.mark.skip()
    @parametrize
    def test_streaming_response_retrieve_categories(self, client: AliTest2) -> None:
        with client.api.v2.with_streaming_response.retrieve_categories() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = response.parse()
            assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True


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

    @pytest.mark.skip()
    @parametrize
    async def test_method_access_tokens(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.access_tokens(
            code="code",
            grant_type="authorizationCode",
        )
        assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_method_access_tokens_with_all_params(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.access_tokens(
            code="code",
            grant_type="authorizationCode",
            email="email",
            scope="customer",
            transfer_email="transferEmail",
            transfer_order_confirmation="transferOrderConfirmation",
        )
        assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_access_tokens(self, async_client: AsyncAliTest2) -> None:
        response = await async_client.api.v2.with_raw_response.access_tokens(
            code="code",
            grant_type="authorizationCode",
        )

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

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_access_tokens(self, async_client: AsyncAliTest2) -> None:
        async with async_client.api.v2.with_streaming_response.access_tokens(
            code="code",
            grant_type="authorizationCode",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = await response.parse()
            assert_matches_type(V2AccessTokensResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    async def test_method_login(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.login(
            email="dev@stainless.com",
        )
        assert v2 is None

    @pytest.mark.skip()
    @parametrize
    async def test_method_login_with_all_params(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.login(
            email="dev@stainless.com",
            source="CUSTOMER_SUPPORT_CHAT",
        )
        assert v2 is None

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_login(self, async_client: AsyncAliTest2) -> None:
        response = await async_client.api.v2.with_raw_response.login(
            email="dev@stainless.com",
        )

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

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_login(self, async_client: AsyncAliTest2) -> None:
        async with async_client.api.v2.with_streaming_response.login(
            email="dev@stainless.com",
        ) as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

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

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    async def test_method_retrieve_app_versions(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.retrieve_app_versions()
        assert_matches_type(V2RetrieveAppVersionsResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_retrieve_app_versions(self, async_client: AsyncAliTest2) -> None:
        response = await async_client.api.v2.with_raw_response.retrieve_app_versions()

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

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_retrieve_app_versions(self, async_client: AsyncAliTest2) -> None:
        async with async_client.api.v2.with_streaming_response.retrieve_app_versions() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = await response.parse()
            assert_matches_type(V2RetrieveAppVersionsResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True

    @pytest.mark.skip()
    @parametrize
    async def test_method_retrieve_categories(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.retrieve_categories()
        assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_method_retrieve_categories_with_all_params(self, async_client: AsyncAliTest2) -> None:
        v2 = await async_client.api.v2.retrieve_categories(
            name="name",
            type="PRIMARY",
        )
        assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

    @pytest.mark.skip()
    @parametrize
    async def test_raw_response_retrieve_categories(self, async_client: AsyncAliTest2) -> None:
        response = await async_client.api.v2.with_raw_response.retrieve_categories()

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

    @pytest.mark.skip()
    @parametrize
    async def test_streaming_response_retrieve_categories(self, async_client: AsyncAliTest2) -> None:
        async with async_client.api.v2.with_streaming_response.retrieve_categories() as response:
            assert not response.is_closed
            assert response.http_request.headers.get("X-Stainless-Lang") == "python"

            v2 = await response.parse()
            assert_matches_type(V2RetrieveCategoriesResponse, v2, path=["response"])

        assert cast(Any, response.is_closed) is True
