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
4 changes: 2 additions & 2 deletions tests/unit/auth/test_noop_with_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def test_noop_with_token_auth_dependency_no_token():

# Assert that an HTTPException is raised when no Authorization header is found
with pytest.raises(HTTPException) as exc_info:
user_id, username, user_token = await dependency(request)
await dependency(request)

assert exc_info.value.status_code == 400
assert exc_info.value.detail == "No Authorization header found"
Expand All @@ -90,7 +90,7 @@ async def test_noop_with_token_auth_dependency_no_bearer():

# Assert that an HTTPException is raised when no Authorization header is found
with pytest.raises(HTTPException) as exc_info:
user_id, username, user_token = await dependency(request)
await dependency(request)

assert exc_info.value.status_code == 400
assert exc_info.value.detail == "No token found in Authorization header"
2 changes: 1 addition & 1 deletion tests/unit/auth/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Unit tests for functions defined in auth/utils.py"""

from auth.utils import extract_user_token
from fastapi import HTTPException
from auth.utils import extract_user_token


def test_extract_user_token():
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from models.config import LLamaStackConfiguration


# [tisnik] Need to resolve dependencies on CI to be able to run this tests
def test_get_llama_stack_library_client() -> None:
"""Test if Llama Stack can be initialized in library client mode."""
cfg = LLamaStackConfiguration(
url=None,
api_key=None,
Expand All @@ -20,6 +20,7 @@ def test_get_llama_stack_library_client() -> None:


def test_get_llama_stack_remote_client() -> None:
"""Test if Llama Stack can be initialized in remove client (server) mode."""
cfg = LLamaStackConfiguration(
url="http://localhost:8321",
api_key=None,
Expand All @@ -32,6 +33,7 @@ def test_get_llama_stack_remote_client() -> None:


def test_get_llama_stack_wrong_configuration() -> None:
"""Test if configuration is checked before Llama Stack is initialized."""
cfg = LLamaStackConfiguration(
url=None,
api_key=None,
Expand All @@ -48,6 +50,7 @@ def test_get_llama_stack_wrong_configuration() -> None:


async def test_get_async_llama_stack_library_client() -> None:
"""Test the initialization of asynchronous Llama Stack client in library mode."""
cfg = LLamaStackConfiguration(
url=None,
api_key=None,
Expand All @@ -60,6 +63,7 @@ async def test_get_async_llama_stack_library_client() -> None:


async def test_get_async_llama_stack_remote_client() -> None:
"""Test the initialization of asynchronous Llama Stack client in server mode."""
cfg = LLamaStackConfiguration(
url="http://localhost:8321",
api_key=None,
Expand All @@ -72,6 +76,7 @@ async def test_get_async_llama_stack_remote_client() -> None:


async def test_get_async_llama_stack_wrong_configuration() -> None:
"""Test if configuration is checked before Llama Stack is initialized."""
cfg = LLamaStackConfiguration(
url=None,
api_key=None,
Expand Down
64 changes: 51 additions & 13 deletions tests/unit/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,49 @@


def test_default_configuration() -> None:
"""Test that configuration attributes are not accessible for uninitialized app."""
cfg = AppConfig()
assert cfg is not None

# configuration is not loaded
with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.configuration
cfg.configuration # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.llama_stack_configuration
cfg.service_configuration # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.user_data_collection_configuration
cfg.llama_stack_configuration # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.user_data_collection_configuration # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.mcp_servers # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.authentication_configuration # pylint: disable=pointless-statement

with pytest.raises(Exception, match="logic error: configuration is not loaded"):
# try to read property
cfg.customization # pylint: disable=pointless-statement


def test_configuration_is_singleton() -> None:
"""Test that configuration is singleton."""
cfg1 = AppConfig()
cfg2 = AppConfig()
assert cfg1 == cfg2


def test_init_from_dict() -> None:
"""Test the configuration initialization from dictionary with config values."""
config_dict = {
"name": "foo",
"service": {
Expand Down Expand Up @@ -126,8 +145,9 @@ def test_init_from_dict_with_mcp_servers() -> None:


def test_load_proper_configuration(tmpdir) -> None:
"""Test loading proper configuration from YAML file."""
cfg_filename = tmpdir / "config.yaml"
with open(cfg_filename, "w") as fout:
with open(cfg_filename, "w", encoding="utf-8") as fout:
fout.write(
"""
name: foo bar baz
Expand Down Expand Up @@ -159,7 +179,7 @@ def test_load_proper_configuration(tmpdir) -> None:
def test_load_configuration_with_mcp_servers(tmpdir) -> None:
"""Test loading configuration from YAML file with MCP servers."""
cfg_filename = tmpdir / "config.yaml"
with open(cfg_filename, "w") as fout:
with open(cfg_filename, "w", encoding="utf-8") as fout:
fout.write(
"""
name: test service
Expand Down Expand Up @@ -273,7 +293,7 @@ def test_configuration_not_loaded():
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.configuration
cfg.configuration # pylint: disable=pointless-statement


def test_service_configuration_not_loaded():
Expand All @@ -282,7 +302,7 @@ def test_service_configuration_not_loaded():
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.service_configuration
cfg.service_configuration # pylint: disable=pointless-statement


def test_llama_stack_configuration_not_loaded():
Expand All @@ -291,7 +311,7 @@ def test_llama_stack_configuration_not_loaded():
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.llama_stack_configuration
cfg.llama_stack_configuration # pylint: disable=pointless-statement


def test_user_data_collection_configuration_not_loaded():
Expand All @@ -300,7 +320,7 @@ def test_user_data_collection_configuration_not_loaded():
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.user_data_collection_configuration
cfg.user_data_collection_configuration # pylint: disable=pointless-statement


def test_mcp_servers_not_loaded():
Expand All @@ -309,17 +329,35 @@ def test_mcp_servers_not_loaded():
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.mcp_servers
cfg.mcp_servers # pylint: disable=pointless-statement


def test_authentication_configuration_not_loaded():
"""Test that accessing authentication_configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.authentication_configuration # pylint: disable=pointless-statement


def test_customization_not_loaded():
"""Test that accessing customization before loading raises an error."""
cfg = AppConfig()
with pytest.raises(
AssertionError, match="logic error: configuration is not loaded"
):
cfg.customization # pylint: disable=pointless-statement


def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> None:
"""Test loading configuration from YAML file with customization."""
system_prompt_filename = tmpdir / "system_prompt.txt"
with open(system_prompt_filename, "w") as fout:
with open(system_prompt_filename, "w", encoding="utf-8") as fout:
fout.write("this is system prompt")

cfg_filename = tmpdir / "config.yaml"
with open(cfg_filename, "w") as fout:
with open(cfg_filename, "w", encoding="utf-8") as fout:
fout.write(
f"""
name: test service
Expand Down Expand Up @@ -359,7 +397,7 @@ def test_load_configuration_with_customization_system_prompt_path(tmpdir) -> Non
def test_load_configuration_with_customization_system_prompt(tmpdir) -> None:
"""Test loading configuration from YAML file with system_prompt in the customization."""
cfg_filename = tmpdir / "config.yaml"
with open(cfg_filename, "w") as fout:
with open(cfg_filename, "w", encoding="utf-8") as fout:
fout.write(
"""
name: test service
Expand Down