Best Python code snippet using tempest_python
RepoViewSet.py
Source: RepoViewSet.py
1from rest_framework.viewsets import ModelViewSet2from rest_framework.decorators import action3from rest_framework.response import Response4from repo.models import SendOut, SendRecord, ProductRecord, Product, SendOutShop, Shop5from repo.serializers import SendOutSerializer, SendRecordSerializer6from repo.filters import SendOutFilter, ProductFilter7from rest_framework.filters import OrderingFilter8from django_filters.rest_framework import DjangoFilterBackend9import logging10import json11log = logging.getLogger(__name__)12# 工人é¢èµ°åå13class SendOutViewSet(ModelViewSet):14 queryset = SendOut.objects.all()15 serializer_class = SendOutSerializer16 filterset_class = SendOutFilter17 filter_backends = (OrderingFilter, DjangoFilterBackend)18 ordering_fields = ('date', 'id')19 def get_queryset(self):20 return super().get_queryset().distinct()21 def create(self, request):22 data = request.data23 take = data.pop('take')24 serializer = SendOutSerializer(data=data)25 if serializer.is_valid():26 sendout = serializer.save()27 for each in take:28 shop = Shop.objects.get(shop_no=each['no'])29 SendOutShop.objects.create(send=sendout, shop=shop, option='Bring', out_num=each['out_num']) 30 # åå°ä»åºåºå31 shop.shop_num -= each['out_num']32 shop.save()33 return Response(status=201)34 else:35 return Response(status=400)36 @action(detail=True, methods=['put'])37 def bring_back(self, request, pk=None):38 data = request.data39 bring_object = self.get_object()40 for each in data.get('shop'):41 shop = Shop.objects.get(shop_no=each['no'])42 try:43 sendoutshop = SendOutShop.objects.get(send=bring_object, shop=shop)44 sendoutshop.in_num += each['in_num']45 sendoutshop.save()46 except SendOutShop.DoesNotExist:47 SendOutShop.objects.create(send=bring_object, shop=shop, option='Back', in_num=each['in_num']) 48 remark = data.get('remark')49 #å½è¿è®°å½50 SendRecord.objects.create(send=bring_object, shop=shop, date=data.get('date'), change_num=each.get('in_num'), remark=data.get('remark'))51 #å¢å è´§ååºå æ件è¢ãåªåãæ¿æ¦å½è¿ä¸å¢å åºå52 if shop.shop_no in ['001', '700A', '700B', '123', '425A', '425B', '425c', '425D', '425F']:53 pass54 else:55 shop.shop_num += each.get('in_num')56 shop.save()57 return Response()58 def destroy(self, request, *args, **kwargs):59 delete_object = self.get_object()60 if SendRecord.objects.filter(send=delete_object).count() > 0:61 return Response(status=511, data={"message": "å½è¿ä¸ä¸ºç©ºï¼ä¸è½å é¤"})62 for sendoutshop in SendOutShop.objects.filter(send=delete_object):63 shop = sendoutshop.shop64 shop.shop_num += sendoutshop.out_num65 shop.save()66 sendoutshop.delete()67 delete_object.delete()68 return Response(status=204, data={'message': 'å é¤æå'})69 70 @action(detail=True, methods=['get'])71 def get_comebacks(self, request, pk=None):72 bring_object = self.get_object()73 sendrecord = SendRecord.objects.filter(send=bring_object)74 serializer = SendRecordSerializer(sendrecord, many=True)75 return Response(serializer.data)76 @action(detail=True, methods=['put'])77 def change_status(self, request, pk=None):78 data = request.data79 bring_object = self.get_object()80 bring_object.status = data.get('status')81 bring_object.save()82 return Response()83class SendRecordViewSet(ModelViewSet):84 queryset = SendRecord.objects.all()85 serializer_class = SendRecordSerializer86 def destroy(self, request, pk=None):87 delete_object = self.get_object()88 # éè¿æ°éåå°89 send = delete_object.send90 shop = delete_object.shop91 try:92 sendoutshop = SendOutShop.objects.get(send=send, shop=shop)93 # å«æé¢èµ°è´§å94 if sendoutshop.option == 'Bring':95 sendoutshop.in_num -= delete_object.change_num96 sendoutshop.save()97 # ä¸å«æé¢èµ°è´§å98 else:99 sendoutshop.delete()100 except SendOutShop.DoesNotExist:101 pass102 # åå°åºåæ°é æ件è¢ãåªåãæ¿æ¦å½è¿ä¸å½±ååºå103 if shop.shop_no in ['001', '700A', '700B', '123', '425A', '425B', '425c', '425D', '425F']:104 pass105 else:106 shop.shop_num -= delete_object.change_num107 shop.save()108 delete_object.delete()109 ...
yostar_login.py
Source: yostar_login.py
...20 target_date = None21 target_content = None22 for key, email in emails.items():23 if 'Date' not in email:24 self.__s3_bucket.delete_object(key)25 logging.info(f'Deleted the object `{key}`.')26 continue27 date = datetime.datetime.strptime(28 email['Date'], '%a, %d %b %Y %H:%M:%S %z')29 now = datetime.datetime.now(tz=datetime.timezone.utc)30 if date < now - datetime.timedelta(minutes=30):31 # èªè¨¼ã³ã¼ãã®æå¹æéã30åãªã®ã§ï¼30å以ä¸åã«éããã32 # ã¡ã¼ã«ã¯ç¡æ¡ä»¶ã§åé¤ããï¼33 self.__s3_bucket.delete_object(key)34 logging.info(f'Deleted the object `{key}`.')35 continue36 if 'To' not in email:37 self.__s3_bucket.delete_object(key)38 logging.info(f'Deleted the object `{key}`.')39 continue40 if email['To'] != self.__email_address:41 # å®å
ãç°ãªãã¡ã¼ã«ã¯ä»ã®ã¯ãã¼ã©ã«å¯¾ãã¦éããã42 # ã¡ã¼ã«ã®å¯è½æ§ãããã®ã§ç¡è¦ããï¼43 continue44 if date < start_time:45 self.__s3_bucket.delete_object(key)46 logging.info(f'Deleted the object `{key}`.')47 continue48 if target_date is not None and date < target_date:49 self.__s3_bucket.delete_object(key)50 logging.info(f'Deleted the object `{key}`.')51 continue52 if 'From' not in email:53 self.__s3_bucket.delete_object(key)54 logging.info(f'Deleted the object `{key}`.')55 continue56 if email['From'] != 'info@mail.yostar.co.jp':57 self.__s3_bucket.delete_object(key)58 logging.info(f'Deleted the object `{key}`.')59 continue60 if 'Subject' not in email:61 self.__s3_bucket.delete_object(key)62 logging.info(f'Deleted the object `{key}`.')63 continue64 if email['Subject'] != 'Eã¡ã¼ã«ã¢ãã¬ã¹ã®ç¢ºèª':65 self.__s3_bucket.delete_object(key)66 logging.info(f'Deleted the object `{key}`.')67 continue68 target_date = date69 body = email.get_body()70 target_content = body.get_content()71 self.__s3_bucket.delete_object(key)72 logging.info(f'Deleted the object `{key}`.')73 if target_content is None:74 return None75 m = re.search('>(\\d{6})<', target_content)76 if m is None:77 return None78 return m.group(1)79 def get_auth_code(self, *, start_time: datetime.datetime,80 timeout: datetime.timedelta) -> str:81 while True:82 auth_code = self.__get_auth_code(start_time=start_time)83 if auth_code is not None:84 break85 now = datetime.datetime.now(tz=datetime.timezone.utc)...
OrderViewSet.py
Source: OrderViewSet.py
1from rest_framework.viewsets import ModelViewSet2from rest_framework.decorators import action3from rest_framework.response import Response4from repo.models import ShopOrder, ShopRecord,Shop, OrderRecord5from repo.serializers import ShopOrderSerializer, OrderRecordSerializer6from repo.filters import OrderFilter7from rest_framework.filters import OrderingFilter8from django_filters.rest_framework import DjangoFilterBackend9from repo.util import sum_shop10import logging11from .. import filters12import json13log = logging.getLogger(__name__)14class OrderViewSet(ModelViewSet):15 queryset = ShopOrder.objects.all()16 serializer_class = ShopOrderSerializer17 filterset_class = OrderFilter 18 filter_backends = (OrderingFilter, DjangoFilterBackend )19 ordering_fields = ('order_date', 'id')20 def create(self, request):21 data = request.data22 shop_no = data.pop('shop_no')23 shop = Shop.objects.get(shop_no=shop_no)24 ShopOrder.objects.create(shop=shop, order_date=data['order_date'], num=data['num'], material=data.get('material'), remark=data.get('remark')) 25 sum_shop(shop)26 return Response(status=201)27 @action(detail=True, methods=['put'])28 def bring_back(self, request, pk=None):29 #data {30 # "in_num": 131 # "date": "2020-12-06",32 # "remark": "æ "33 #}34 data = request.data35 bring_object = self.get_object()36 bring_object.in_num = bring_object.in_num + data.get('in_num')37# if bring_object.in_num > bring_object.num:38# return Response(status=400, data={"message": "å½è¿çæ°éä¸è½å¤§äºæªå½è¿çæ°é"})39# if bring_object.in_num == bring_object.num:40# bring_object.status = "Done"41 # è®°å½å½è¿ä¿¡æ¯ 42 OrderRecord.objects.create(order=bring_object, num=data.get('in_num'), date=data.get('date'), remark=data.get('remark')) 43 shop = bring_object.shop44 shop.shop_num = shop.shop_num + data.get('in_num')45 bring_object.save()46 shop.save() 47 sum_shop(shop)48 return Response()49 @action(detail=True, methods=['get'])50 def get_comebacks(self, request, pk=None):51 bring_object = self.get_object()52 records = bring_object.orderrecord_set.all()53 serializer = OrderRecordSerializer(records, many=True)54 return Response(serializer.data)55 def destroy(self, request, *args, **kwargs):56 delete_object = self.get_object()57 if delete_object.orderrecord_set.count()>0:58 return Response(status=511, data={"message": "å·²ç»æå½è¿æ°æ®ï¼è¯·å
å é¤å½è¿æ°æ®"})59 delete_object.delete()60 shop = delete_object.shop61 sum_shop(shop) 62 return Response(status=204)63# ç»æ¸
64 @action(detail=True, methods=['put'])65 def change_status(self, request, pk=None):66 data = request.data67 bring_object = self.get_object()68 bring_object.status = data.get('status')69 bring_object.save()70 shop = bring_object.shop71 sum_shop(shop)72 return Response()73class OrderRecordViewSet(ModelViewSet):74 queryset = OrderRecord.objects.all()75 serializer_class = OrderRecordSerializer76 def destroy(self, request, pk=None):77 delete_object = self.get_object()78 order = delete_object.order79 # éè¿æ°éåå°80 order.in_num -= delete_object.num81 shop = order.shop82 # åå°åºåæ°é83 shop.shop_num -= delete_object.num84 order.save()85 shop.save()86 sum_shop(shop)87 delete_object.delete()88 ...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
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!!