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,55 @@
from langflow.memory import get_messages
from langflow.schema.message import Message
from tests.integration.utils import run_single_component
from langflow.components.inputs import ChatInput
import pytest
@pytest.mark.asyncio
async def test_default():
outputs = await run_single_component(ChatInput, run_input="hello")
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert outputs["message"].sender == "User"
assert outputs["message"].sender_name == "User"
outputs = await run_single_component(ChatInput, run_input="")
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == ""
assert outputs["message"].sender == "User"
assert outputs["message"].sender_name == "User"
@pytest.mark.asyncio
async def test_sender():
outputs = await run_single_component(
ChatInput, inputs={"sender": "Machine", "sender_name": "AI"}, run_input="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_messages():
session_id = "test-session-id"
outputs = await run_single_component(
ChatInput, inputs={"should_store_message": True}, run_input="hello", session_id=session_id
)
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert outputs["message"].session_id == session_id
assert len(get_messages(session_id=session_id)) == 1
session_id = "test-session-id-another"
outputs = await run_single_component(
ChatInput, inputs={"should_store_message": False}, run_input="hello", session_id=session_id
)
assert isinstance(outputs["message"], Message)
assert outputs["message"].text == "hello"
assert outputs["message"].session_id == session_id
assert len(get_messages(session_id=session_id)) == 0