Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tests/unit/app/endpoints/test_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def test_is_feedback_enabled(mocker: MockerFixture) -> None:
mock_config = AppConfig()
mock_config._configuration = mocker.Mock()
mock_config._configuration.user_data_collection = UserDataCollection(
feedback_enabled=True, feedback_storage="/tmp"
feedback_enabled=True,
feedback_storage="/tmp",
transcripts_enabled=False,
transcripts_storage=None,
)
mocker.patch("app.endpoints.feedback.configuration", mock_config)
assert is_feedback_enabled() is True, "Feedback should be enabled"
Expand All @@ -46,7 +49,10 @@ def test_is_feedback_disabled(mocker: MockerFixture) -> None:
mock_config = AppConfig()
mock_config._configuration = mocker.Mock()
mock_config._configuration.user_data_collection = UserDataCollection(
feedback_enabled=False, feedback_storage=None
feedback_enabled=False,
feedback_storage=None,
transcripts_enabled=False,
transcripts_storage=None,
)
mocker.patch("app.endpoints.feedback.configuration", mock_config)
assert is_feedback_enabled() is False, "Feedback should be disabled"
Expand Down Expand Up @@ -338,7 +344,10 @@ def test_feedback_status_enabled(mocker: MockerFixture) -> None:
mock_config = AppConfig()
mock_config._configuration = mocker.Mock()
mock_config._configuration.user_data_collection = UserDataCollection(
feedback_enabled=True, feedback_storage="/tmp"
feedback_enabled=True,
feedback_storage="/tmp",
transcripts_enabled=False,
transcripts_storage=None,
)
mocker.patch("app.endpoints.feedback.configuration", mock_config)

Expand All @@ -353,7 +362,10 @@ def test_feedback_status_disabled(mocker: MockerFixture) -> None:
mock_config = AppConfig()
mock_config._configuration = mocker.Mock()
mock_config._configuration.user_data_collection = UserDataCollection(
feedback_enabled=False, feedback_storage=None
feedback_enabled=False,
feedback_storage=None,
transcripts_enabled=False,
transcripts_storage=None,
)
mocker.patch("app.endpoints.feedback.configuration", mock_config)

