|
| 1 | +"""Integration tests for IntegrationResource.""" |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from deepset_mcp.api.client import AsyncDeepsetClient |
| 8 | +from deepset_mcp.api.integrations.models import IntegrationProvider |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.asyncio |
| 12 | +@pytest.mark.integration |
| 13 | +class TestIntegrationResourceIntegration: |
| 14 | + """Integration tests for IntegrationResource. |
| 15 | +
|
| 16 | + These tests run against the actual deepset API and require: |
| 17 | + - DEEPSET_API_KEY environment variable to be set |
| 18 | + - Valid API access |
| 19 | + """ |
| 20 | + |
| 21 | + @pytest.fixture(autouse=True) |
| 22 | + def check_api_key(self) -> None: |
| 23 | + """Ensure API key is available for integration tests.""" |
| 24 | + if not os.environ.get("DEEPSET_API_KEY"): |
| 25 | + pytest.skip("DEEPSET_API_KEY not set, skipping integration tests") |
| 26 | + |
| 27 | + async def test_list_integrations_real_api(self) -> None: |
| 28 | + """Test listing integrations against real API.""" |
| 29 | + async with AsyncDeepsetClient() as client: |
| 30 | + # Act |
| 31 | + result = await client.integrations().list() |
| 32 | + |
| 33 | + # Assert |
| 34 | + # We can't assert specific content since it depends on the account configuration |
| 35 | + # but we can verify the structure is correct |
| 36 | + assert hasattr(result, "integrations") |
| 37 | + assert isinstance(result.integrations, list) |
| 38 | + |
| 39 | + # If there are integrations, verify their structure |
| 40 | + for integration in result.integrations: |
| 41 | + assert hasattr(integration, "invalid") |
| 42 | + assert hasattr(integration, "model_registry_token_id") |
| 43 | + assert hasattr(integration, "provider") |
| 44 | + assert hasattr(integration, "provider_domain") |
| 45 | + assert isinstance(integration.invalid, bool) |
| 46 | + assert isinstance(integration.provider, IntegrationProvider) |
| 47 | + assert isinstance(integration.provider_domain, str) |
| 48 | + |
| 49 | + async def test_get_integration_real_api(self) -> None: |
| 50 | + """Test getting a specific integration against real API. |
| 51 | +
|
| 52 | + This test attempts to get an AWS Bedrock integration. |
| 53 | + If it doesn't exist, the test will expect a 404 error. |
| 54 | + """ |
| 55 | + async with AsyncDeepsetClient() as client: |
| 56 | + try: |
| 57 | + # Act |
| 58 | + result = await client.integrations().get(IntegrationProvider.AWS_BEDROCK) |
| 59 | + |
| 60 | + # Assert - if we get a result, verify its structure |
| 61 | + assert hasattr(result, "invalid") |
| 62 | + assert hasattr(result, "model_registry_token_id") |
| 63 | + assert hasattr(result, "provider") |
| 64 | + assert hasattr(result, "provider_domain") |
| 65 | + assert isinstance(result.invalid, bool) |
| 66 | + assert result.provider == IntegrationProvider.AWS_BEDROCK |
| 67 | + assert isinstance(result.provider_domain, str) |
| 68 | + |
| 69 | + except Exception as e: |
| 70 | + # If the integration doesn't exist, we expect a 404-like error |
| 71 | + # The exact error type depends on the API implementation |
| 72 | + # This is acceptable for integration tests |
| 73 | + assert "404" in str(e) or "not found" in str(e).lower() or "Not Found" in str(e) |
0 commit comments