chore: refactor and add components integration tests (#3607)

* improve inegration tests

* add fixes

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Nicolò Boschi 2024-09-02 15:21:47 +02:00 • committed by GitHub
commit 96872f3aa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 523 additions and 131 deletions

View file

@ -0,0 +1,45 @@
from langflow.components.outputs import ChatOutput
from langflow.memory import get_messages
from langflow.schema.message import Message
from tests.integration.utils import run_single_component
import pytest
@pytest.mark.asyncio
async def test_string():
outputs = await run_single_component(ChatOutput, inputs={"input_value": "hello"})
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert outputs["message"].sender == "Machine"
assert outputs["message"].sender_name == "AI"
@pytest.mark.asyncio
async def test_message():
outputs = await run_single_component(ChatOutput, inputs={"input_value": Message(text="hello")})
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert outputs["message"].sender == "Machine"
assert outputs["message"].sender_name == "AI"
@pytest.mark.asyncio
async def test_do_not_store_message():
session_id = "test-session-id"
outputs = await run_single_component(
ChatOutput, inputs={"input_value": "hello", "should_store_message": True}, session_id=session_id
)
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert len(get_messages(session_id=session_id)) == 1
session_id = "test-session-id-another"
outputs = await run_single_component(
ChatOutput, inputs={"input_value": "hello", "should_store_message": False}, session_id=session_id
)
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert len(get_messages(session_id=session_id)) == 0