From d41798f192525e97b2115c42c8af3f1c0393dfaa Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 18 Oct 2023 19:56:49 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(test=5Fstore.py):=20add=20test?= =?UTF-8?q?=20for=20search=5Fcomponents=20function=20in=20StoreService=20c?= =?UTF-8?q?lass?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test covers the search_components function in the StoreService class. It mocks the response from the HTTP GET request and asserts that the request was made with the correct parameters. It also asserts that the search method returns a list of ComponentResponse objects. --- tests/test_store.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/test_store.py diff --git a/tests/test_store.py b/tests/test_store.py new file mode 100644 index 000000000..3302c8950 --- /dev/null +++ b/tests/test_store.py @@ -0,0 +1,58 @@ +# FILEPATH: /Users/ogabrielluiz/Projects/langflow2/tests/test_store_service.py + +from datetime import datetime +from unittest.mock import patch, Mock + +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 ComponentResponse + from langflow.services.store.service import StoreService + + 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": "likes", + }, + ) + + # Assert that the search method returns a list of ComponentResponse objects + assert len(components) == 2 + assert all(isinstance(component, ComponentResponse) for component in components)