Best Python code snippet using autotest_python
rte_manpower.py
Source:rte_manpower.py
...80 return db_data81# Get Manpower Group82@router.get('/group', status_code=status.HTTP_200_OK, response_model=List[val_manpower.ManPowerGroupOut])83@logger.catch()84def get_group_entries(dt: val_manpower.ManPowerGroupDatesIn, db: Session = Depends(get_db), current_user: val_user.UserOut = Depends(get_current_user)):85 if current_user.permissions < 1:86 return JSONResponse(status_code=status.HTTP_403_FORBIDDEN, content={'detail': 'unauthorized'})87 try:88 db_data = db.query(mdl_manpower.ManpowerGroup).filter(89 mdl_manpower.ManpowerGroup.created_at > dt.start,90 mdl_manpower.ManpowerGroup.created_at < dt.stop,91 mdl_manpower.ManpowerGroup.shift == dt.shift).order_by(92 mdl_manpower.ManpowerGroup.id).all()93 if not db_data:94 return JSONResponse(status_code=status.HTTP_404_NOT_FOUND)95 except Exception as error:96 logger.error(f'{error}')97 return Response(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)98 return db_data...
merge_keepass_xmls.py
Source:merge_keepass_xmls.py
...42 entry.find("username").text or "")43 def sorted_dict_items(self, d):44 # sort by key lexicographical order.45 return sorted(d.iteritems(), key=lambda x:x[0])46 def get_group_entries(self, elem):47 """48 for comparison's sake, take the most recent entry.49 """50 d = {}51 for entry in elem.findall("entry"):52 key = self.get_entry_key(entry)53 old_entry = d.get(key, None)54 if old_entry:55 # check the lastmod attribute56 if self.get_entry_lastmod_time(entry) > self.get_entry_lastmod_time(57 old_entry):58 # overwrite with the most recent.59 d[key] = entry60 else:61 d[key] = entry62 return d63 def get_subgroup_names(self, elem):64 # don't modify backups65 return dict([(group.find("title").text, group) for group in66 elem.findall("group") if group.find("title").text != "Backup"])67 def add_missing_groups(self, source, dest):68 """69 if there's a group in source but not in dest, add it to dest.70 renames will cause duplication.71 """72 dest_groups = self.get_subgroup_names(dest)73 for source_group_name, source_group_obj in self.get_subgroup_names(74 source).iteritems():75 if source_group_name in dest_groups:76 # check and add potentially missing subgroups.77 self.add_missing_groups(source_group_obj,78 dest_groups[source_group_name])79 else:80 dest.append(source_group_obj)81 def merge_entry(self, first, second, d_group, key):82 if self.get_entry_lastmod_time(first) > self.get_entry_lastmod_time(second):83 print "Entry %s/%s was changed." % tuple(key.split(self.SEP))84 second_entry_index = list(d_group).index(second)85 d_group.insert(second_entry_index+1, first)86 def merge_entries(self, source, dest):87 """88 # rules:89 # if an entry is in source but not in dest, it is added.90 # if an entry is both in source and dest:91 # if the content is the same, do nothing and be happy.92 # if the content differs, fully take the one with the most recent lastmod.93 """94 s_groups = self.get_subgroup_names(source)95 for group_name, s_group in s_groups.items():96 s_entries = self.get_group_entries(s_group)97 d_groups = self.get_subgroup_names(dest)98 d_group = d_groups[group_name]99 d_entries = self.get_group_entries(d_group)100 for s_entry_key, s_entry in s_entries.items():101 if not (s_entry_key in d_entries):102 print "missing %s/%s in dest, appending" % tuple(103 s_entry_key.split(self.SEP))104 d_group.append(s_entry)105 else:106 d_entry = d_entries[s_entry_key]107 self.merge_entry(s_entry, d_entry, d_group, s_entry_key)108 self.merge_entries(s_group, d_group)109 def merge_databases(self, first_xml_db_filename, second_xml_db_filename,110 destination_filename):111 first_xml_db = parse(first_xml_db_filename).getroot()112 second_xml_db = parse(second_xml_db_filename).getroot()113 self.add_missing_groups(first_xml_db, second_xml_db)...
era5_terria_catalog_generator_service.py
Source:era5_terria_catalog_generator_service.py
...122 """ Adds the terria catalog entry to catalog and returns the new catalog"""123 terria_catalog = load_terria_catalog_yaml()124125 group_name = ' '.join(entry.get('name').split(' ')[:2])126 group_entries = get_group_entries(group_name, terria_catalog.get('catalog'))127128 subgroup_name = ' '.join(entry.get('name').split(' ')[:4])129 subgroup_entries = get_group_entries(subgroup_name, group_entries)130131 subgroup_entries.append(entry)132133 return terria_catalog134135136def get_group_entries(group_name: str, groups: list) -> list:137 group = [d for d in groups if d.get('name', ' ') == group_name]138 if not group:139 groups.append({140 'name': group_name,141 'type': 'group',142 'preserveOrder': True,143 'isOpen': False,144 'items': []145 })146 group = [d for d in groups if d.get('name') == group_name]147 return group[0].get('items')148149150def load_terria_catalog_yaml() -> dict:
...
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!!