📝 (tests/conftest.py): Remove duplicate imports and organize imports for better readability

♻️ (tests/test_custom_component.py): Refactor CustomComponent to Component for better naming consistency
♻️ (tests/test_endpoints.py): Refactor test functions to improve readability and maintainability by simplifying assertions and organizing code
This commit is contained in:
ogabrielluiz 2024-06-04 09:25:27 -03:00
commit e4f4401d75
3 changed files with 23 additions and 16 deletions

View file

@ -4,6 +4,7 @@ from uuid import UUID, uuid4
import pytest
from fastapi import status
from fastapi.testclient import TestClient
from langflow.custom.directory_reader.directory_reader import DirectoryReader
from langflow.services.deps import get_settings_service
@ -445,9 +446,10 @@ def test_successful_run_no_payload(client, starter_project, created_api_key):
assert all(["ChatOutput" in _id for _id in ids])
display_names = [output.get("component_display_name") for output in outputs_dict.get("outputs")]
assert all([name in display_names for name in ["Chat Output"]])
inner_results = [output.get("results").get("result") for output in outputs_dict.get("outputs")]
output_results_has_results = all("results" in output.get("results") for output in outputs_dict.get("outputs"))
inner_results = [output.get("results") for output in outputs_dict.get("outputs")]
assert all([result is not None for result in inner_results]), inner_results
assert all([result is not None for result in inner_results]), (outputs_dict, output_results_has_results)
def test_successful_run_with_output_type_text(client, starter_project, created_api_key):
@ -475,9 +477,9 @@ def test_successful_run_with_output_type_text(client, starter_project, created_a
assert all(["ChatOutput" in _id for _id in ids]), ids
display_names = [output.get("component_display_name") for output in outputs_dict.get("outputs")]
assert all([name in display_names for name in ["Chat Output"]]), display_names
inner_results = [output.get("results").get("result") for output in outputs_dict.get("outputs")]
expected_result = ""
assert all([expected_result in result for result in inner_results]), inner_results
inner_results = [output.get("results") for output in outputs_dict.get("outputs")]
expected_keys = ["Record", "Message"]
assert all([key in result for result in inner_results for key in expected_keys]), outputs_dict
def test_successful_run_with_output_type_any(client, starter_project, created_api_key):
@ -506,9 +508,9 @@ def test_successful_run_with_output_type_any(client, starter_project, created_ap
assert all(["ChatOutput" in _id or "TextOutput" in _id for _id in ids]), ids
display_names = [output.get("component_display_name") for output in outputs_dict.get("outputs")]
assert all([name in display_names for name in ["Chat Output"]]), display_names
inner_results = [output.get("results").get("result") for output in outputs_dict.get("outputs")]
expected_result = ""
assert all([expected_result in result for result in inner_results]), inner_results
inner_results = [output.get("results") for output in outputs_dict.get("outputs")]
expected_keys = ["Record", "Message"]
assert all([key in result for result in inner_results for key in expected_keys]), outputs_dict
def test_successful_run_with_output_type_debug(client, starter_project, created_api_key):
@ -564,7 +566,7 @@ def test_successful_run_with_input_type_text(client, starter_project, created_ap
text_input_outputs = [output for output in outputs_dict.get("outputs") if "TextInput" in output.get("component_id")]
assert len(text_input_outputs) == 0
# Now we check if the input_value is correct
assert all([output.get("results").get("result") == "value1" for output in text_input_outputs]), text_input_outputs
assert all([output.get("results") == "value1" for output in text_input_outputs]), text_input_outputs
# Now do the same for "chat" input type
@ -595,7 +597,9 @@ def test_successful_run_with_input_type_chat(client, starter_project, created_ap
chat_input_outputs = [output for output in outputs_dict.get("outputs") if "ChatInput" in output.get("component_id")]
assert len(chat_input_outputs) == 1
# Now we check if the input_value is correct
assert all([output.get("results").get("result") == "value1" for output in chat_input_outputs]), chat_input_outputs
assert all(
[output.get("results").get("Message").get("result") == "value1" for output in chat_input_outputs]
), chat_input_outputs
def test_successful_run_with_input_type_any(client, starter_project, created_api_key):
@ -629,7 +633,9 @@ def test_successful_run_with_input_type_any(client, starter_project, created_api
]
assert len(any_input_outputs) == 1
# Now we check if the input_value is correct
assert all([output.get("results").get("result") == "value1" for output in any_input_outputs]), any_input_outputs
assert all(
[output.get("results").get("Message").get("result") == "value1" for output in any_input_outputs]
), any_input_outputs
def test_run_with_inputs_and_outputs(client, starter_project, created_api_key):