How to use dict_put method in localstack

Best Python code snippet using localstack_python

case_generator.py

Source:case_generator.py Github

copy

Full Screen

1import json2from faker import Faker3fake = Faker()4'''5Tool used to generate random parameters and test cases from specified JSON.6Outputs the JSON into output.json.7'''8# input dictionary values for posting9def post_generate(i, body_key, id):10 # template for posting11 dict_post = {12 "url": None,13 "type": "POST",14 "header": {15 None16 },17 "body": {18 },19 "check": {20 "url": None,21 "success_code": "201"22 }23 }24 dict_post['body'][body_key] = {}25 dict_post["url"] = i['url']26 #generate random value for post body27 for x in i['body'][body_key]:28 if (i['body'][body_key][x] == "int"):29 dict_post['body'][body_key][x] = fake.pyint()30 if (i['body'][body_key][x] == "string"):31 dict_post['body'][body_key][x] = fake.pystr()32 dict_post["check"]["url"] = i['url'] + "/" + str(dict_post['body'][body_key][id])33 dict_post["header"] = i["header"]34 return dict_post35# input dictionary values for deletion36def delete_generate(i, body_key, id):37 # template for deletion38 dict_delete = {39 "url": None,40 "type":"DELETE",41 "header" :{42 None43 },44 "check":{45 "url": None,46 "success_code":"200"47 }48 }49 dict_delete["url"] = i['url'] + "/" + str(i['body'][body_key][id])50 dict_delete["check"]["url"] = i['url'] + "/" + str(i['body'][body_key][id])51 #generate random value for put body52 for x in i["header"]:53 if(x != "Content-Type"):54 dict_header = {x: i['header'][x]}55 dict_delete['header'] = dict_header56 return dict_delete57# input dictionary values for updating58def put_generate(i, body_key, id):59 60 #template for updating61 dict_put = {62 "url": None,63 "type": "PUT",64 "header": {65 None66 },67 "body": {68 },69 "check": {70 "url": None,71 "success_code": "200"72 }73 }74 dict_put['body'][body_key] = {}75 dict_put["url"] = i['url'] + "/" + str(i['body'][body_key][id])76 dict_put["check"]["url"] = i['url'] + "/" + str(i['body'][body_key][id])77 for x in i['body'][body_key]:78 if (x != id):79 dict_put['body'][body_key][x] = i['body'][body_key][x]80 dict_put["header"] = i["header"]81 return dict_put82# main function for generating test cases83def run_generation(json_file, id = None, del_option = 0, put_option = 0):84 # Opening JSON file85 f = open(json_file, )86 # returns JSON object as a dictionary87 data = json.load(f)88 add_data = []89 # Iterating through the json90 # list91 body_key = None92 for i in data:93 if('body' in i and i['type'].lower() == "post"):94 # get body key95 for key in i['body'].keys():96 body_key = key97 if ('count' in i):98 count = int(i['count'])99 else:100 count = 1101 #generate post request based on count102 for y in range(0, count):103 #if more than one is generated104 dict_post = post_generate(i, body_key, id)105 add_data.append(dict_post)106 #if put option = 1, generate put cases for post req107 if (put_option == 1 and body_key in i['body']):108 dict_put = put_generate(dict_post, body_key, id)109 add_data.append(dict_put)110 #if option = 1, generate delete cases for post req111 if (del_option == 1 and id in i['body'][body_key]):112 dict_delete = delete_generate(dict_post, body_key, id)113 add_data.append(dict_delete)114 elif(i['type'].lower() == "delete"):115 add_data.append(i)116 elif ('body' in i and i['type'].lower() == "put"):117 # get body key118 for key in i['body'].keys():119 body_key = key120 # generate data for body content based on type given in JSON input121 for x in i['body'][body_key]:122 if (i['body'][body_key][x] == "int"):123 i['body']['contact'][x] = fake.pyint()124 if (i['body'][body_key][x] == "string"):125 i['body'][body_key][x] = fake.pystr()126 add_data.append(i)127 #write converted json into json128 DataFile = open("output.json", "w")129 DataFile.write(json.dumps(add_data, indent=4))130 DataFile.close()...

Full Screen

Full Screen

mappeds_test.py

Source:mappeds_test.py Github

copy

Full Screen

...47 result = E(Funcall(BindingRef('always_none'), [NilConst]))48 assert result == NilConst49def dict_create():50 return {}51def dict_put(d, k, v):52 d[k] = v53def dict_get(d, k):54 return d[k]55def test_mapped_dict_funs(empty_context_eval):56 E = empty_context_eval57 S = StringVal58 E(Assign('dict_create', MappedFunctionVal(dict_create, [])))59 E(Assign('dict_put',60 MappedFunctionVal(dict_put,61 [FunctionParamVal('d'),62 FunctionParamVal('k'),63 FunctionParamVal('v')])))64 E(Assign('dict_get',65 MappedFunctionVal(dict_get,...

Full Screen

Full Screen

taskscheduler621.py

Source:taskscheduler621.py Github

copy

Full Screen

1class Solution:2 def leastInterval(self, tasks: List[str], n: int) -> int:3 frequency_dict = {}4 for task in tasks:5 if task in frequency_dict:6 frequency_dict[task] += 17 else:8 frequency_dict[task] = 19 task_sorted = sorted(frequency_dict, reverse = True,key = lambda x:frequency_dict[x])10 dict_put = defaultdict(list)11 max_i = 012 for task in task_sorted:13 for i in range(frequency_dict[task]):14 15 if len(dict_put[i]) < n+1:16 dict_put[i].append(task)17 max_i = max(max_i,i)18 elif len(dict_put[i]) == n+1:19 while len(dict_put[i])==n+1:20 i+= 121 dict_put[i].append(task)22 max_i =max(max_i, i)23 ...

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