@@ -543,3 +543,48 @@ def test_connection_various_case(self, workspace):
543543 assert workspace .dhis2_connection ("polio-123" ).url == url
544544 assert workspace .dhis2_connection ("Polio-123" ).url == url
545545 assert workspace .dhis2_connection ("POLIO-123" ).url == url
546+
547+ def test_workspace_configuration (self , workspace ):
548+ mock_config = {
549+ "api_url" : "https://api.example.com" ,
550+ "debug_mode" : "true" ,
551+ "database_config" : {"host" : "localhost" , "port" : 5432 },
552+ }
553+
554+ mock_workspace_data = mock .Mock ()
555+ mock_workspace_data .configuration = mock_config
556+
557+ with mock .patch ("openhexa.sdk.workspaces.current_workspace.OpenHexaClient" ) as mock_client :
558+ mock_client .return_value .workspace .return_value = mock_workspace_data
559+ assert workspace .configuration == mock_config
560+
561+ def test_workspace_get_config (self , workspace ):
562+ mock_config = {
563+ "api_url" : "https://api.example.com" ,
564+ "debug_mode" : "true" ,
565+ "database_config" : {"host" : "localhost" , "port" : 5432 },
566+ }
567+
568+ mock_workspace_data = mock .Mock ()
569+ mock_workspace_data .configuration = mock_config
570+
571+ with mock .patch ("openhexa.sdk.workspaces.current_workspace.OpenHexaClient" ) as mock_client :
572+ mock_client .return_value .workspace .return_value = mock_workspace_data
573+
574+ assert workspace .get_config ("api_url" ) == "https://api.example.com"
575+ assert workspace .get_config ("database_config" ) == {"host" : "localhost" , "port" : 5432 }
576+ assert workspace .get_config ("missing_key" , "default_value" ) == "default_value"
577+ assert workspace .get_config ("missing_key" ) is None
578+
579+ def test_workspace_has_config (self , workspace ):
580+ mock_config = {"api_url" : "https://api.example.com" , "debug_mode" : "true" }
581+
582+ mock_workspace_data = mock .Mock ()
583+ mock_workspace_data .configuration = mock_config
584+
585+ with mock .patch ("openhexa.sdk.workspaces.current_workspace.OpenHexaClient" ) as mock_client :
586+ mock_client .return_value .workspace .return_value = mock_workspace_data
587+
588+ assert workspace .has_config ("api_url" ) is True
589+ assert workspace .has_config ("debug_mode" ) is True
590+ assert workspace .has_config ("missing_key" ) is False
0 commit comments