Best Python code snippet using selene_python
db_helpers.py
Source:db_helpers.py
...73 'sku': car.sku74 }75 )76 return car_model[0]77async def get_or_create_driver(discord_id, guild_id, iracing_id, name=None):78 guild_model = await get_or_create_guild(guild_id)79 driver_model = await Driver.get_or_create(80 discord_id=discord_id,81 defaults={'iracing_id': iracing_id}82 )83 driver = driver_model[0]84 if name:85 driver.iracing_name = name86 await driver.save()87 await driver.guilds.add(guild_model)88 return driver89# This also deletes all previous data from this driver90async def create_or_update_driver(iracing_id, discord_id, guild_id, name=None):91 guild_model = await get_or_create_guild(guild_id)92 driver = await Driver.get_or_none(discord_id=discord_id)93 if driver:94 await driver.update_from_dict({'iracing_name': name, 'iracing_id': iracing_id})95 await driver.save()96 else:97 driver = await Driver.create(98 discord_id=discord_id,99 iracing_name=name,100 iracing_id=iracing_id101 )102 driver = await get_or_create_driver(discord_id, guild_id, iracing_id, name)103 await driver.guilds.add(guild_model)104 await remove_driver_data(driver)105 return driver106async def remove_driver_data(driver):107 try:108 await Irating.filter(driver=driver).delete()109 except:110 pass111 try:112 await License.filter(driver=driver).delete()113 except:114 pass115 try:116 await Stat.filter(driver=driver).delete()117 except:118 pass119async def create_or_update_stat_from_driver(driver, stat, stat_type):120 if stat_type == StatsType.career:121 stat_model_tuple = await Stat.get_or_create(122 driver=driver,123 category=Category.from_name(stat.category),124 stat_type=StatsType.career125 )126 stat_model = stat_model_tuple[0]127 else:128 stat_model_tuple = await Stat.get_or_create(129 driver=driver,130 category=Category.from_name(stat.category),131 stat_type=StatsType.yearly,132 year=stat.year133 )134 stat_model = stat_model_tuple[0]135 await stat_model.update_from_dict({136 'avg_incidents': stat.incidents_avg,137 'total_laps': stat.laps,138 'laps_led': stat.laps_led,139 'laps_led_percentage': stat.laps_led_pcnt,140 'points_avg': stat.points_avg,141 'points_club': stat.points_club,142 'poles': stat.poles,143 'avg_start_pos': stat.pos_start_avg,144 'avg_finish_pos': stat.pos_finish_avg,145 'total_starts': stat.starts,146 'top_five_percentage': stat.top_5_pcnt,147 'total_top_fives': stat.top_5s,148 'win_percentage': stat.win_pcnt,149 'total_wins': stat.wins,150 })151 await stat_model.save()152 return stat_model153async def create_or_update_stats(driver_discord_id, guild_id, stat, stat_type, driver_iracing_id):154 driver_model = await get_or_create_driver(driver_discord_id, guild_id, driver_iracing_id)155 if stat_type == StatsType.career:156 stat_model_tuple = await Stat.get_or_create(157 driver=driver_model,158 category=Category.from_name(stat.category),159 stat_type=StatsType.career160 )161 stat_model = stat_model_tuple[0]162 else:163 stat_model_tuple = await Stat.get_or_create(164 driver=driver_model,165 category=Category.from_name(stat.category),166 stat_type=StatsType.yearly,167 year=stat.year168 )169 stat_model = stat_model_tuple[0]170 await stat_model.update_from_dict({171 'avg_incidents': stat.incidents_avg,172 'total_laps': stat.laps,173 'laps_led': stat.laps_led,174 'laps_led_percentage': stat.laps_led_pcnt,175 'points_avg': stat.points_avg,176 'points_club': stat.points_club,177 'poles': stat.poles,178 'avg_start_pos': stat.pos_start_avg,179 'avg_finish_pos': stat.pos_finish_avg,180 'total_starts': stat.starts,181 'top_five_percentage': stat.top_5_pcnt,182 'total_top_fives': stat.top_5s,183 'win_percentage': stat.win_pcnt,184 'total_wins': stat.wins,185 })186 await stat_model.save()187 return stat_model188async def get_or_create_guild(guild_id):189 guild_model = await Guild.get_or_create(190 discord_id=guild_id191 )192 return guild_model[0]193async def update_driver_name(discord_id, guild_id, name, iracing_id):194 guild_model = await get_or_create_guild(guild_id)195 driver_model = await get_or_create_driver(discord_id, guild_id, iracing_id)196 driver_model.iracing_name = name197 await driver_model.save()198 await driver_model.guilds.add(guild_model)199 return driver_model200async def get_or_create_irating_for_driver(driver, irating, category):201 irating_timestamp = datetime.fromtimestamp((irating.timestamp / 1000))202 irating_model = await Irating.get_or_create(203 timestamp=irating_timestamp,204 driver=driver,205 category=Category(category),206 defaults={207 'value': irating.value208 }209 )210 return irating_model[0]211async def get_or_create_irating(guild_id, driver_discord_id, irating, category, driver_iracing_id):212 driver_model = await get_or_create_driver(driver_discord_id, guild_id, driver_iracing_id)213 irating_timestamp = datetime.fromtimestamp((irating.timestamp / 1000))214 irating_model = await Irating.get_or_create(215 timestamp=irating_timestamp,216 driver=driver_model,217 category=Category(category),218 defaults={219 'value': irating.value220 }221 )222 return irating_model[0]223async def get_or_create_license_for_driver(driver, license_class, category):224 license_timestamp = datetime.fromtimestamp((license_class.timestamp / 1000))225 license_model = await License.get_or_create(226 timestamp=license_timestamp,227 driver=driver,228 category=Category(category),229 defaults={230 'license_number': license_class.license_number231 }232 )233 return license_model[0]234async def get_or_create_license(guild_id, driver_discord_id, license_class, category, driver_iracing_id):235 driver_model = await get_or_create_driver(driver_discord_id, guild_id, driver_iracing_id)236 license_timestamp = datetime.fromtimestamp((license_class.timestamp / 1000))237 license_model = await License.get_or_create(238 timestamp=license_timestamp,239 driver=driver_model,240 category=Category(category),241 defaults={242 'license_number': license_class.license_number243 }244 )245 return license_model[0]246async def set_all_fav_series(guild_id, series_ids):247 for series_id in series_ids:248 await add_fav_series(guild_id, series_id)249async def add_fav_series(guild_id, series_id):...
register_user.py
Source:register_user.py
...8 first_name = ''.join(random.choice(string.ascii_lowercase) for _ in range(5))9 surname = ''.join(random.choice(string.ascii_lowercase) for _ in range(8))10 username = first_name + '_' + surname11 password = "password01"12 self.browser = get_or_create_driver()13 # Navigate to Registration page14 self.browser.find_element_by_xpath("/html/body/header[2]/div/nav/ul[2]/li[2]/a").click()15 # Enter Username16 self.browser.find_element_by_id("field-username").clear()17 self.browser.find_element_by_id("field-username").send_keys(username)18 # Enter Full Name19 self.browser.find_element_by_id("field-fullname").clear()20 self.browser.find_element_by_id("field-fullname").send_keys(first_name + ' ' + surname)21 # Enter email address22 self.browser.find_element_by_id("field-email").clear()23 self.browser.find_element_by_id("field-email").send_keys(first_name + '.' + surname + "@test.com")24 # Enter password25 self.browser.find_element_by_id("field-password").clear()26 self.browser.find_element_by_id("field-password").send_keys(password)...
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!!