Skip to content

Commit ba5385c

Browse files
committed
fixed integration(mock) tests
1 parent 30b5360 commit ba5385c

6 files changed

Lines changed: 140 additions & 125 deletions

File tree

shells/generic_terraform_service/tests/.env.template.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ CS_USERNAME = ""
77
CS_PASSWORD = ""
88

99
CLP_RESOURSE = ""
10+
CLP_ATTRIBUTES = ""
11+
12+
GITHUB_TOKEN_ENC = ""
13+
GITHUB_TOKEN_DEC = ""
1014

1115
TFEXEC_VERSION = ""
1216
RESERVATION_DOMAIN = ""

shells/generic_terraform_service/tests/integration_tests/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from cloudshell.api.cloudshell_api import ResourceAttribute
2+
13
SHELL_NAME = "Generic Terraform Service"
24
UUID_ATTRIBUTE = f"{SHELL_NAME}.UUID"
35

6+
47
class ATTRIBUTE_NAMES:
58
TF_OUTPUTS = "Terraform Outputs"
69
TF_SENSIITVE_OUTPUTS = "Terraform Sensitive Outputs"

shells/generic_terraform_service/tests/integration_tests/helper_objects/integration_context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,30 @@
77
from cloudshell.shell.core.driver_context import ResourceCommandContext
88

99
from tests.integration_tests.helper_objects.env_vars import EnvVars
10+
from tests.integration_tests.helper_services.service_attributes_factory import ServiceAttributesFactory
1011

1112

1213
class 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+
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
from cloudshell.api.cloudshell_api import NameValuePair
2+
13
from tests.integration_tests.constants import SHELL_NAME, ATTRIBUTE_NAMES
24

35

46
class ServiceAttributesFactory:
5-
def __init__(self):
6-
self.attributes = {}
7-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.REMOTE_STATE_PROVIDER}"] = ""
8-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.BRANCH}"] = ""
9-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.CUSTOM_TAGS}"] = ""
10-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.APPLY_TAGS}"] = ""
11-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.GITHUB_TERRAFORM_MODULE_URL}"] = ""
12-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TERRAFORM_VERSION}"] = ""
13-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.GITHUB_TOKEN}"] = ""
14-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.CLOUD_PROVIDER}"] = ""
15-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.UUID}"] = ""
16-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_OUTPUTS}"] = ""
17-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_SENSIITVE_OUTPUTS}"] = ""
18-
self.attributes[f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_INPUTS}"] = ""
7+
@staticmethod
8+
def create_empty_attributes() -> list[dict]:
9+
attributes = [
10+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.REMOTE_STATE_PROVIDER}", Value=""),
11+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.BRANCH}", Value=""),
12+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.CUSTOM_TAGS}", Value=""),
13+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.APPLY_TAGS}", Value=""),
14+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.GITHUB_TERRAFORM_MODULE_URL}", Value=""),
15+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TERRAFORM_VERSION}", Value=""),
16+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.GITHUB_TOKEN}", Value=""),
17+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.CLOUD_PROVIDER}", Value=""),
18+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.UUID}", Value=""),
19+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_OUTPUTS}", Value=""),
20+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_SENSIITVE_OUTPUTS}", Value=""),
21+
NameValuePair(Name=f"{SHELL_NAME}.{ATTRIBUTE_NAMES.TF_INPUTS}", Value="")
22+
]
23+
return attributes

0 commit comments

Comments
 (0)