How to use delete_object method in tempest

Best Python code snippet using tempest_python

RepoViewSet.py

Source:RepoViewSet.py Github

copy

Full Screen

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 ...

Full Screen

Full Screen

yostar_login.py

Source:yostar_login.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

OrderViewSet.py

Source:OrderViewSet.py Github

copy

Full Screen

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 ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful