Best Python code snippet using lisa_python
custom.py
Source:custom.py
...14 if name not in added:15 added[name] = database_model(name=name, model=model)16 return added17LocationTuple = namedtuple('Location', ['region', 'zone', 'facies', 'case_id'])18def _get_location_info(data_dict, case_id):19 return LocationTuple(20 region=data_dict.get('faultblock', None),21 zone=data_dict.get('zone', None),22 facies=data_dict.get('facies', None),23 case_id=case_id)24def _add_locations(data_dicts, case):25 added = {}26 for data_dict in data_dicts:27 location_key = _get_location_info(data_dict, case_id=case.id)28 if location_key not in added:29 added[location_key] = Location(30 facies_name=location_key.facies,31 zone_name=location_key.zone,32 region_name=location_key.region,33 license='Custom license',34 case=case)35 return added36RealizationTuple = namedtuple('Realization', ['location_id', 'realization', 'iteration'])37def _get_realization_key(data_dict, locations, case):38 location_key = _get_location_info(data_dict, case_id=case.id)39 location_id = locations[location_key].id40 return RealizationTuple(41 location_id=location_id,42 realization=data_dict.get('realization'),43 iteration=data_dict.get('iteration', 1),44 )45def _add_realizations(data_dicts, locations, case):46 added = {}47 for data_dict in data_dicts:48 realization_key = _get_realization_key(data_dict, locations=locations, case=case)49 if realization_key not in added:50 added[realization_key] = Realization(51 realization=realization_key.realization,52 iteration=realization_key.iteration,...
main.py
Source:main.py
...18 if not r.ok:19 raise RuntimeError(f"Response not ok: {r}")20 appointments = [Appointment.parse_obj(_) for _ in r.json()]21 return appointments22def _get_location_info(location_code: int):23 url = urljoin(24 base=settings.CBP_BASE_URL,25 url="/schedulerapi/locations/?temporary=false&inviteOnly=false&operational=true&serviceName=Global%20Entry",26 )27 with requests.Session() as s:28 r = s.get(url)29 if not r.ok:30 raise RuntimeError(f"Response not ok: {r}")31 data = r.json()32 location_data = [_ for _ in data if int(_["id"]) == location_code][0]33 return location_data34def main():35 appointments = _check_for_appointments(settings.INTERVIEW_LOCATION_ID)36 if not appointments:37 log.info("No appointments found")38 return39 log.info("Found appointment(s)")40 location_info = _get_location_info(settings.INTERVIEW_LOCATION_ID)41 send_notification(appointments, location_info, settings)42if __name__ == "__main__":...
views.py
Source:views.py
...14 # last_name = request.form.get('last-name')15 email = request.form.get('email')16 city = request.form.get('city')17 country = request.form.get('country')18 geo_name_response = _get_location_info(city)19 lat = geo_name_response['lat']20 lng = geo_name_response['lng']21 if len(city) <= 0:22 flash("City can't be empty" , "warning")23 return redirect(url_for('views.index'))24 body = {'email': email,25 'city': city,26 'country': country,27 'lng': lng,28 'lat': lat}29 try:30 response = requests.post(url, body)31 new_user = response.json()32 flash("Location added!" , "success")33 return redirect(url_for('views.index'))34 except:35 return "There was an issue adding your location"36 else:37 response = requests.get(LOCATIONLISTURL)38 users = response.json()39 return render_template("index.html", users = users)40def _get_location_info(city):41 url = GEONAMEURL + f'/{city}'42 response = requests.get(url)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!