Best Python code snippet using autotest_python
populate_testcases.py
Source:populate_testcases.py
1from vtv_task import VtvTask, vtv_task_main2INSERT_TESTCASE = 'insert into test_cases (suite_id, record, created_at, last_modified, flag) values(%s, %s, now(), now(), %s)'3class PopulateTestcases(VtvTask):4 def __init__(self):5 VtvTask.__init__(self)6 self.db_ip = '10.4.2.187'7 self.db_name = 'DATATESTDB'8 self.sports_db = '10.4.18.183'9 self.sports_dbname = 'SPORTSDB'10 self.test_file = open('testcases_file', 'r')11 self.out_file = open('write_testcases', 'w')12 self.stadiums_file= open('stadiums_merge', 'r') 13 self.stadiums = {}14 self.stadiums_gids = {}15 self.duplicate_list = []16 self.duplicates_file = open('duplicate_stadiums', 'w')17 def get_suite_id(self):18 query = "select id from test_suites where suite_name= 'stadiums'"19 self.cursor.execute(query)20 result = self.cursor.fetchone()21 if result:22 result = result[0]23 return result24 25 def populate_testcases(self):26 suite_id = self.get_suite_id()27 for row in self.test_file:28 row = [rw.strip() for rw in row.strip().split(',')]29 if len(row) == 6:30 query = 'select record from test_cases where suite_id=%s and record like %s'31 val = '%' + row[0] + '#%'32 values = (suite_id, val)33 self.cursor.execute(query, values)34 data = self.cursor.fetchone()35 if data:36 continue37 record = '#<>#'.join(row)38 print record39 #inserting test cases40 values = (suite_id, record, 'active')41 self.cursor.execute(INSERT_TESTCASE, values)42 self.out_file.write('%s\n' % record)43 wiki_gid = row[0]44 title = row[1]45 self.stadiums[wiki_gid] = title46 47 def get_stadium_gids(self):48 self.open_cursor(self.sports_db, self.sports_dbname)49 import pdb; pdb.set_trace()50 for record in self.stadiums_file.readlines():51 if ',' in record:52 stadium_gid, wiki_gid = [rec.strip() for rec in record.split(',')]53 else:54 stadium_gid, wiki_gid = [rec.strip() for rec in record.split('<>')]55 if not 'WIKI' in wiki_gid:56 wiki_gid = 'WIKI' + wiki_gid57 if self.stadiums_gids.get(wiki_gid, ''):58 if stadium_gid not in self.duplicate_list:59 self.duplicate_list.append(stadium_gid)60 stadiums = '<>'.join([stadium_gid, wiki_gid])61 self.duplicates_file.write('%s\n' % stadiums)62 else:63 self.stadiums_gids[wiki_gid] = stadium_gid64 def populate_stadiums_merge(self):65 self.open_cursor('10.4.2.187', 'GUIDMERGE')66 query = 'select exposed_gid, child_gid from sports_wiki_merge'67 self.cursor.execute(query)68 stadium_list = {}69 for row in self.get_fetchmany_results():70 exposed_gid, child_gid = row71 if 'STAD' in child_gid:72 stadium_list[exposed_gid] = child_gid73 for wiki_gid, stad_gid in self.stadiums_gids.iteritems():74 if (stad_gid not in stadium_list.values()) and (wiki_gid not in stadium_list.keys()): 75 query = 'insert ignore into sports_wiki_merge (exposed_gid, child_gid, action, modified_date) values(%s, %s, %s, now())'76 values = (wiki_gid, stad_gid, 'override')77 self.cursor.execute(query, values)78 def run_main(self):79 self.open_cursor(self.db_ip, self.db_name)80 self.get_stadium_gids()81 self.populate_stadiums_merge()82 #self.populate_testcases()83if __name__ == '__main__':...
appium_db.py
Source:appium_db.py
...14 15 mng_db.APPIUM_TC_DETAILS.insert(regJson)16 mng_client.close()17 print 'Regression Created'18def insert_testcase(regId,testId, testcaseName):19 print 'Inside insert testcase'20 tcJson = {}21 tcJson['elements'] = []22 tcJson['testcaseName'] = testcaseName23 tcJson['testId'] = testId24 tcJson['description'] = 'test'25 26 mng_db.APPIUM_TC_DETAILS.update({"regId":regId},{"$push":{"testcases":tcJson}},True)27 28 mng_client.close()29 print 'Testcase Inserted'30def insert_element_data(regId,testId, testcaseName,testElementJson):31 32 33# mng_db.APPIUM_TC_DETAILS.update({"regId":regId},{"$push":{"elements":testElementJson}},True)34 mng_db.APPIUM_TC_DETAILS.update({"regId":regId, "testcases.testId":testId},{"$push":{"testcases.$.elements":testElementJson}},True)35 mng_client.close()36 print 'Testcase Inserted'37# create_Regression('1000')38# insert_testcase('1000','100', 'clickButton')39# insert_testcase('1000','101', 'dragitem')40def main():41 pass42if __name__ == "__main__":43 create_Regression('1000')44 insert_testcase('1000','100', 'clickButton')45 insert_testcase('1000','101', 'dragitem')...
test_problems_db.py
Source:test_problems_db.py
...910 test.reset_tables()11 test.insert_problem("two sum", "Find the smallest array that can contain your mother mod 10**9 + 7")12 test.insert_problem("find sum", "add two numbers\nINPUT:\nfirst line is n\nafter that n lines of two numbers to sum")13 test.insert_testcase(1, "2\n1 2\n2 3", "3\n5")14 test.insert_testcase(1, "2\n9 1\n2 5", "10\n7")15 test.insert_testcase(1, "1\n100 1", "101")16 test.insert_testcase(2, "2\n1 2\n2 3", "3\n5")17 test.dump_all()18 test.cursor.close()
...
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!!