Best Python code snippet using playwright-python
views.py
Source:views.py
...36def notary_req(request):37 """"show datacap request record """38 page_index = request.POST.get('page_index', '1')39 page_size = request.POST.get('page_size', '5')40 page_size = interface.handle_page(page_size, 5)41 page_index = interface.handle_page(page_index, 1)42 name = request.POST.get('name').strip('')43 msg_code, msg_data = interface.get_notary_req(name=name)44 total = len(msg_data)45 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]46 return format_return(msg_code, data={'data': msg_data, 'total': total})47@common_ajax_response48@lang_translate49def query_msg(request):50 """get msg details"""51 msg_cid = request.POST.get('msg_cid')52 msg_code, msg_data = interface.query_msg(msg_cid=msg_cid)53 return format_return(msg_code, data=msg_data)54@common_ajax_response55@lang_translate56def provider_info_basic_info(request):57 """basic info of provider info"""58 provider_id = request.POST.get('provider_id')59 msg_code, msg_data = interface.get_provider_info_basic_info(provider_id=provider_id)60 return format_return(msg_code, data=msg_data)61@common_ajax_response62@lang_translate63def provider_info_order_stat(request):64 """order stat of provider info"""65 page_index = request.POST.get('page_index')66 page_size = request.POST.get('page_size')67 page_size = interface.handle_page(page_size, 5)68 page_index = interface.handle_page(page_index, 1)69 provider_id = request.POST.get('provider_id')70 msg_code, msg_data1, msg_data2 = interface.get_provider_info_order_stat(provider_id=provider_id)71 msg_data1 = msg_data1[(page_size * (page_index - 1)):page_size * page_index]72 msg_data2 = msg_data2[(page_size * (page_index - 1)):page_size * page_index]73 return format_return(msg_code, data={'time': msg_data1, 'data': msg_data2})74@common_ajax_response75@lang_translate76def provider_info_order_details_list(request):77 """order details list of provider info"""78 page_index = request.POST.get('page_index')79 page_size = request.POST.get('page_size')80 page_size = interface.handle_page(page_size, 5)81 page_index = interface.handle_page(page_index, 1)82 provider_id = request.POST.get('provider_id')83 msg_code, msg_data = interface.get_provider_info_order_details_list(provider_id=provider_id)84 total = len(msg_data)85 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]86 return format_return(msg_code, data={'data': msg_data, 'total': total})87@common_ajax_response88@lang_translate89def provider_info_client_list(request):90 """client list of provider info"""91 page_index = request.POST.get('page_index')92 page_size = request.POST.get('page_size')93 page_size = interface.handle_page(page_size, 5)94 page_index = interface.handle_page(page_index, 1)95 provider_id = request.POST.get('provider_id')96 msg_code, msg_data = interface.get_provider_info_client_list(provider_id=provider_id)97 total = len(msg_data)98 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]99 return format_return(msg_code, data={'data': msg_data, 'total': total})100@common_ajax_response101@lang_translate102def new_seven_data(request):103 """data in a week"""104 msg_code, msg_data = interface.get_new_seven_data()105 return format_return(msg_code, data=msg_data)106@common_ajax_response107@lang_translate108def get_name(request):109 """get the notary and client name"""110 data = interface.get_name_list()111 return format_return(0, data=data)112@common_ajax_response113@lang_translate114def distribution_data(request):115 """show the distribution data"""116 msg_code, msg_data = interface.distribution_data()117 return format_return(msg_code, data=msg_data)118@common_ajax_response119@lang_translate120def notary_distribution_data(request):121 """show the distribution data of notary"""122 notary_list = request.POST.get('notary_list')123 msg_code, msg_data = interface.notary_distribution_data(notary_list=None)124 return format_return(msg_code, data=msg_data)125@common_ajax_response126@lang_translate127def handle_efficiency(request):128 """show the efficiency of handling datacap request """129 notary_list = request.POST.get('notary_list')130 msg_code, msg_data = interface.get_handle_efficiency(notary_list=notary_list)131 return format_return(msg_code, data=msg_data)132@common_ajax_response133@lang_translate134def notary_handle_efficiency_borad(request):135 """handling data request board"""136 page_index = request.POST.get('page_index')137 page_size = request.POST.get('page_size')138 sort_type = request.POST.get('sort_type')139 page_size = interface.handle_page(page_size, 5)140 page_index = interface.handle_page(page_index, 1)141 msg_data = interface.get_handle_efficiency_borad()142 msg_code, msg_data = interface.get_handle_efficiency_borad_sort(sort_type=sort_type, data=msg_data)143 if msg_code != 0:144 return format_return(msg_code)145 length = len(msg_data)146 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]147 return format_return(msg_code, data={'data': msg_data, 'length': length})148@common_ajax_response149@lang_translate150def request_borad(request):151 """show datacap request board"""152 page_index = request.POST.get('page_index')153 page_size = request.POST.get('page_size')154 sort_type = request.POST.get('sort_type')155 page_size = interface.handle_page(page_size, 5)156 page_index = interface.handle_page(page_index, 1)157 msg_data = interface.get_request_borad()158 msg_code, msg_data = interface.get_request_borad_sort(data=msg_data, sort_type=sort_type)159 if msg_code != 0:160 return format_return(msg_code)161 length = len(msg_data)162 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]163 return format_return(msg_code, data={'data': msg_data, 'length': length})164@common_ajax_response165@lang_translate166def provider_borad(request):167 """show the provider board"""168 page_index = request.POST.get('page_index')169 page_size = request.POST.get('page_size')170 sort_type = request.POST.get('sort_type')171 page_size = interface.handle_page(page_size, 5)172 page_index = interface.handle_page(page_index, 1)173 msg_data = interface.get_provider_borad()174 msg_code, msg_data = interface.get_provider_borad_sort(sort_type=sort_type, data=msg_data)175 if msg_code != 0:176 return format_return(msg_code)177 length = len(msg_data)178 msg_data = msg_data[(page_size * (page_index - 1)):page_size * page_index]179 return format_return(0, data={'data': msg_data, 'length': length})180@common_ajax_response181@lang_translate182def user_info(request):183 """show the user info"""184 address = request.POST.get('address')185 msg_code, msg_data = interface.get_user_info(address=address)186 return format_return(msg_code, data=msg_data)187@common_ajax_response188@lang_translate189def assumption_details(request):190 """show the details of assumption"""191 address = request.POST.get('address')192 page_index = request.POST.get('page_index', '1')193 page_size = request.POST.get('page_size', '5')194 page_size = interface.handle_page(page_size, 5)195 page_index = interface.handle_page(page_index, 1)196 msg_code, msg_data = interface.get_assumption_details(address=address)197 obj = Page(msg_data, page_size).page(page_index)198 data_list = []199 for i in obj.get('objects'):200 data_list.append({201 'deal_id': i.deal_id,202 'height_time': i.height_time.strftime('%Y-%m-%d %H:%M:%S'),203 'provider_id': i.provider_id,204 'file_size': i.file_size,205 })206 return format_return(0, data={"objs": data_list, "total_page": obj.get('total_page'),207 "total_count": obj.get('total_count')})208@common_ajax_response209@lang_translate210def request_records(request):211 """show the datacap request records"""212 address = request.POST.get('address')213 page_index = request.POST.get('page_index', '1')214 page_size = request.POST.get('page_size', '5')215 page_size = interface.handle_page(page_size, 5)216 page_index = interface.handle_page(page_index, 1)217 msg_code, msg_data = interface.request_record(address=address)218 obj = Page(msg_data, page_size).page(page_index)219 data_list = []220 for i in obj.get('objects'):221 msg_cid = i.msg_cid222 assignee = i.assignee223 comments_url = i.comments_url224 data_list.append({225 'assignee': assignee,226 'created_at': i.created_at.strftime('%Y-%m-%d %H:%M:%S') if i.created_at else i.created_at,227 'region': i.region,228 'request_datacap': i.request_datacap,229 'status': i.status,230 'allocated_datacap': i.allocated_datacap,...
base.py
Source:base.py
...29import lxml.html30class Spatula:31 """ mixin for scrapelib.Scraper """32 def scrape_page_items(self, page_type, url=None, **kwargs):33 yield from page_type(self, url=url, **kwargs).handle_page()34 def scrape_page(self, page_type, url=None, obj=None, **kwargs):35 return page_type(self, url=url, obj=obj, **kwargs).handle_page()36class NoListItems(Exception):37 pass38class AbstractPage:39 def __init__(self, scraper, url=None, *, obj=None, **kwargs):40 self.scraper = scraper41 if url:42 self.url = url43 self.obj = obj44 self.kwargs = kwargs45class Page(AbstractPage):46 def __init__(self, scraper, url=None, *, obj=None, **kwargs):47 super().__init__(scraper, url=url, obj=obj, **kwargs)48 resp = self.do_request()49 self.doc = lxml.html.fromstring(resp.text)50 self.doc.make_links_absolute(self.url)51 def do_request(self):52 return self.scraper.get(self.url)53 def scrape_page_items(self, page_type, url=None, **kwargs):54 """55 creates an instance of ``page_type`` and returns an iterable of56 scraped items57 """58 yield from page_type(self.scraper, url=url, **kwargs).handle_page()59 def scrape_page(self, page_type, url=None, obj=None, **kwargs):60 """61 creates an instance of ``page_type`` that knows about an object62 being built (``obj``)63 """64 return page_type(self.scraper, url=url, obj=obj, **kwargs).handle_page()65 def handle_list_item(self, item):66 """67 override handle_list_item for scrapers that iterate over68 return values69 """70 raise NotImplementedError()71 def handle_page(self):72 n = 073 for item in self.doc.xpath(self.list_xpath):74 n += 175 processed = self.handle_list_item(item)76 if processed:77 if hasattr(processed, '__iter__'):78 yield from processed79 else:80 yield processed81 # if not n:82 # raise NoListItems('no matches for {} on {}'.format(self.list_xpath, self.url))83class PDF(AbstractPage):84 pdftotext_type = 'text'85 def __init__(self, scraper, url=None, *, obj=None, **kwargs):...
test_pagination.py
Source:test_pagination.py
...53 p = Pagination(ls[:50], len(ls), 1, 50)54 self.assertEqual(p.last_page, 20)55 p = Pagination(ls[:50], len(ls), 1, 100)56 self.assertEqual(p.last_page, 10)57 def test_handle_page(self):58 """Check the handle_page function, this is important as it stops Redis59 going crazy if the index is too high on a list or sorted set.60 """61 # Create a mock request object so that this functon does not require62 # a request. It gets a request object passed in.63 class Request(object):64 args = {}65 request = Request()66 # Check a couple of values67 self.assertEqual(handle_page(request), 1)68 request.args['page'] = 100000069 self.assertEqual(handle_page(request), 1000000)70 # Ensure our minimum value can't be broken71 request.args['page'] = -172 self.assertEqual(handle_page(request), 1)73 # Ensure the maximum value (4294967295) can't be broken74 request.args['page'] = 100000000000075 self.assertEqual(handle_page(request), 4294967295)76 # Ensure it does not brake with invalid types77 request.args['page'] = None78 self.assertEqual(handle_page(request), 1)79 request.args['page'] = {}...
builder.py
Source:builder.py
...30 'genindexcounts': indexcounts,31 'split_index': self.config.html_split_index,32 }33 if self.config.html_split_index:34 self.handle_page('genindex', genindexcontext,35 'genindex-split.html')36 self.handle_page('genindex-all', genindexcontext,37 'genindex.html')38 for (key, entries), count in zip(genindex, indexcounts):39 ctx = {'key': key, 'entries': entries, 'count': count,40 'genindexentries': genindex}41 self.handle_page('genindex-' + key, ctx,42 'genindex-single.html')43 else:44 self.handle_page('genindex', genindexcontext, 'genindex.html')45def add_custom_jinja2(app) -> None:46 env = app.builder.templates.environment47 env.tests['prefixedwith'] = str.startswith48 env.tests['suffixedwith'] = str.endswith49def add_builders(app) -> None:50 """This is necessary because RTD injects their own for some reason."""51 app.set_translator('html', DPYHTML5Translator, override=True)52 app.add_builder(DPYStandaloneHTMLBuilder, override=True)53 try:54 original = app.registry.builders['readthedocs']55 except KeyError:56 pass57 else:58 injected_mro = tuple(base if base is not StandaloneHTMLBuilder else DPYStandaloneHTMLBuilder...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!