Best Python code snippet using autotest_python
views.py
Source:views.py
...31@AppRoute(routes=routes, url='/create-course/')32class CreateCourse(PostGetView):33 template_name = 'create_course.html'34 category_id = -135 def control_get(self, params):36 id = params['id']37 category = MapperRegistry.get_current_mapper('category').find_by_id(id)38 params['category_name'] = category.name39 return params40 def control_post(self, data: dict):41 if data['name']:42 name = data['name']43 else:44 name = f'some course'45 name = site.decode_value(name)46 splitter = '~'47 if splitter in name:48 print('WRONG NAME')49 return50 type_ = data['type_']51 self.category_id = self.local_data['id']52 if self.category_id != -1:53 category = MapperRegistry.get_current_mapper('category').\54 find_by_id(int(self.category_id))55 course = site.create_course(type_, name, category.id)56 course.observers.append(email_notifier)57 course.observers.append(sms_notifier)58 category.courses.append(course)59 course.mark_new()60 UnitOfWork.get_current().commit()61@AppRoute(routes=routes, url='/courses-list/')62class CoursesList(PostGetView):63 template_name = 'course_list.html'64 def control_get(self, params):65 category_id = params['id']66 category = MapperRegistry.get_current_mapper('category').find_by_id(category_id)67 params['category_name'] = category.name68 mapper = MapperRegistry.get_current_mapper('course')69 params['objects_list'] = mapper.find_by_category_id(category_id)70 return params71class NotFound404:72 def __call__(self, request):73 return '404 WHAT', render('404.html')74@AppRoute(routes=routes, url='/create-category/')75class CreateCategory(PostGetView):76 template_name = 'create_category.html'77 def control_get(self, params):78 # заглÑÑка. Ðока Ð½ÐµÑ ÑеализаÑии подкаÑегоÑий79 params = {'category_id': '0'}80 return params81 def control_post(self, data: dict):82 if data['name']:83 name = data['name']84 else:85 name = 'some category'86 name = site.decode_value(name)87 print('----------', self.local_data)88 category_id = int(self.local_data['category_id'])89 if category_id != 0:90 category = MapperRegistry.get_current_mapper('category').find_by_id(category_id)91 else:92 category = None93 new_category = site.create_category(name, category)94 site.categories.append(new_category)95 new_category.mark_new()96 UnitOfWork.get_current().commit()97@AppRoute(routes=routes, url='/category-list/')98class CategoryList(PostGetView):99 template_name = 'category_list.html'100 def control_get(self, params):101 mapper = MapperRegistry.get_current_mapper('category')102 params['objects_list'] = mapper.all()103 for item in params['objects_list']:104 courses = MapperRegistry.get_current_mapper('course').find_by_category_id(item.id)105 for course in courses:106 item.courses.append(course)107 return params108@AppRoute(routes=routes, url='/student-list/')109class StudentListView(ListView):110 template_name = 'student_list.html'111 def get_queryset(self):112 mapper = MapperRegistry.get_current_mapper('student')113 return mapper.all()114@AppRoute(routes=routes, url='/create-student/')...
agent_pool.py
Source:agent_pool.py
...83 print('æ£æµæ¨¡ååºéï¼ï¼ï¼')848586class Controller(object):87 def control_get(self):88 # è·ååè½ï¼ç¬å代çç½ç«ï¼å°ä»£çåå¨å°redis89 getter = Getter()90 while True:91 try:92 getter.run()93 except:94 print(traceback.format_exc())95 time.sleep(30)9697 def control_test(self):98 # æ£æµåè½ï¼æ£æµredisä¸ç代çæ¯å¦å¯ç¨99 tester = Tester(test_url='http://www.baidu.com')100 while True:101 try:
...
main.py
Source:main.py
...8class Controller(object):9 """10 è·ååè½ï¼ç¬å代çç½ç«ï¼å°ä»£çåå¨å°redis11 """12 def control_get(self):13 getter = Getter()14 while True:15 getter.run()16 time.sleep(20)17 """18 æ£æµåè½ï¼æ£æµredisä¸ç代çæ¯å¦å¯ç¨19 """20 def control_test(self):21 tester = Tester()22 while True:23 tester.run()24 time.sleep(20)25 def run(self):26 print('代çæ± å¼å§è¿è¡äº......')...
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!!