langflow/tests/test_initial_setup.py
Gabriel Luiz Freitas Almeida c7f5e4f843
Fix lint and tests (#1959)
* refactor(chat.py): rename flow_id variable to flow_id_str for better clarity
refactor(chat.py): update flow_id usage to flow_id_str in build_vertex function for consistency
refactor(chat.py): change flow_id to flow_id_str in build_vertex function for consistency
refactor(chat.py): replace flow_id with flow_id_str in build_vertex function for consistency
refactor(chat.py): update flow_id to flow_id_str in build_vertex_stream function for consistency
refactor(chat.py): change flow_id to flow_id_str in build_vertex_stream function for consistency
refactor(chat.py): replace flow_id with flow_id_str in build_vertex_stream function for consistency
refactor(chat.py): update flow_id to flow_id_str in build_vertex_stream function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): update flow_id to flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): change flow_id to flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): update flow_id to flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): change flow_id to flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): update flow_id to flow_id_str in simplified_run_flow function for consistency
refactor(endpoints.py): change flow_id to flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): update flow_id to flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): change flow_id to flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): update flow_id to flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): change flow_id to flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): replace flow_id with flow_id_str in experimental_run_flow function for consistency
refactor(endpoints.py): update flow_id

fix(files.py): update variable names from flow_id to flow_id_str for consistency
feat(files.py): use flow_id_str instead of flow_id for file operations to ensure correct folder paths
feat(files.py): improve error handling and response messages in file operations
feat(flows.py): optimize query for fetching example flows
feat(folders.py): refactor create_folder function for better readability and maintainability
feat(folders.py): update_folder function to handle excluded_flows and concat_folder_components
feat(folders.py): improve error handling and response messages in folder operations
feat(folders.py): optimize query for fetching folder in download_file function
feat(schemas.py): update FlowListReadWithFolderName schema field names to name and description

feat(OpenAIConversationalAgent.py): add support for using pydantic SecretStr for storing API key securely
feat(ChatOpenAISpecs.py): add support for using pydantic SecretStr for storing API key securely
refactor(RecordsOutput.py): change base class from TextComponent to CustomComponent
refactor(base.py): remove unused import and log_transaction call
refactor(model.py): change components and flows fields to have default_factory=list
refactor(utils.py): update SQLModel import and use Field for components and flows fields
refactor(service.py): change table_map declaration to use type hints for better readability

* feat(tests): add import statement for Folder model in conftest.py to support new functionality
refactor(tests): update query in conftest.py to use nested query for Folder name
refactor(tests): update import statement for UUID in test_endpoints.py
refactor(tests): update UUID usage in test_endpoints.py for consistency and clarity
refactor(tests): update UUID usage in test_endpoints.py for consistency and clarity
refactor(tests): update UUID usage in test_endpoints.py for consistency and clarity
refactor(tests): update UUID usage in test_endpoints.py for consistency and clarity
feat(tests): add import statement for Folder model in test_initial_setup.py to support new functionality
refactor(tests): update query in test_initial_setup.py to use Folder model for better readability and maintainability

* new lock
2024-05-23 07:55:06 -07:00

93 lines
3.6 KiB
Python

from datetime import datetime
from pathlib import Path
from sqlmodel import select
from langflow.initial_setup.setup import (
STARTER_FOLDER_NAME,
create_or_update_starter_projects,
get_project_data,
load_starter_projects,
)
from langflow.services.database.models.folder.model import Folder
from langflow.services.deps import session_scope
def test_load_starter_projects():
projects = load_starter_projects()
assert isinstance(projects, list)
assert all(isinstance(project[1], dict) for project in projects)
assert all(isinstance(project[0], Path) for project in projects)
def test_get_project_data():
projects = load_starter_projects()
for _, project in projects:
(
project_name,
project_description,
project_is_component,
updated_at_datetime,
project_data,
project_icon,
project_icon_bg_color,
) = get_project_data(project)
assert isinstance(project_name, str)
assert isinstance(project_description, str)
assert isinstance(project_is_component, bool)
assert isinstance(updated_at_datetime, datetime)
assert isinstance(project_data, dict)
assert isinstance(project_icon, str) or project_icon is None
assert isinstance(project_icon_bg_color, str) or project_icon_bg_color is None
def test_create_or_update_starter_projects(client):
with session_scope() as session:
# Run the function to create or update projects
create_or_update_starter_projects()
# Get the number of projects returned by load_starter_projects
num_projects = len(load_starter_projects())
# Get the number of projects in the database
folder = session.exec(select(Folder).where(Folder.name == STARTER_FOLDER_NAME)).first()
num_db_projects = len(folder.flows)
# Check that the number of projects in the database is the same as the number of projects returned by load_starter_projects
assert num_db_projects == num_projects
# Some starter projects require integration
# @pytest.mark.asyncio
# async def test_starter_projects_can_run_successfully(client):
# with session_scope() as session:
# # Run the function to create or update projects
# create_or_update_starter_projects()
# # Get the number of projects returned by load_starter_projects
# num_projects = len(load_starter_projects())
# # Get the number of projects in the database
# num_db_projects = session.exec(select(func.count(Flow.id)).where(Flow.folder == STARTER_FOLDER_NAME)).one()
# # Check that the number of projects in the database is the same as the number of projects returned by load_starter_projects
# assert num_db_projects == num_projects
# # Get all the starter projects
# projects = session.exec(select(Flow).where(Flow.folder == STARTER_FOLDER_NAME)).all()
# graphs: list[tuple[str, Graph]] = []
# for project in projects:
# # Add tweaks to make file_path work
# tweaks = {"path": __file__}
# graph_data = process_tweaks(project.data, tweaks)
# graph_object = Graph.from_payload(graph_data, flow_id=project.id)
# graphs.append((project.name, graph_object))
# assert len(graphs) == len(projects)
# for name, graph in graphs:
# outputs = await graph.arun(
# inputs={},
# outputs=[],
# session_id="test",
# )
# assert all(isinstance(output, RunOutputs) for output in outputs), f"Project {name} error: {outputs}"
# delete_messages(session_id="test")