Best Python code snippet using lisa_python
export_origin_job.py
Source:export_origin_job.py
1from ethereumetl.executors.batch_work_executor import BatchWorkExecutor2from blockchainetl.jobs.base_job import BaseJob3from ethereumetl.utils import validate_range4from ethereumetl.mappers.receipt_log_mapper import EthReceiptLogMapper5from ethereumetl.mappers.origin_mapper import OriginMarketplaceListingMapper, OriginShopProductMapper6from ethereumetl.service.origin_extractor import OriginEventExtractor7# Addresses of the marketplace contracts.8ORIGIN_MARKETPLACE_V0_CONTRACT_ADDRESS = '0x819Bb9964B6eBF52361F1ae42CF4831B921510f9'9ORIGIN_MARKETPLACE_V1_CONTRACT_ADDRESS = '0x698Ff47B84837d3971118a369c570172EE7e54c2'10# Block number at which contracts were deployed to the Mainnet.11ORIGIN_MARKETPLACE_V0_BLOCK_NUMBER_EPOCH = 643615712ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH = 858259713class ExportOriginJob(BaseJob):14 def __init__(15 self,16 start_block,17 end_block,18 batch_size,19 web3,20 ipfs_client,21 marketplace_listing_exporter,22 shop_product_exporter,23 max_workers):24 validate_range(start_block, end_block)25 self.start_block = start_block26 self.end_block = end_block27 self.web3 = web328 self.marketplace_listing_exporter = marketplace_listing_exporter29 self.shop_product_exporter = shop_product_exporter30 self.batch_work_executor = BatchWorkExecutor(batch_size, max_workers)31 self.event_extractor = OriginEventExtractor(ipfs_client)32 self.receipt_log_mapper = EthReceiptLogMapper()33 self.marketplace_listing_mapper = OriginMarketplaceListingMapper()34 self.shop_listing_mapper = OriginShopProductMapper()35 def _start(self):36 self.marketplace_listing_exporter.open()37 self.shop_product_exporter.open()38 def _export(self):39 self.batch_work_executor.execute(40 range(self.start_block, self.end_block + 1),41 self._export_batch,42 total_items=self.end_block - self.start_block + 143 )44 def _export_batch(self, block_number_batch):45 assert len(block_number_batch) > 046 from_block = block_number_batch[0]47 to_block = block_number_batch[-1]48 # Nothing to process if the block range is older than the V0 marketplace contract's epoch.49 if to_block < ORIGIN_MARKETPLACE_V0_BLOCK_NUMBER_EPOCH:50 return51 # Determine the version and address of the marketplace contract to query based on the block range.52 batches = []53 if to_block < ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH or from_block >= ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH:54 # The block range falls within a single version of the marketplace contract.55 version = '000' if to_block < ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH else '001'56 address = ORIGIN_MARKETPLACE_V0_CONTRACT_ADDRESS if version == '000' else ORIGIN_MARKETPLACE_V1_CONTRACT_ADDRESS57 batches.append({58 'contract_address': address,59 'contract_version': version,60 'from_block': from_block,61 'to_block': to_block62 })63 else:64 # The block range spans across 2 versions of the marketplace contract.65 batches.append({66 'contract_address': ORIGIN_MARKETPLACE_V0_CONTRACT_ADDRESS,67 'contract_version': '000',68 'from_block': from_block,69 'to_block': ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH - 170 })71 batches.append({72 'contract_address': ORIGIN_MARKETPLACE_V1_CONTRACT_ADDRESS,73 'contract_version': '001',74 'from_block': ORIGIN_MARKETPLACE_V1_BLOCK_NUMBER_EPOCH,75 'to_block': to_block76 })77 for batch in batches:78 # https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getfilterlogs79 filter_params = {80 'address': batch['contract_address'],81 'fromBlock': batch['from_block'],82 'toBlock': batch['to_block']83 }84 event_filter = self.web3.eth.filter(filter_params)85 events = event_filter.get_all_entries()86 for event in events:87 log = self.receipt_log_mapper.web3_dict_to_receipt_log(event)88 listing, shop_products = self.event_extractor.extract_event_from_log(log, batch['contract_version'])89 if listing:90 item = self.marketplace_listing_mapper.listing_to_dict(listing)91 self.marketplace_listing_exporter.export_item(item)92 for product in shop_products:93 item = self.shop_listing_mapper.product_to_dict(product)94 self.shop_product_exporter.export_item(item)95 self.web3.eth.uninstallFilter(event_filter.filter_id)96 def _end(self):97 self.batch_work_executor.shutdown()98 self.marketplace_listing_exporter.close()...
views.py
Source:views.py
1# Create your views here.2import logging3from django.conf import settings4from django.core.urlresolvers import reverse5from django.db import transaction6from django.db.models import Q7from django.http import HttpResponseRedirect8from django.template import RequestContext9from django.shortcuts import render_to_response, get_object_or_40410from django.utils.translation import ugettext as _11from auth.models import User12from shops.models import Shop 13from payments.gateways.braintreegw import BraintreeGateway 14from users.models import Profile 15from shops.forms import MailingListMemberForm16def profiles_list(request, letter):17 from shops.models import Shop18 19 marketplace = request.marketplace20 shops = Shop.actives.filter(marketplace=marketplace).filter(name__startswith=letter)21 return render_to_response("%s/community/profiles_list.html" % request.marketplace.template_prefix, 22 {'shops':shops, 'letter': letter},23 RequestContext(request))24 25def profiles(request):26 from shops.models import Shop27 28 letters = []29 marketplace = request.marketplace30 shops = Shop.actives.filter(marketplace=marketplace)31 32 for shop in shops: letters.append(shop.name[0]) 33 letters = sorted(set(letters))34 return render_to_response("%s/community/profiles.html" % request.marketplace.template_prefix, {'letters' : letters, 'shops' : shops,}, RequestContext(request))35def forums(request):36 return render_to_response("%s/community/forums.html" % request.marketplace.template_prefix, 37 {},38 RequestContext(request))39def blogs(request):40 import datetime41 from blog_pages.models import Post42 from models import PostEditorPick43 44 today = datetime.date.today()45 wday = today.weekday()46 monday = today - datetime.timedelta(days=wday)47 sunday = monday + datetime.timedelta(days=6)48 49 logging.critical(today)50 logging.critical(wday)51 logging.critical(monday)52 logging.critical(sunday)53 54 marketplace = request.marketplace55 last_posts = Post.objects.filter(shop__marketplace=marketplace).filter(draft=False).order_by("-date_time")[:5]56 posts_picks = PostEditorPick.objects.filter(marketplace=marketplace).order_by("order")57 most_visited = Post.objects.filter(shop__marketplace=marketplace).filter(draft=False).order_by("-views")[:5]58 #most_visited = posts.filter(date_time__range=(monday, sunday)).order_by("-views")[:5]59 60 return render_to_response("%s/community/blogs.html" % request.marketplace.template_prefix, 61 {62 'last_posts' : last_posts,63 'posts_picks' : posts_picks,64 'most_visited' : most_visited,65 },66 RequestContext(request))67 68def faq(request):69 from market_community.models import FAQCategory70 marketplace = request.marketplace71 72 categories = FAQCategory.objects.filter(marketplace=marketplace)73 return render_to_response("%s/community/faq.html" % request.marketplace.template_prefix, 74 {75 'categories' : categories, 76 },77 RequestContext(request))78def overview(request):79 from blog_pages.models import Post80 from shops.models import Shop81 from market_community.models import MarketPlaceAnnouncement82 from market.forms import MarketMailingListMemberForm83 84 marketplace = request.marketplace85 announcements = MarketPlaceAnnouncement.objects.filter(marketplace=marketplace).order_by("-posted_on")[:5]86 shops = Shop.actives.filter(marketplace=marketplace).order_by("-date_time")[:3]87 last_posts = Post.objects.filter(shop__marketplace=marketplace).filter(draft=False).order_by("-date_time")[:5]88 if request.method == "POST":89 form = MarketMailingListMemberForm(request.POST)90 if form.is_valid():91 member = form.save(commit=False)92 member.marketplace = request.marketplace93 member.save()94 request.flash['message'] = unicode(_("Email successfully registered."))95 request.flash['severity'] = "success"96 return HttpResponseRedirect(reverse("market_community"))97 else:98 form = MarketMailingListMemberForm() 99 100 return render_to_response("%s/community/overview.html" % request.marketplace.template_prefix, 101 {102 'announcements' : announcements,103 'last_posts' : last_posts,104 'shops' : shops,105 'mailing_list_form' : form,106 },...
test.py
Source:test.py
...32 response = self.mws.get_inbound_service_status()33 status = response.GetServiceStatusResult.Status34 self.assertIn(status, ('GREEN', 'GREEN_I', 'YELLOW', 'RED'))35 @property36 def marketplace(self):37 try:38 return self._marketplace39 except AttributeError:40 response = self.mws.list_marketplace_participations()41 result = response.ListMarketplaceParticipationsResult42 self._marketplace = result.ListMarketplaces.Marketplace[0]43 return self.marketplace44 @property45 def marketplace_id(self):46 return self.marketplace.MarketplaceId47 @unittest.skipUnless(simple and isolator, "skipping simple test")48 def test_marketplace_participations(self):49 response = self.mws.list_marketplace_participations()50 result = response.ListMarketplaceParticipationsResult...
Check out the latest blogs from LambdaTest on this topic:
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
With new-age project development methodologies like Agile and DevOps slowly replacing the old-age waterfall model, the demand for testing is increasing in the industry. Testers are now working together with the developers and automation testing is vastly replacing manual testing in many ways. If you are new to the domain of automation testing, the organization that just hired you, will expect you to be fast, think out of the box, and able to detect bugs or deliver solutions which no one thought of. But with just basic knowledge of testing, how can you be that successful test automation engineer who is different from their predecessors? What are the skills to become a successful automation tester in 2019? Let’s find out.
In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.
Hey Testers! We know it’s been tough out there at this time when the pandemic is far from gone and remote working has become the new normal. Regardless of all the hurdles, we are continually working to bring more features on-board for a seamless cross-browser testing experience.
With the rising demand for new services and technologies in the IT, manufacturing, healthcare, and financial sector, QA/ DevOps engineering has become the most important part of software companies. Below is a list of some characteristics to look for when interviewing a potential candidate.
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!!