How to use recurse_object method in localstack

Best Python code snippet using localstack_python

substitutions.py

Source:substitutions.py Github

copy

Full Screen

...6 primary_resource_dict = primary_resource.dict()7 for prop in template_step.properties:8 val = prop.value9 if isinstance(prop.value, dict):10 val = recurse_object(prop.value, primary_resource_dict)11 if prop.type == 'array':12 if prop.name in resource_to_update.properties:13 existing_arr = resource_to_update.properties[prop.name]14 else:15 existing_arr = []16 if prop.arraySubstitutionAction == 'overwrite':17 existing_arr = [val]18 if prop.arraySubstitutionAction == 'append':19 existing_arr.append(val)20 if prop.arraySubstitutionAction == 'remove':21 item_index = find_item_index(existing_arr, prop.arrayMatchField, val)22 if item_index > -1:23 del existing_arr[item_index]24 if prop.arraySubstitutionAction == 'replace':25 item_index = find_item_index(existing_arr, prop.arrayMatchField, val)26 if item_index > -1:27 existing_arr[item_index] = val28 else:29 existing_arr.append(val)30 properties[prop.name] = existing_arr31 else:32 properties[prop.name] = val33 else:34 val = substitute_value(val, primary_resource_dict)35 properties[prop.name] = val36 return properties37def find_item_index(array: list, arrayMatchField: str, val: dict) -> int:38 for i in range(0, len(array)):39 if array[i][arrayMatchField] == val[arrayMatchField]:40 return i41 return -142def recurse_object(obj: dict, primary_resource_dict: dict) -> dict:43 for prop in obj:44 if isinstance(obj[prop], list):45 for i in range(0, len(obj[prop])):46 if isinstance(obj[prop][i], list) or isinstance(obj[prop][i], dict):47 obj[prop][i] = recurse_object(obj[prop][i], primary_resource_dict)48 else:49 obj[prop][i] = substitute_value(obj[prop][i], primary_resource_dict)50 if isinstance(obj[prop], dict):51 obj[prop] = recurse_object(obj[prop], primary_resource_dict)52 else:53 obj[prop] = substitute_value(obj[prop], primary_resource_dict)54 return obj55def substitute_value(val: str, primary_resource_dict: dict) -> Union[dict, list, str]:56 if "{{" not in val:57 return val58 val = val.replace("{{ ", "{{").replace(" }}", "}}")59 # if the value being substituted in is a simple type, we can return it in the string, to allow for concatenation60 # like "This was deployed by {{ resource.id }}"61 # else if the value being injected in is a dict/list - we shouldn't try to concatenate that, we'll return the true value and drop any surrounding text62 # extract the tokens to replace63 tokens = []64 parts = val.split("{{")65 for p in parts:...

Full Screen

Full Screen

core.py

Source:core.py Github

copy

Full Screen

...33 "open_api": open_api34 }35 open_api.info.description36 on_start.notify_observers(cap_statement, context)37 recurse_object(cap_statement)38 on_end.notify_observers(cap_statement, context)39# events40on_start = Observable()41on_key_value = Observable()42on_value = Observable()43on_increased_depth = Observable()44on_end = Observable()45class CapabilityStatementObserver(Observer):46 @staticmethod47 def discriminator(self, event, context):48 return context["parent"] == "" and context["fhir"]["resourceType"] == "CapabilityStatement"49 def action(self, event, context):50 pass51CapabilityStatementObserver(on_start)52def recurse_object(obj, context):53 on_increased_depth.notify_observers({"value": obj}, context)54 if isinstance(obj, dict):55 for k, v in obj.items():56 if isinstance(v, dict) or isinstance(v, list):57 recurse_object(v, context)58 else:59 on_key_value.notify_observers({"key": k, "value": v}, context)60 else:61 for v in obj:62 if isinstance(v, dict) or isinstance(v, list):63 recurse_object(v, context)64 else:65 on_value.notify_observers({"value": v}, context)66def trigger():67 pass68def update_context():69 pass70"""71Loop through,72Process values,73Save dicts and arrays for end.74"""...

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 localstack 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