Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for AmazonBedrockComponent component #6620

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
from langflow.components.models import AmazonBedrockComponent

from tests.base import ComponentTestBaseWithClient


@pytest.mark.usefixtures("client")
class TestAmazonBedrockComponent(ComponentTestBaseWithClient):
@pytest.fixture
def component_class(self):
return AmazonBedrockComponent

@pytest.fixture
def default_kwargs(self):
return {
"model_id": "anthropic.claude-3-haiku-20240307-v1:0",
"aws_access_key_id": "AWS_ACCESS_KEY_ID",
"aws_secret_access_key": "AWS_SECRET_ACCESS_KEY",
"region_name": "us-east-1",
"model_kwargs": {},
"endpoint_url": "https://example.com",
}

@pytest.fixture
def file_names_mapping(self):
return [
{"version": "1.0.0", "module": "aws", "file_name": "AmazonBedrock"},
]

async def test_build_model_success(self, component_class, default_kwargs):
component = component_class(**default_kwargs)
model = await component.build_model()
assert model is not None

async def test_build_model_missing_dependencies(self, component_class, default_kwargs):
with pytest.raises(ImportError, match="langchain_aws is not installed"):
component = component_class(**default_kwargs)
component.build_model()

Check failure on line 38 in src/backend/tests/unit/components/models/test_amazon_bedrock_component.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PT012)

src/backend/tests/unit/components/models/test_amazon_bedrock_component.py:36:9: PT012 `pytest.raises()` block should contain a single simple statement

with pytest.raises(ImportError, match="boto3 is not installed"):
component = component_class(**default_kwargs)
component.build_model()

Check failure on line 42 in src/backend/tests/unit/components/models/test_amazon_bedrock_component.py

View workflow job for this annotation

GitHub Actions / Ruff Style Check (3.12)

Ruff (PT012)

src/backend/tests/unit/components/models/test_amazon_bedrock_component.py:40:9: PT012 `pytest.raises()` block should contain a single simple statement

async def test_build_model_invalid_credentials(self, component_class, default_kwargs):
default_kwargs["aws_access_key_id"] = None
default_kwargs["aws_secret_access_key"] = None
component = component_class(**default_kwargs)
with pytest.raises(ValueError, match="Could not create a boto3 session."):
await component.build_model()

async def test_build_model_connection_error(self, component_class, default_kwargs):
default_kwargs["endpoint_url"] = "invalid_url"
component = component_class(**default_kwargs)
with pytest.raises(ValueError, match="Could not connect to AmazonBedrock API."):
await component.build_model()
Loading