def its_property_contains_key(step, property, key, resourcelist=TerraformResourceList): if step.context.stash.__class__ is resourcelist: number_of_resources = len(step.context.stash.resource_list) step.context.stash = step.context.stash.find_property( property).find_property(key) if step.context.stash: if len(step.context.stash.properties) > 0: if number_of_resources > len(step.context.stash.properties): write_stdout( level='INFO', message= 'Some of the resources does not have {} property defined within.\n' 'Removed {} resource (out of {}) from the test scope.\n\n' .format( property, (number_of_resources - len(step.context.stash.properties)), number_of_resources, )) else: skip_step( step, resource=str(property) + " with key " + str(key), message='Can not find {resource} property in any resource.' ) else: skip_step( step, resource=str(property) + " with key " + str(key), message='Can not find {resource} property in any resource.') else: skip_step(step)
def it_condition_contain_something(step_obj, something, propertylist=TerraformPropertyList, resourcelist=TerraformResourceList): if something in resource_name.keys(): something = resource_name[something] step_can_skip = step_condition(step_obj) in ["given", "when"] if step_obj.context.stash.__class__ is propertylist: for prop in step_obj.context.stash.properties: value = parse_hcl_value(prop.property_value, world.config.terraform.terraform_config) if value is not None: assert (value == something or something.lower() in value), \ '{} property in {} can not be found in {} ({}). It is set to {} instead'.format(something, prop.property_name, prop.resource_name, prop.resource_type, value) else: write_stdout( level='WARNING', message='Can not get value of {} in {}/{}. ' 'Might be set by an unknown source (module, etc. )\n' 'Value : {}'.format(something, prop.property_name, prop.resource_type, prop.property_value)) step_obj.state = 'skipped' elif step_obj.context.stash.__class__ is resourcelist: if step_can_skip is False: step_obj.context.stash.should_have_properties(something) step_obj.context.stash = step_obj.context.stash.find_property( something) assert step_obj.context.stash.properties, \ 'No defined property/value found for {}.'.format(something) step_obj.context.stash = step_obj.context.stash.properties else: try: step_obj.context.stash.should_have_properties(something) number_of_resources = len(step_obj.context.stash.resource_list) step_obj.context.stash = step_obj.context.stash.find_property( something) if step_obj.context.stash: if number_of_resources > len( step_obj.context.stash.properties): write_stdout( level='INFO', message= 'Some of the resources does not have {} property defined within.\n' 'Removed {} resource (out of {}) from the test scope.\n' '\n'.format( something, (number_of_resources - len(step_obj.context.stash.properties)), number_of_resources, )) except Exception as e: number_of_resources = len(step_obj.context.stash.resource_list) step_obj.context.stash = step_obj.context.stash.find_property( something) if step_obj.context.stash: write_stdout( level='INFO', message= 'Some of the resources does not have {} property defined within.\n' 'Removed {} resource (out of {}) from the test scope.\n\n' 'Due to : \n' '{}'.format(something, (number_of_resources - len(step_obj.context.stash.properties)), number_of_resources, str(e))) else: skip_step( step_obj, resource=something, message= 'Can not find {resource} property in any resource.') elif step_obj.context.stash.__class__ is dict: if something in step_obj.context.stash: step_obj.context.stash = step_obj.context.stash[something] else: if step_can_skip: skip_step( step_obj, resource=something, message= 'Can not find {resource} resource in terraform files.') else: assert False, '{} does not exist.'.format(something)
def test_write_stdout(self): self.assertEqual(None, write_stdout('info', 'test'))