Expand Down Expand Up @@ -384,7 +396,7 @@ async def test_feedback_endpoint_handler_conversation_not_found(
assert exc_info.value.status_code == status.HTTP_404_NOT_FOUND
detail = exc_info.value.detail
assert isinstance(detail, dict)
assert detail["response"] == "Conversation not found"
assert detail["response"] == "Conversation not found" # type: ignore[index]


@pytest.mark.asyncio
Expand Down Expand Up @@ -414,4 +426,4 @@ async def test_feedback_endpoint_handler_conversation_wrong_owner(
assert exc_info.value.status_code == status.HTTP_403_FORBIDDEN
detail = exc_info.value.detail
assert isinstance(detail, dict)
assert "does not have permission" in detail["response"]
assert "does not have permission" in detail["response"] # type: ignore[index]
6 changes: 3 additions & 3 deletions tests/unit/app/endpoints/test_rags.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def test_rags_endpoint_connection_error(
detail = e.value.detail
assert isinstance(detail, dict)
assert "response" in detail
assert "Unable to connect to Llama Stack" in detail["response"]
assert "Unable to connect to Llama Stack" in detail["response"] # type: ignore[index]


@pytest.mark.asyncio
Expand Down Expand Up @@ -158,7 +158,7 @@ async def test_rag_info_endpoint_rag_not_found(
detail = e.value.detail
assert isinstance(detail, dict)
assert "response" in detail
assert "Rag not found" in detail["response"]
assert "Rag not found" in detail["response"] # type: ignore[index]


@pytest.mark.asyncio
Expand Down Expand Up @@ -186,7 +186,7 @@ async def test_rag_info_endpoint_connection_error(
detail = e.value.detail
assert isinstance(detail, dict)
assert "response" in detail
assert "Unable to connect to Llama Stack" in detail["response"]
assert "Unable to connect to Llama Stack" in detail["response"] # type: ignore[index]


@pytest.mark.asyncio
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/app/endpoints/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def test_tools_endpoint_success(
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -192,7 +192,7 @@ async def test_tools_endpoint_no_mcp_servers(mocker: MockerFixture) -> None:
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -228,7 +228,7 @@ async def test_tools_endpoint_api_connection_error(
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -270,7 +270,7 @@ async def test_tools_endpoint_partial_failure( # pylint: disable=redefined-oute
app_config._configuration = mock_configuration
mocker.patch("app.endpoints.tools.configuration", app_config)

mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
mock_client = mocker.AsyncMock()
mock_client_holder.return_value.get_client.return_value = mock_client
Expand Down Expand Up @@ -309,7 +309,7 @@ async def test_tools_endpoint_toolgroup_not_found( # pylint: disable=redefined-
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -365,7 +365,7 @@ async def test_tools_endpoint_builtin_toolgroup(
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -432,7 +432,7 @@ async def test_tools_endpoint_mixed_toolgroups(mocker: MockerFixture) -> None:
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -512,7 +512,7 @@ async def test_tools_endpoint_value_attribute_error(
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -542,7 +542,7 @@ async def test_tools_endpoint_apiconnection_error_toolgroups( # pylint: disable
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder and clien
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -579,7 +579,7 @@ async def test_tools_endpoint_client_holder_apiconnection_error( # pylint: disa
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder to raise APIConnectionError
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down Expand Up @@ -613,7 +613,7 @@ async def test_tools_endpoint_general_exception(
mocker.patch("app.endpoints.tools.configuration", app_config)

# Mock authorization decorator to bypass i
mocker.patch("app.endpoints.tools.authorize", lambda action: lambda func: func)
mocker.patch("app.endpoints.tools.authorize", lambda _: lambda func: func)

# Mock client holder to raise exception
mock_client_holder = mocker.patch("app.endpoints.tools.AsyncLlamaStackClientHolder")
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/authentication/test_api_key_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def test_api_key_with_token_auth_dependency_no_token(
assert exc_info.value.status_code == 401
detail = exc_info.value.detail
assert isinstance(detail, dict)
assert detail["cause"] == "No Authorization header found"
assert detail["cause"] == "No Authorization header found" # type: ignore[index]


async def test_api_key_with_token_auth_dependency_no_bearer(
Expand All @@ -105,7 +105,7 @@ async def test_api_key_with_token_auth_dependency_no_bearer(
assert exc_info.value.status_code == 401
detail = exc_info.value.detail
assert isinstance(detail, dict)
assert detail["cause"] == "No token found in Authorization header"
assert detail["cause"] == "No token found in Authorization header" # type: ignore[index]


async def test_api_key_with_token_auth_dependency_invalid(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/authentication/test_jwk_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def default_jwk_configuration() -> JwkConfiguration:
jwt_configuration=JwtConfiguration(
# Should default to:
# user_id_claim="user_id", username_claim="username"
),
), # pyright: ignore[reportCallIssue]
)


Expand Down
22 changes: 13 additions & 9 deletions tests/unit/cache/test_cache_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def noop_cache_config() -> ConversationHistoryConfiguration:
Returns:
ConversationHistoryConfiguration: configuration instance with `type` set to CACHE_TYPE_NOOP
"""
return ConversationHistoryConfiguration(type=CACHE_TYPE_NOOP)
return ConversationHistoryConfiguration(
type=CACHE_TYPE_NOOP
) # pyright: ignore[reportCallIssue]


@pytest.fixture(scope="module", name="memory_cache_config_fixture")
Expand All @@ -53,7 +55,7 @@ def memory_cache_config() -> ConversationHistoryConfiguration:
"""
return ConversationHistoryConfiguration(
type=CACHE_TYPE_MEMORY, memory=InMemoryCacheConfig(max_entries=10)
)
) # pyright: ignore[reportCallIssue]


@pytest.fixture(scope="module", name="postgres_cache_config_fixture")
Expand All @@ -72,7 +74,7 @@ def postgres_cache_config() -> ConversationHistoryConfiguration:
type=CACHE_TYPE_POSTGRES,
postgres=PostgreSQLDatabaseConfiguration(
db="database", user="user", password=SecretStr("password")
),
), # pyright: ignore[reportCallIssue],
)


Expand All @@ -95,7 +97,7 @@ def sqlite_cache_config(tmpdir: Path) -> ConversationHistoryConfiguration:
db_path = str(tmpdir / "test.sqlite")
return ConversationHistoryConfiguration(
type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path)
)
) # pyright: ignore[reportCallIssue]


@pytest.fixture(scope="module", name="invalid_cache_type_config_fixture")
Expand All @@ -108,7 +110,7 @@ def invalid_cache_type_config() -> ConversationHistoryConfiguration:
Returns:
ConversationHistoryConfiguration: configuration with `type` set to "foo bar baz".
"""
c = ConversationHistoryConfiguration()
c = ConversationHistoryConfiguration() # pyright: ignore[reportCallIssue]
# the conversation cache type name is incorrect in purpose
c.type = "foo bar baz" # pyright: ignore
return c
Expand Down Expand Up @@ -138,7 +140,7 @@ def test_conversation_cache_in_memory_improper_config() -> None:
"""Check if memory cache configuration is checked in cache factory."""
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_MEMORY, memory=InMemoryCacheConfig(max_entries=10)
)
) # pyright: ignore[reportCallIssue]
# simulate improper configuration (can not be done directly as model checks this)
cc.memory = None
with pytest.raises(ValueError, match="Expecting configuration for in-memory cache"):
Expand Down Expand Up @@ -168,7 +170,7 @@ def test_conversation_cache_sqlite_improper_config(tmpdir: Path) -> None:
db_path = str(tmpdir / "test.sqlite")
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_SQLITE, sqlite=SQLiteDatabaseConfiguration(db_path=db_path)
)
) # pyright: ignore[reportCallIssue]
# simulate improper configuration (can not be done directly as model checks this)
cc.sqlite = None
with pytest.raises(ValueError, match="Expecting configuration for SQLite cache"):
Expand Down Expand Up @@ -201,7 +203,7 @@ def test_conversation_cache_postgres_improper_config() -> None:
type=CACHE_TYPE_POSTGRES,
postgres=PostgreSQLDatabaseConfiguration(
db="db", user="u", password=SecretStr("p")
),
), # pyright: ignore[reportCallIssue]
)
# simulate improper configuration (can not be done directly as model checks this)
cc.postgres = None
Expand All @@ -220,7 +222,9 @@ def test_conversation_cache_no_type() -> None:
whose `type` is None raises a ValueError with message "Cache type must be
set".
"""
cc = ConversationHistoryConfiguration(type=CACHE_TYPE_NOOP)
cc = ConversationHistoryConfiguration(
type=CACHE_TYPE_NOOP
) # pyright: ignore[reportCallIssue]
# simulate improper configuration (can not be done directly as model checks this)
cc.type = None
with pytest.raises(ValueError, match="Cache type must be set"):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/cache/test_postgres_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def postgres_cache_config() -> PostgreSQLDatabaseConfiguration:
db="database",
user="user",
password=SecretStr("password"),
)
) # pyright: ignore[reportCallIssue]


@pytest.fixture(scope="module", name="postgres_cache_config_fixture_wrong_namespace")
Expand All @@ -129,7 +129,7 @@ def postgres_cache_config_wrong_namespace() -> PostgreSQLDatabaseConfiguration:
user="user",
password=SecretStr("password"),
namespace="foo bar baz",
)
) # pyright: ignore[reportCallIssue]


@pytest.fixture(scope="module", name="postgres_cache_config_fixture_too_long_namespace")
Expand All @@ -154,7 +154,7 @@ def postgres_cache_config_too_long_namespace() -> PostgreSQLDatabaseConfiguratio
user="user",
password=SecretStr("password"),
namespace="too long namespace that is longer than allowed 63 characters limit",
)
) # pyright: ignore[reportCallIssue]


def test_cache_initialization(
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/models/config/test_authentication_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def test_authentication_configuration_in_config_noop() -> None:
library_client_config_path="tests/configuration/run.yaml",
url="localhost",
api_key=SecretStr(""),
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down Expand Up @@ -347,6 +348,7 @@ def test_authentication_configuration_skip_readiness_probe() -> None:
library_client_config_path="tests/configuration/run.yaml",
url="localhost",
api_key=SecretStr(""),
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down Expand Up @@ -393,6 +395,7 @@ def test_authentication_configuration_in_config_k8s() -> None:
library_client_config_path="tests/configuration/run.yaml",
url="localhost",
api_key=SecretStr(""),
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down Expand Up @@ -449,6 +452,7 @@ def test_authentication_configuration_in_config_rh_identity() -> None:
library_client_config_path="tests/configuration/run.yaml",
url="localhost",
api_key=SecretStr(""),
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down Expand Up @@ -495,6 +499,7 @@ def test_authentication_configuration_in_config_jwktoken() -> None:
library_client_config_path="tests/configuration/run.yaml",
url="localhost",
api_key=SecretStr(""),
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/models/config/test_llama_stack_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def test_llama_stack_configuration_constructor() -> None:
library_client_config_path="tests/configuration/run.yaml",
url=None,
api_key=None,
timeout=60,
)
assert llama_stack_configuration is not None

Expand All @@ -26,6 +27,7 @@ def test_llama_stack_configuration_constructor() -> None:
url="http://localhost",
library_client_config_path=None,
api_key=None,
timeout=60,
)
assert llama_stack_configuration is not None

Expand Down
1 change: 1 addition & 0 deletions tests/unit/models/responses/test_successful_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ def test_constructor(self) -> None:
use_as_library_client=False,
api_key=None,
library_client_config_path=None,
timeout=60,
),
user_data_collection=UserDataCollection(
feedback_enabled=False,
Expand Down
Loading
Loading