def test_step_condition(self): step = MockedStep() step.sentence = 'Given I do this' self.assertEqual(step_condition(step), 'given') step.sentence = 'When I do this' self.assertEqual(step_condition(step), 'when') step.sentence = 'Then I do this' self.assertEqual(step_condition(step), 'then')
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)