How to use _test_parameter method in avocado

Best Python code snippet using avocado_python

Sub.py

Source:Sub.py Github

copy

Full Screen

...17 matches = []18 string_params = cfn.get_sub_parameters(sub_string)19 for string_param in string_params:20 if isinstance(string_param, (str)):21 matches.extend(self._test_parameter(string_param, cfn, parameters, tree))22 return matches23 def _get_parameters(self, cfn):24 """Get all Parameter Names"""25 results = {}26 parameters = cfn.template.get('Parameters', {})27 if isinstance(parameters, dict):28 for param_name, param_values in parameters.items():29 # This rule isn't here to check the Types but we need30 # something valid if it doesn't exist31 if isinstance(param_values, dict):32 results[param_name] = param_values.get('Type', 'String')33 return results34 def _test_parameters(self, parameters, cfn, tree):35 """Check parameters for appropriate configuration"""36 supported_functions = [37 'Fn::Base64',38 'Fn::FindInMap',39 'Fn::GetAZs',40 'Fn::GetAtt',41 'Fn::If',42 'Fn::ImportValue',43 'Fn::Join',44 'Fn::Select',45 'Fn::Sub',46 'Ref',47 ]48 matches = []49 for parameter_name, parameter_value_obj in parameters.items():50 param_tree = tree[:] + [parameter_name]51 if isinstance(parameter_value_obj, dict):52 if len(parameter_value_obj) == 1:53 for key, value in parameter_value_obj.items():54 if key not in supported_functions:55 message = 'Sub parameter should use a valid function for {0}'56 matches.append(RuleMatch(57 param_tree, message.format('/'.join(map(str, tree)))))58 elif key in ['Ref']:59 matches.extend(self._test_parameter(value, cfn, {}, tree))60 elif key in ['Fn::GetAtt']:61 if isinstance(value, list):62 # Only test this if all the items are a string63 if_all_strings = True64 for v in value:65 if not isinstance(v, str):66 # skip things got too complex67 if_all_strings = False68 if if_all_strings:69 matches.extend(self._test_parameter(70 '.'.join(value), cfn, {}, tree))71 elif isinstance(value, str):72 matches.extend(self._test_parameter(value, cfn, {}, tree))73 else:74 message = 'Sub parameter should be an object of 1 for {0}'75 matches.append(RuleMatch(76 param_tree, message.format('/'.join(map(str, tree)))))77 elif isinstance(parameter_value_obj, list):78 message = 'Sub parameter value should be a string for {0}'79 matches.append(RuleMatch(80 param_tree, message.format('/'.join(map(str, tree)))))81 return matches82 def _test_parameter(self, parameter, cfn, parameters, tree):83 """ Test a parameter """84 matches = []85 get_atts = cfn.get_valid_getatts()86 valid_params = list(PSEUDOPARAMS)87 valid_params.extend(cfn.get_resource_names())88 template_parameters = self._get_parameters(cfn)89 for key, _ in parameters.items():90 valid_params.append(key)91 if parameter not in valid_params:92 found = False93 if parameter in template_parameters:94 found = True95 if template_parameters.get(parameter) in VALID_PARAMETER_TYPES_LIST:96 message = 'Fn::Sub cannot use list {0} at {1}'...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful