How to use response_204 method in Django Test Plus

Best Python code snippet using django-test-plus_python

views.py

Source:views.py Github

copy

Full Screen

1from rest_framework import generics, status2from .serializers import *3from core.models import *4from core.api.filter import *5from rest_framework.response import Response6from core.api.authentication import *7from rest_framework.permissions import IsAuthenticated8from django_filters.rest_framework import DjangoFilterBackend9response_204 = Response({'status': 204, 'description': 'OK'}, status=status.HTTP_204_NO_CONTENT)10response_400 = Response({'status': 400, 'description': 'Bad request.'}, status=status.HTTP_400_BAD_REQUEST)11response_500 = Response({'status': 500, 'description': 'There is an internal issue.'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)12response_200 = Response({'status': 200, 'description': 'OK.'}, status=status.HTTP_200_OK)13class InsertMovie(generics.CreateAPIView):14 permission_classes = (AdminPermission,)15 serializer_class = MovieSerializer16 def post(self, request, *args, **kwargs):17 if set(request.data.keys()) == set(['name', 'description']):18 try:19 Movie.objects.create(name=request.data['name'], description=request.data['description'])20 return response_20421 except: return response_50022 else: return response_40023class ManageMovie(generics.RetrieveUpdateDestroyAPIView):24 serializer_class = MovieSerializer25 permission_classes = (AdminPermission,)26 def put(self, request, *args, **kwargs):27 if set(request.data.keys()) == set(['name', 'description']):28 try:29 Movie.objects.get(id=kwargs['pk'])30 Movie.objects.filter(id=kwargs['pk']).update(name=request.data['name'], description=request.data['description'])31 return response_20432 except: return response_40033 else: return response_40034 def delete(self, request, *args, **kwargs):35 try:36 movie = Movie.objects.get(id=kwargs['pk'])37 movie.delete()38 return response_20439 except: return response_40040class ManageComment(generics.RetrieveUpdateDestroyAPIView):41 serializer_class = CommentSerializerAdmin 42 def put(self, request, *args, **kwargs):43 if set(request.data.keys()) == set(['approved']):44 try:45 Comment.objects.get(id=kwargs['pk'])46 Comment.objects.filter(id=kwargs['pk']).update(approved=request.data['approved'])47 return response_20448 except: return response_40049 else: return response_40050 def delete(self, request, *args, **kwargs):51 try:52 comment = Comment.objects.get(id=kwargs['pk'])53 comment.delete()54 return response_20455 except: return response_40056class UserVote(generics.CreateAPIView):57 serializer_class = VoteSerializer58 permission_classes = (UserPermission,)59 def post(self, request, *args, **kwargs):60 if set(request.data.keys()) == set(['movie_id', 'vote']):61 try:62 Vote.objects.create(rating=request.data['vote'], movie_id=request.data['movie_id'], user=request.user)63 return response_20464 except: return response_50065 else: return response_40066class UserComment(generics.CreateAPIView):67 serializer_class = CommentSerializer68 permission_classes = (UserPermission,)69 def post(self, request, *args, **kwargs):70 if set(request.data.keys()) == set(['movie_id', 'comment_body']):71 try:72 Movie.objects.get(id=request.data['movie_id'])73 Comment.objects.create(comment=request.data['comment_body'], movie_id=request.data['movie_id'], user=request.user)74 return response_20075 except: return response_40076 else: return response_40077class CommentAPI(generics.ListAPIView):78 permission_classes = (AnonymousPermission,)79 filter_backends = [DjangoFilterBackend]80 filter_class = CommentFilter81 serializer_class = GetCommentSerializer82 def get(self, request, *args, **kwargs):83 try:84 mv = Movie.objects.filter(id=request.query_params['movie_id'])85 mv[0]86 except:87 return response_40088 return super().get(request, *args, **kwargs)89 def get_queryset(self):90 try:91 return Comment.objects.filter(movie_id=self.request.query_params['movie_id'])92 except:93 return Comment.objects.none()94class MovieAPI(generics.ListAPIView):95 permission_classes = (AnonymousPermission,)96 serializer_class = GetMovieSerializer97 def get_queryset(self):98 return Movie.objects.all().order_by('id')99class MovieWithIDAPI(generics.ListAPIView):100 permission_classes = (AnonymousPermission,)101 serializer_class = MovieIDSerializer102 def get(self, request, *args, **kwargs):103 try:104 Movie.objects.get(id=kwargs['pk'])105 except:106 return response_400107 return super().get(request, *args, **kwargs)108 def get_queryset(self):...

Full Screen

Full Screen

osidb_api_v1_affects_destroy.py

Source:osidb_api_v1_affects_destroy.py Github

copy

Full Screen

1from typing import Any, Dict, Optional2import requests3from ...client import AuthenticatedClient4from ...models.osidb_api_v1_affects_destroy_response_204 import OsidbApiV1AffectsDestroyResponse2045from ...types import UNSET, Response, Unset6def _get_kwargs(7 uuid: str,8 *,9 client: AuthenticatedClient,10) -> Dict[str, Any]:11 url = "{}/osidb/api/v1/affects/{uuid}".format(12 client.base_url,13 uuid=uuid,14 )15 headers: Dict[str, Any] = client.get_headers()16 return {17 "url": url,18 "headers": headers,19 }20def _parse_response(*, response: requests.Response) -> Optional[OsidbApiV1AffectsDestroyResponse204]:21 if response.status_code == 204:22 _response_204 = response.json()23 response_204: OsidbApiV1AffectsDestroyResponse20424 if isinstance(_response_204, Unset):25 response_204 = UNSET26 else:27 response_204 = OsidbApiV1AffectsDestroyResponse204.from_dict(_response_204)28 return response_20429 return None30def _build_response(*, response: requests.Response) -> Response[OsidbApiV1AffectsDestroyResponse204]:31 return Response(32 status_code=response.status_code,33 content=response.content,34 headers=response.headers,35 parsed=_parse_response(response=response),36 )37def sync_detailed(38 uuid: str,39 *,40 client: AuthenticatedClient,41) -> Response[OsidbApiV1AffectsDestroyResponse204]:42 kwargs = _get_kwargs(43 uuid=uuid,44 client=client,45 )46 response = requests.delete(47 verify=client.verify_ssl,48 auth=client.auth,49 timeout=client.timeout,50 **kwargs,51 )52 response.raise_for_status()53 return _build_response(response=response)54def sync(55 uuid: str,56 *,57 client: AuthenticatedClient,58) -> Optional[OsidbApiV1AffectsDestroyResponse204]:59 """ """60 return sync_detailed(61 uuid=uuid,62 client=client,...

Full Screen

Full Screen

osidb_api_v1_flaws_destroy.py

Source:osidb_api_v1_flaws_destroy.py Github

copy

Full Screen

1from typing import Any, Dict, Optional2import requests3from ...client import AuthenticatedClient4from ...models.osidb_api_v1_flaws_destroy_response_204 import OsidbApiV1FlawsDestroyResponse2045from ...types import UNSET, Response, Unset6def _get_kwargs(7 id: str,8 *,9 client: AuthenticatedClient,10) -> Dict[str, Any]:11 url = "{}/osidb/api/v1/flaws/{id}".format(12 client.base_url,13 id=id,14 )15 headers: Dict[str, Any] = client.get_headers()16 return {17 "url": url,18 "headers": headers,19 }20def _parse_response(*, response: requests.Response) -> Optional[OsidbApiV1FlawsDestroyResponse204]:21 if response.status_code == 204:22 _response_204 = response.json()23 response_204: OsidbApiV1FlawsDestroyResponse20424 if isinstance(_response_204, Unset):25 response_204 = UNSET26 else:27 response_204 = OsidbApiV1FlawsDestroyResponse204.from_dict(_response_204)28 return response_20429 return None30def _build_response(*, response: requests.Response) -> Response[OsidbApiV1FlawsDestroyResponse204]:31 return Response(32 status_code=response.status_code,33 content=response.content,34 headers=response.headers,35 parsed=_parse_response(response=response),36 )37def sync_detailed(38 id: str,39 *,40 client: AuthenticatedClient,41) -> Response[OsidbApiV1FlawsDestroyResponse204]:42 kwargs = _get_kwargs(43 id=id,44 client=client,45 )46 response = requests.delete(47 verify=client.verify_ssl,48 auth=client.auth,49 timeout=client.timeout,50 **kwargs,51 )52 response.raise_for_status()53 return _build_response(response=response)54def sync(55 id: str,56 *,57 client: AuthenticatedClient,58) -> Optional[OsidbApiV1FlawsDestroyResponse204]:59 """ """60 return sync_detailed(61 id=id,62 client=client,...

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 Django Test Plus 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