Skip to content

Commit

Permalink
Added test for process_validation_error
Browse files Browse the repository at this point in the history
  • Loading branch information
cszsol committed Sep 24, 2024
1 parent e1a5cb7 commit 839a91e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
20 changes: 19 additions & 1 deletion tests/app/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
get_morphology_feature_tool,
get_traces_tool,
get_update_kg_hierarchy,
get_user_id, get_settings, get_connection_string, get_engine, get_session,
get_user_id, get_settings, get_connection_string, get_engine, get_session, get_kg_token,
)
from neuroagent.tools import (
ElectrophysFeatureTool,
Expand Down Expand Up @@ -471,3 +471,21 @@ def test_get_session_success(_):
def test_get_session_no_engine():
with pytest.raises(HTTPException):
next(get_session(None))


def test_get_kg_token_with_token():
settings = Mock()
token = "Test_Token"
result = get_kg_token(settings, token)
assert result == "Test_Token"


def test_get_kg_token_with_settings_knowledge_graph_token():
settings = Mock()
settings.knowledge_graph.use_token = True
settings.knowledge_graph.token.get_secret_value.return_value = "Test_kg_Token"
token = None

result = get_kg_token(settings, token)

assert result == "Test_kg_Token"
24 changes: 22 additions & 2 deletions tests/tools/test_basic_tool.py → tests/tools/test_base_tool.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Literal, Type
from unittest.mock import Mock

import pytest
from langchain_core.language_models.fake_chat_models import FakeMessagesListChatModel
from langchain_core.messages import AIMessage, HumanMessage
from langchain_core.tools import ToolException
from langgraph.prebuilt import create_react_agent
from neuroagent.tools.base_tool import BasicTool
from pydantic import BaseModel
from neuroagent.tools.base_tool import BasicTool, process_validation_error
from pydantic import BaseModel, ValidationError


class input_for_test(BaseModel):
Expand Down Expand Up @@ -103,3 +105,21 @@ def bind_tools(self, functions: list):
'unable to parse string as an integer"}]'
)
assert response["messages"][7].content == "fake answer"


@pytest.mark.parametrize("title, errors, expected", [
("ValidationError", [{"type": "literal_error", "input": "distinct", "loc": ["led"]}],
'[{"Validation error": "Wrong value: provided distinct for input led. Try again and change this problematic input."}]'),
("ValidationError", [{"type": "missing", "loc": ["led"]}],
'[{"Validation error": "Missing input : led. Try again and add this input."}]'),
("ValidationError", [{"type": "other_error", "loc": ["led"], "msg": "This is a test error message"}],
'[{"Validation error": "led. This is a test error message"}]'),
("ValidationError", [{}],
'[{"Validation error": "Error in ValidationError : \'type\'"}]')
])
def test_process_validation_error(title, errors, expected):
error = Mock()
error.title = title
error.errors.return_value = errors
result = process_validation_error(error)
assert result == expected

0 comments on commit 839a91e

Please sign in to comment.