diff --git a/tests/unit/auth/test_noop_with_token.py b/tests/unit/auth/test_noop_with_token.py index 784bdf03..0ed460b2 100644 --- a/tests/unit/auth/test_noop_with_token.py +++ b/tests/unit/auth/test_noop_with_token.py @@ -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" @@ -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" diff --git a/tests/unit/auth/test_utils.py b/tests/unit/auth/test_utils.py index f5301914..68fa847d 100644 --- a/tests/unit/auth/test_utils.py +++ b/tests/unit/auth/test_utils.py @@ -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(): diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 773b108e..97b1e555 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py index 55f6892b..cd097e94 100644 --- a/tests/unit/test_configuration.py +++ b/tests/unit/test_configuration.py @@ -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": { @@ -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 @@ -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 @@ -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(): @@ -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(): @@ -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(): @@ -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(): @@ -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 @@ -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