From f3d866f0b6a5dea6db264fc8aa43d6eba53b55ef Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 5 Sep 2023 09:34:57 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(test=5Fendpoints.py):=20fix?= =?UTF-8?q?=20import=20statements=20and=20add=20missing=20import=20for=20c?= =?UTF-8?q?rud=20module=20=E2=9C=A8=20feat(test=5Fendpoints.py):=20add=20m?= =?UTF-8?q?ock=20function=20for=20update=5Ftotal=5Fuses=20to=20fix=20test?= =?UTF-8?q?=5Fprocess=5Fflow=5Finvalid=5Fapi=5Fkey=20=E2=9C=A8=20feat(test?= =?UTF-8?q?=5Fendpoints.py):=20add=20mock=20function=20for=20update=5Ftota?= =?UTF-8?q?l=5Fuses=20to=20fix=20test=5Fprocess=5Fflow=5Fwithout=5Fautolog?= =?UTF-8?q?in=20=E2=9C=A8=20feat(test=5Fendpoints.py):=20add=20mock=20func?= =?UTF-8?q?tion=20for=20update=5Ftotal=5Fuses=20to=20fix=20test=5Fprocess?= =?UTF-8?q?=5Fflow=5Ffails=5Fautologin=5Foff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_endpoints.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index e48393bed..376de6f4e 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -106,14 +106,20 @@ def created_api_key(session, active_user): def test_process_flow_invalid_api_key(client, flow, monkeypatch): # Mock de process_graph_cached - async def mock_process_graph_cached(*args, **kwargs): - return Result(result={}, session_id="session_id_mock") + from langflow.api.v1 import endpoints + from langflow.services.database.models.api_key import crud settings_manager = get_settings_manager() settings_manager.auth_settings.AUTO_LOGIN = False - from langflow.api.v1 import endpoints + + async def mock_process_graph_cached(*args, **kwargs): + return Result(result={}, session_id="session_id_mock") + + def mock_update_total_uses(*args, **kwargs): + return created_api_key monkeypatch.setattr(endpoints, "process_graph_cached", mock_process_graph_cached) + monkeypatch.setattr(crud, "update_total_uses", mock_update_total_uses) headers = {"x-api-key": "invalid_api_key"} @@ -160,6 +166,7 @@ def test_process_flow_invalid_id(client, monkeypatch, created_api_key): def test_process_flow_without_autologin(client, flow, monkeypatch, created_api_key): # Mock de process_graph_cached from langflow.api.v1 import endpoints + from langflow.services.database.models.api_key import crud settings_manager = get_settings_manager() settings_manager.auth_settings.AUTO_LOGIN = False @@ -167,7 +174,11 @@ def test_process_flow_without_autologin(client, flow, monkeypatch, created_api_k async def mock_process_graph_cached(*args, **kwargs): return Result(result={}, session_id="session_id_mock") + def mock_update_total_uses(*args, **kwargs): + return created_api_key + monkeypatch.setattr(endpoints, "process_graph_cached", mock_process_graph_cached) + monkeypatch.setattr(crud, "update_total_uses", mock_update_total_uses) api_key = created_api_key.api_key headers = {"x-api-key": api_key} @@ -193,6 +204,7 @@ def test_process_flow_without_autologin(client, flow, monkeypatch, created_api_k def test_process_flow_fails_autologin_off(client, flow, monkeypatch): # Mock de process_graph_cached from langflow.api.v1 import endpoints + from langflow.services.database.models.api_key import crud settings_manager = get_settings_manager() settings_manager.auth_settings.AUTO_LOGIN = False @@ -200,7 +212,11 @@ def test_process_flow_fails_autologin_off(client, flow, monkeypatch): async def mock_process_graph_cached(*args, **kwargs): return Result(result={}, session_id="session_id_mock") + async def mock_update_total_uses(*args, **kwargs): + return created_api_key + monkeypatch.setattr(endpoints, "process_graph_cached", mock_process_graph_cached) + monkeypatch.setattr(crud, "update_total_uses", mock_update_total_uses) headers = {"x-api-key": "api_key"}