1515 POSTGRES_DEFAULT_GSS_ENCMODE ,
1616)
1717
18+ from utils .checks import InvalidConfigurationError
19+
1820from models .config import (
1921 AuthenticationConfiguration ,
2022 Configuration ,
2729 ModelContextProtocolServer ,
2830 InferenceConfiguration ,
2931 PostgreSQLDatabaseConfiguration ,
32+ SQLiteDatabaseConfiguration ,
33+ DatabaseConfiguration ,
3034)
3135
32- from utils .checks import InvalidConfigurationError
33-
3436
3537def test_service_configuration_constructor () -> None :
3638 """
@@ -503,9 +505,10 @@ def test_configuration_multiple_mcp_servers() -> None:
503505
504506def test_dump_configuration (tmp_path ) -> None :
505507 """
506- Test that the Configuration object can be serialized to a JSON
507- file and that the resulting file contains all expected sections
508- and values.
508+ Test that the Configuration object can be serialized to a JSON file and
509+ that the resulting file contains all expected sections and values.
510+
511+ Please note that redaction process is not in place.
509512 """
510513 cfg = Configuration (
511514 name = "test_name" ,
@@ -525,6 +528,7 @@ def test_dump_configuration(tmp_path) -> None:
525528 llama_stack = LlamaStackConfiguration (
526529 use_as_library_client = True ,
527530 library_client_config_path = "tests/configuration/run.yaml" ,
531+ api_key = "whatever" ,
528532 ),
529533 user_data_collection = UserDataCollection (
530534 feedback_enabled = False , feedback_storage = None
@@ -593,7 +597,7 @@ def test_dump_configuration(tmp_path) -> None:
593597 },
594598 "llama_stack" : {
595599 "url" : None ,
596- "api_key" : None ,
600+ "api_key" : "whatever" ,
597601 "use_as_library_client" : True ,
598602 "library_client_config_path" : "tests/configuration/run.yaml" ,
599603 },
@@ -874,6 +878,60 @@ def test_authentication_configuration_module_unsupported() -> None:
874878 )
875879
876880
881+ def test_database_configuration (subtests ) -> None :
882+ """Test the database configuration handling."""
883+ with subtests .test (msg = "PostgreSQL" ):
884+ d1 = PostgreSQLDatabaseConfiguration (
885+ db = "db" ,
886+ user = "user" ,
887+ password = "password" ,
888+ port = 1234 ,
889+ ca_cert_path = Path ("tests/configuration/server.crt" ),
890+ )
891+ d = DatabaseConfiguration (postgres = d1 )
892+ assert d is not None
893+ assert d .sqlite is None
894+ assert d .postgres is not None
895+ assert d .db_type == "postgres"
896+
897+ with subtests .test (msg = "SQLite" ):
898+ d1 = SQLiteDatabaseConfiguration (
899+ db_path = "/tmp/foo/bar/baz" ,
900+ )
901+ d = DatabaseConfiguration (sqlite = d1 )
902+ assert d is not None
903+ assert d .sqlite is not None
904+ assert d .postgres is None
905+ assert d .db_type == "sqlite"
906+
907+
908+ def test_no_databases_configuration () -> None :
909+ """Test if no databases configuration is checked."""
910+ d = DatabaseConfiguration ()
911+ assert d is not None
912+
913+ # default should be SQLite when nothing is provided
914+ assert d .db_type == "sqlite"
915+
916+ # simulate no DB configuration
917+ d .sqlite = None
918+ d .postgres = None
919+
920+ with pytest .raises (ValueError , match = "No database configuration found" ):
921+ # access propery to call it's getter
922+ _ = d .db_type
923+
924+
925+ def test_two_databases_configuration () -> None :
926+ """Test if two databases configuration is checked."""
927+ d1 = PostgreSQLDatabaseConfiguration (db = "db" , user = "user" , password = "password" )
928+ d2 = SQLiteDatabaseConfiguration (db_path = "foo_bar_baz" )
929+ with pytest .raises (
930+ ValidationError , match = "Only one database configuration can be provided"
931+ ):
932+ DatabaseConfiguration (postgres = d1 , sqlite = d2 )
933+
934+
877935def test_postgresql_database_configuration () -> None :
878936 """Test the PostgreSQLDatabaseConfiguration model."""
879937 c = PostgreSQLDatabaseConfiguration (db = "db" , user = "user" , password = "password" )
0 commit comments