-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored app_ports_operation to move the get custom params method t…
…o a domain service
- Loading branch information
Showing
5 changed files
with
53 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
package/cloudshell/cp/aws/domain/services/model_parser/custom_param_extractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class VmCustomParamsExtractor(object): | ||
def __init__(self): | ||
pass | ||
|
||
def get_custom_param_value(self, custom_params, name): | ||
""" | ||
Returns the value of the requested custom param | ||
:param custom_params: The VMCustomParams array that is created by the DeployDataHolder from the deployed app json | ||
:param str name: the name of the custom param to extract | ||
:return: the value of the custom param or None if custom param not found | ||
:rtype str: | ||
""" | ||
name = name.lower() | ||
params = filter(lambda x: x.name.lower() == name, custom_params) | ||
if len(params) == 1: | ||
return params[0].value | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
package/tests/test_domain_services/test_vm_custom_params_extractor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from unittest import TestCase | ||
|
||
import jsonpickle | ||
from cloudshell.cp.aws.common.deploy_data_holder import DeployDataHolder | ||
from cloudshell.cp.aws.domain.services.model_parser.custom_param_extractor import VmCustomParamsExtractor | ||
|
||
|
||
class TestVmCustomParamsExtractor(TestCase): | ||
def setUp(self): | ||
pass | ||
|
||
def test_extracor(self): | ||
json_str = '{"vmCustomParams":[{"name": "param", "value": "some_value"}]}' | ||
dict = jsonpickle.decode(json_str) | ||
vmdetails = DeployDataHolder(dict) | ||
|
||
extracotr = VmCustomParamsExtractor() | ||
param_value = extracotr.get_custom_param_value(vmdetails.vmCustomParams, "param") | ||
|
||
self.assertEqual(param_value, "some_value") | ||
|
||
|