# This file is auto-generated by oagen. Do not edit.


import pytest

from tests.generated_helpers import load_fixture
from workos import AsyncWorkOSClient, WorkOSClient
from workos._errors import (
    AuthenticationError,
    BadRequestError,
    NotFoundError,
    RateLimitExceededError,
    ServerError,
    UnprocessableEntityError,
)
from workos.pipes_provider.models import (
    DataIntegrationConfigurationListResponse,
    DataIntegrationConfigurationResponse,
)


class TestPipesProvider:
    def test_list_organization_data_integration_configurations(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_list_response.json"),
        )
        result = (
            workos.pipes_provider.list_organization_data_integration_configurations(
                "test_organizationId"
            )
        )
        assert isinstance(result, DataIntegrationConfigurationListResponse)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/organizations/test_organizationId/data_integration_configurations"
        )

    def test_update_organization_data_integration_configuration(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_response.json"),
        )
        result = (
            workos.pipes_provider.update_organization_data_integration_configuration(
                "test_organizationId", "test_slug"
            )
        )
        assert isinstance(result, DataIntegrationConfigurationResponse)
        assert result.object == "data_integration_configuration"
        assert result.id == "data_integration_01EHZNVPK3SFK441A1RGBFSHRT"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/organizations/test_organizationId/data_integration_configurations/test_slug"
        )

    def test_list_organization_data_integration_configurations_with_request_options(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_list_response.json")
        )
        workos.pipes_provider.list_organization_data_integration_configurations(
            "test_organizationId",
            request_options={"extra_headers": {"X-Custom": "value"}},
        )
        request = httpx_mock.get_request()
        assert request.headers["X-Custom"] == "value"

    def test_list_organization_data_integration_configurations_unauthorized(
        self, workos, httpx_mock
    ):
        httpx_mock.add_response(
            status_code=401,
            json={"message": "Unauthorized"},
        )
        with pytest.raises(AuthenticationError):
            workos.pipes_provider.list_organization_data_integration_configurations(
                "test_organizationId"
            )

    def test_list_organization_data_integration_configurations_not_found(
        self, httpx_mock
    ):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=404, json={"message": "Not found"})
            with pytest.raises(NotFoundError):
                workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            workos.close()

    def test_list_organization_data_integration_configurations_rate_limited(
        self, httpx_mock
    ):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(
                status_code=429,
                headers={"Retry-After": "0"},
                json={"message": "Slow down"},
            )
            with pytest.raises(RateLimitExceededError):
                workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            workos.close()

    def test_list_organization_data_integration_configurations_server_error(
        self, httpx_mock
    ):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=500, json={"message": "Server error"})
            with pytest.raises(ServerError):
                workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            workos.close()

    def test_list_organization_data_integration_configurations_bad_request(
        self, httpx_mock
    ):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=400, json={"message": "Bad request"})
            with pytest.raises(BadRequestError):
                workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            workos.close()

    def test_list_organization_data_integration_configurations_unprocessable(
        self, httpx_mock
    ):
        workos = WorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=422, json={"message": "Unprocessable"})
            with pytest.raises(UnprocessableEntityError):
                workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            workos.close()


class TestAsyncPipesProvider:
    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_list_response.json")
        )
        result = await async_workos.pipes_provider.list_organization_data_integration_configurations(
            "test_organizationId"
        )
        assert isinstance(result, DataIntegrationConfigurationListResponse)
        assert result.object == "list"
        request = httpx_mock.get_request()
        assert request.method == "GET"
        assert request.url.path.endswith(
            "/organizations/test_organizationId/data_integration_configurations"
        )

    @pytest.mark.asyncio
    async def test_update_organization_data_integration_configuration(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_response.json")
        )
        result = await async_workos.pipes_provider.update_organization_data_integration_configuration(
            "test_organizationId", "test_slug"
        )
        assert isinstance(result, DataIntegrationConfigurationResponse)
        assert result.object == "data_integration_configuration"
        assert result.id == "data_integration_01EHZNVPK3SFK441A1RGBFSHRT"
        request = httpx_mock.get_request()
        assert request.method == "PUT"
        assert request.url.path.endswith(
            "/organizations/test_organizationId/data_integration_configurations/test_slug"
        )

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_with_request_options(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(
            json=load_fixture("data_integration_configuration_list_response.json")
        )
        await async_workos.pipes_provider.list_organization_data_integration_configurations(
            "test_organizationId",
            request_options={"extra_headers": {"X-Custom": "value"}},
        )
        request = httpx_mock.get_request()
        assert request.headers["X-Custom"] == "value"

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_unauthorized(
        self, async_workos, httpx_mock
    ):
        httpx_mock.add_response(status_code=401, json={"message": "Unauthorized"})
        with pytest.raises(AuthenticationError):
            await async_workos.pipes_provider.list_organization_data_integration_configurations(
                "test_organizationId"
            )

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_not_found(
        self, httpx_mock
    ):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=404, json={"message": "Not found"})
            with pytest.raises(NotFoundError):
                await workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_rate_limited(
        self, httpx_mock
    ):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(
                status_code=429,
                headers={"Retry-After": "0"},
                json={"message": "Slow down"},
            )
            with pytest.raises(RateLimitExceededError):
                await workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_server_error(
        self, httpx_mock
    ):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=500, json={"message": "Server error"})
            with pytest.raises(ServerError):
                await workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_bad_request(
        self, httpx_mock
    ):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=400, json={"message": "Bad request"})
            with pytest.raises(BadRequestError):
                await workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            await workos.close()

    @pytest.mark.asyncio
    async def test_list_organization_data_integration_configurations_unprocessable(
        self, httpx_mock
    ):
        workos = AsyncWorkOSClient(
            api_key="sk_test_123", client_id="client_test", max_retries=0
        )
        try:
            httpx_mock.add_response(status_code=422, json={"message": "Unprocessable"})
            with pytest.raises(UnprocessableEntityError):
                await workos.pipes_provider.list_organization_data_integration_configurations(
                    "test_organizationId"
                )
        finally:
            await workos.close()
