77from cloudshell .shell .core .driver_context import ResourceCommandContext
88
99from tests .integration_tests .helper_objects .env_vars import EnvVars
10+ from tests .integration_tests .helper_services .service_attributes_factory import ServiceAttributesFactory
1011
1112
1213class IntegrationData (object ):
13- def __init__ (self , service_name : str , real_api : bool = True , mocked_attributes : list [ AttributeValueInfo ] = None ):
14+ def __init__ (self , service_name : str , is_api_real : bool = True , mock_api : Mock = None ):
1415 self ._env_vars = EnvVars (service_name )
1516
16- if real_api :
17+ if is_api_real :
1718 self .api = CloudShellAPISession (
1819 self ._env_vars .cs_server ,
1920 self ._env_vars .cs_user ,
2021 self ._env_vars .cs_pass ,
2122 self ._env_vars .cs_domain
2223 )
23- self ._set_context (real_api )
24- self ._logger = get_qs_logger (log_group = self .context .resource .name )
25- self .create_tf_shell ()
2624
2725 else :
28- self .api = Mock ()
26+ self .api = mock_api
2927 self .api .authentication .xmlrpc_token = Mock ()
30- self ._set_context (real_api )
31- self ._logger = get_qs_logger (log_group = self .context .resource .name )
28+ self ._set_context (is_api_real )
29+ self ._logger = get_qs_logger (log_group = self .context .resource .name )
30+ self .create_tf_shell ()
3231
33- self ._set_context (real_api , mocked_attributes )
3432
35- def _set_context (self , real_api : bool , mocked_attributes : list [ AttributeValueInfo ] = None ):
33+ def _set_context (self , is_api_real : bool ):
3634 self .context = mock .create_autospec (ResourceCommandContext )
3735 self .context .connectivity = mock .MagicMock ()
3836 self .context .connectivity .server_address = self ._env_vars .cs_server
@@ -42,9 +40,10 @@ def _set_context(self, real_api: bool, mocked_attributes: list[AttributeValueInf
4240 self .context .resource .attributes = dict ()
4341 self .context .resource .name = self ._env_vars .sb_service_alias
4442 self .context .resource .model = 'Generic Terraform Service'
45- if real_api :
43+ if is_api_real :
4644 self .set_context_resource_attributes_from_cs ()
47-
45+ else :
46+ self .context .resource .attributes = ServiceAttributesFactory .create_empty_attributes ()
4847 self .context .reservation = mock .MagicMock ()
4948 self .context .reservation .reservation_id = self ._env_vars .cs_res_id
5049 self .context .reservation .domain = self ._env_vars .cs_domain
@@ -64,3 +63,4 @@ def set_context_resource_attributes_from_cs(self, the_only_attribute_to_update:
6463 def create_tf_shell (self ):
6564 self ._config = TerraformShellConfig (write_sandbox_messages = True , update_live_status = True )
6665 self .tf_shell = TerraformShell (self .context , self ._logger , self ._config )
66+
0 commit comments