From c6dfb90bcfcc15acbee6220029864aaf3d7e4efd Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 21 Nov 2023 14:45:02 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(flows.py):=20remove=20unused?= =?UTF-8?q?=20imports=20and=20fix=20function=20call=20to=20read=5Fflows=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(test=5Fdatabase.py):=20fix=20function=20call?= =?UTF-8?q?=20to=20Flow.model=5Fvalidate=20=F0=9F=90=9B=20fix(test=5Fllms?= =?UTF-8?q?=5Ftemplate.py):=20fix=20values=20in=20test=20cases=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(test=5Fstore.py):=20remove=20unused=20test?= =?UTF-8?q?=20file=20and=20test=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/flows.py | 14 +++---- tests/test_database.py | 2 +- tests/test_llms_template.py | 4 +- tests/test_store.py | 57 ---------------------------- 4 files changed, 9 insertions(+), 68 deletions(-) delete mode 100644 tests/test_store.py diff --git a/src/backend/langflow/api/v1/flows.py b/src/backend/langflow/api/v1/flows.py index c3f894732..5e4dde4e0 100644 --- a/src/backend/langflow/api/v1/flows.py +++ b/src/backend/langflow/api/v1/flows.py @@ -1,6 +1,10 @@ from typing import List from uuid import UUID + +import orjson +from fastapi import APIRouter, Depends, File, HTTPException, UploadFile from fastapi.encoders import jsonable_encoder +from sqlmodel import Session from langflow.api.utils import remove_api_keys from langflow.api.v1.schemas import FlowListCreate, FlowListRead @@ -12,13 +16,7 @@ from langflow.services.database.models.flow import ( FlowUpdate, ) from langflow.services.database.models.user.user import User -from langflow.services.deps import get_session -from langflow.services.deps import get_settings_service -import orjson -from sqlmodel import Session -from fastapi import APIRouter, Depends, HTTPException - -from fastapi import File, UploadFile +from langflow.services.deps import get_session, get_settings_service # build router router = APIRouter(prefix="/flows", tags=["Flows"]) @@ -163,5 +161,5 @@ async def download_file( current_user: User = Depends(get_current_active_user), ): """Download all flows as a file.""" - flows = read_flows(session=session, current_user=current_user) + flows = read_flows(current_user=current_user) return FlowListRead(flows=flows) diff --git a/tests/test_database.py b/tests/test_database.py index abbe20c81..369e2a0f6 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -182,7 +182,7 @@ def test_download_file( with session_getter(db_manager) as session: for flow in flow_list.flows: flow.user_id = active_user.id - db_flow = Flow.from_orm(flow) + db_flow = Flow.model_validate(flow) session.add(db_flow) session.commit() # Make request to endpoint diff --git a/tests/test_llms_template.py b/tests/test_llms_template.py index 78131cb05..e66c8c650 100644 --- a/tests/test_llms_template.py +++ b/tests/test_llms_template.py @@ -243,7 +243,7 @@ def test_openai(client: TestClient, logged_in_headers): "placeholder": "", "show": False, "multiline": False, - "value": 6, + "value": 2, "password": False, "name": "max_retries", "type": "int", @@ -385,7 +385,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers): "placeholder": "", "show": False, "multiline": False, - "value": 6, + "value": 2, "password": False, "name": "max_retries", "type": "int", diff --git a/tests/test_store.py b/tests/test_store.py deleted file mode 100644 index d139537fa..000000000 --- a/tests/test_store.py +++ /dev/null @@ -1,57 +0,0 @@ -# FILEPATH: /Users/ogabrielluiz/Projects/langflow2/tests/test_store_service.py - -from datetime import datetime -from unittest.mock import Mock, patch - -from langflow.services.deps import get_store_service - - -@patch("langflow.services.store.service.httpx") -def test_search_components(mock_httpx: Mock, client): - # Mock the response from the HTTP GET request - from langflow.services.store.schema import CreateComponentResponse - - mock_response = Mock() - mock_response.json.return_value = { - "data": [ - { - "id": "1", - "name": "Test Component 1", - "description": "This is a test component.", - "tags": ["test"], - "status": "published", - "date_updated": datetime.now().isoformat(), - "is_component": False, - }, - { - "id": "2", - "name": "Test Component 2", - "description": "This is another test component.", - "tags": ["test"], - "status": "published", - "date_updated": datetime.now().isoformat(), - "is_component": True, - }, - ] - } - mock_httpx.get.return_value = mock_response - - # Create an instance of the StoreService class and call the search method - store_service = get_store_service() - components = store_service.search(api_key=None, query="test", limit=5) - - # Assert that the HTTP GET request was made with the correct parameters - mock_httpx.get.assert_called_once_with( - store_service.components_url, - headers={}, - params={ - "filter[name][_like]": "test", - "page": 1, - "limit": 5, - "sort": "count(liked_by)", - }, - ) - - # Assert that the search method returns a list of ComponentResponse objects - assert len(components) == 2 - assert all(isinstance(component, CreateComponentResponse) for component in components)