Best Python code snippet using slash
test.py
Source:test.py
1from requests import get, post, delete2url = "http://127.0.0.1:5000/api/v2/jobs"3print(get(url).json())4print()5# 'team_leader', 'job', 'work_size', 'collaborators', 'category', 'is_finished'6users = [{ # ÐаÑегоÑии не ÑÑÑеÑÑвÑеÑ7 "job": "РабоÑка",8 "team_leader": "Scott Ridley",9 "work_size": 30,10 "collaborators": "Chastain Jessica",11 "category": "not Standard",12 "is_finished": True,13}, { # ÐидеÑа не ÑÑÑеÑÑвÑеÑ14 "job": "РабоÑка",15 "team_leader": "ÐоÑнейм какой-Ñо",16 "work_size": 30,17 "collaborators": "Chastain Jessica",18 "category": "Standard",19 "is_finished": True,20}, { # Ðе Ñ
ваÑÐ°ÐµÑ Ð¿Ð¾Ð»ÐµÐ¹21 "job": "РабоÑка",22 "team_leader": "Scott Ridley",23 "work_size": 30,24 "is_finished": True,25}, { # ÐÑÑ Ð²ÐµÑно26 "job": "РабоÑка",27 "team_leader": "Scott Ridley",28 "work_size": 30,29 "collaborators": "Chastain Jessica",30 "category": "Standard",31 "is_finished": True,32}]33for user in users:34 print(post(url, json=user).json())35print()36print(get(url).json())37print()38print(delete(url + '/1000').json())39print(delete(url + '/0').json())40print(delete(url + '/hahaha').json())41print(delete(url + '/5').json())42print()43print(get(url).json())44print()45print(get(url + '/0').json())46print(get(url + '/f').json())47print(get(url + '/').json())48print(get(url + '/4').json())49print()50print(get(url).json())51'''52{'jobs': [{'category': 1, 'collaborators': '2, 3', 'is_finished': True, 'job': 'Deployment of residential modules 1 and 2', 'team_leader': 1, 'work_size': 15}, {'category': 1, 'collaborators': '3, 4', 'is_finished': True, 'job': 'Exploration of mineral resources', 'team_leader': 2, 'work_size': 15}, {'category': 1, 'collaborators': '4', 'is_finished': False, 'job': 'Development of a management system', 'team_leader': 4, 'work_size': 24}, {'category': 1, 'collaborators': '1, 2, 4, 5', 'is_finished': True, 'job': 'ÐакаÑ-Ñо ÑабоÑа', 'team_leader': 5, 'work_size': 40}]}53{'message': 'Category "not Standard" is not found'}54{'message': 'User "ÐоÑнейм какой-Ñо" is not found'}55{'message': {'collaborators': 'Missing required parameter in the JSON body or the post body or the query string'}}56{'success': 'OK'}57{'jobs': [{'category': 1, 'collaborators': '2, 3', 'is_finished': True, 'job': 'Deployment of residential modules 1 and 2', 'team_leader': 1, 'work_size': 15}, {'category': 1, 'collaborators': '3, 4', 'is_finished': True, 'job': 'Exploration of mineral resources', 'team_leader': 2, 'work_size': 15}, {'category': 1, 'collaborators': '4', 'is_finished': False, 'job': 'Development of a management system', 'team_leader': 4, 'work_size': 24}, {'category': 1, 'collaborators': '1, 2, 4, 5', 'is_finished': True, 'job': 'ÐакаÑ-Ñо ÑабоÑа', 'team_leader': 5, 'work_size': 40}, {'category': 1, 'collaborators': '3', 'is_finished': True, 'job': 'РабоÑка', 'team_leader': 1, 'work_size': 30}]}58{'message': 'Job #1000 is not found'}59{'message': 'Job #0 is not found'}60{'error': 'Not found'}61{'success': 'OK'}62{'jobs': [{'category': 1, 'collaborators': '2, 3', 'is_finished': True, 'job': 'Deployment of residential modules 1 and 2', 'team_leader': 1, 'work_size': 15}, {'category': 1, 'collaborators': '3, 4', 'is_finished': True, 'job': 'Exploration of mineral resources', 'team_leader': 2, 'work_size': 15}, {'category': 1, 'collaborators': '4', 'is_finished': False, 'job': 'Development of a management system', 'team_leader': 4, 'work_size': 24}, {'category': 1, 'collaborators': '1, 2, 4, 5', 'is_finished': True, 'job': 'ÐакаÑ-Ñо ÑабоÑа', 'team_leader': 5, 'work_size': 40}]}63{'message': 'Job #0 is not found'}64{'error': 'Not found'}65{'error': 'Not found'}66{'jobs': {'category': 1, 'collaborators': '1, 2, 4, 5', 'is_finished': True, 'job': 'ÐакаÑ-Ñо ÑабоÑа', 'team_leader': 5, 'work_size': 40}}67{'jobs': [{'category': 1, 'collaborators': '2, 3', 'is_finished': True, 'job': 'Deployment of residential modules 1 and 2', 'team_leader': 1, 'work_size': 15}, {'category': 1, 'collaborators': '3, 4', 'is_finished': True, 'job': 'Exploration of mineral resources', 'team_leader': 2, 'work_size': 15}, {'category': 1, 'collaborators': '4', 'is_finished': False, 'job': 'Development of a management system', 'team_leader': 4, 'work_size': 24}, {'category': 1, 'collaborators': '1, 2, 4, 5', 'is_finished': True, 'job': 'ÐакаÑ-Ñо ÑабоÑа', 'team_leader': 5, 'work_size': 40}]}...
views.py
Source:views.py
1from django.contrib.auth.models import User2from rest_framework import viewsets, permissions, status3from rest_framework.response import Response4from todoapi.serializers import UserSerializer, TodoSerializer5from todoapi.models import Todo6class UserViewSet(viewsets.ModelViewSet):7 queryset = User.objects.all()8 serializer_class = UserSerializer9 permission_classes = [permissions.IsAuthenticated]10 11class TodoViewSet(viewsets.ModelViewSet):12 """13 API endpoint that allows to-do-list to be view or edited.14 """15 queryset = Todo.objects.all()16 serializer_class = TodoSerializer17 permission_classes = [permissions.IsAuthenticated]18 19 def create(self, request):20 user = request.user21 data = self.request.data22 title = data.get('title', None)23 content = data.get('content', None)24 is_finished = data.get('is_finished', False)25 Todo.objects.create(26 title=title,27 content=content,28 user=user,29 is_finished=is_finished30 )31 return Response(status=status.HTTP_201_CREATED)32 33 def get_queryset(self):34 """35 Filtering againist query parameters36 """37 queryset = Todo.objects.all()38 qp = self.request.query_params39 title = qp.get('title', None)40 user = qp.get('user', None)41 content = qp.get('content', None)42 is_finished = qp.get('is_finished', None)43 created_at = qp.get('created_at', None)44 updated_at = qp.get('updated_at', None)45 # print("query params ::", qp)46 if user is not None:47 queryset = queryset.filter(user=user)48 if title is not None:49 queryset = queryset.filter(title=title)50 if content is not None:51 queryset = queryset.filter(content=content)52 if is_finished is not None:53 is_finished_true_list = ["1", "y", "yes", "t", "true"]54 if is_finished.lower() in is_finished_true_list:55 is_finished = True56 else:57 is_finished = False58 queryset = queryset.filter(is_finished=is_finished)59 if created_at is not None:60 queryset = queryset.filter(created_at=created_at)61 if updated_at is not None:62 queryset = queryset.filter(updated_at=updated_at)...
trigger.py
Source:trigger.py
1from bernard import (2 layers as lyr,3)4from bernard.engine.triggers import (5 BaseTrigger,6)7from .store import (8 cs,9)10class RocketLaunched(BaseTrigger):11 """12 This trigger will determine when the guessing is finished.13 The 'is_finished' parameter allow the trigger to activate to return the guessed frame. 14 We will check the difference between both of the indexes, in order to compare them. 15 When both indexes are in the same place, the guessing is finished. 16 """17 def __init__(self, request, is_finished):18 super().__init__(request)19 self.is_finished = is_finished20 # noinspection PyMethodOverriding21 @cs.inject()22 async def rank(self, context) -> float:23 24 try:25 payload = self.request.get_layer(lyr.Postback).payload26 except (KeyError, ValueError, TypeError):27 return .0 28 # Sanity check29 left_index = context.get('left_index')30 right_index = context.get('right_index')31 if left_index is None or right_index is None:32 return .033 34 if left_index + 1 >= right_index:35 is_finished = True36 print('Finished count')37 else:38 is_finished = False39 print('Unfinished count')...
move_effect.py
Source:move_effect.py
1class MoveEffect:2 def __init__(self, is_finished):3 self.is_finished = is_finished4class AttackEffect(MoveEffect):5 def __init__(self, damage, is_finished):6 super().__init__(is_finished)7 self.damage = damage8class IncreasePowerEffect(MoveEffect):9 def __init__(self, value, is_finished):10 super().__init__(is_finished)11 self.value = value12class IncreaseDefenseEffect(MoveEffect):13 def __init__(self, value, is_finished):14 super().__init__(is_finished)15 self.value = value16class IncreaseHealthEffect(MoveEffect):17 def __init__(self, value, is_finished):18 super().__init__(is_finished)19 self.value = value20class IncreaseManaEffect(MoveEffect):21 def __init__(self, value, is_finished):22 super().__init__(is_finished)...
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!!