How to use _is_request_data_valid method in Kiwi

Best Python code snippet using Kiwi_python

views.py

Source:views.py Github

copy

Full Screen

...178 """Clone one case or multiple case into other plan or plans"""179 template_name = "testcases/clone.html"180 http_method_names = ["get", "post"]181 def post(self, request):182 if not self._is_request_data_valid(request):183 return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))184 # Do the clone action185 clone_form = CloneCaseForm(request.POST)186 clone_form.populate(case_ids=request.POST.getlist("case"))187 if clone_form.is_valid():188 for tc_src in clone_form.cleaned_data["case"]:189 tc_dest = tc_src.clone(request.user, clone_form.cleaned_data["plan"])190 # Detect the number of items and redirect to correct one191 if len(clone_form.cleaned_data["case"]) == 1:192 return HttpResponseRedirect(193 reverse(194 "testcases-get",195 args=[196 tc_dest.pk,197 ],198 )199 )200 if len(clone_form.cleaned_data["plan"]) == 1:201 test_plan = clone_form.cleaned_data["plan"][0]202 return HttpResponseRedirect(203 reverse("test_plan_url_short", args=[test_plan.pk])204 )205 # Otherwise tell the user the clone action is successful206 messages.add_message(207 request, messages.SUCCESS, _("TestCase cloning was successful")208 )209 return HttpResponseRedirect(reverse("plans-search"))210 # invalid form211 messages.add_message(request, messages.ERROR, clone_form.errors)212 return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))213 def get(self, request):214 if not self._is_request_data_valid(request, "c"):215 return HttpResponseRedirect(request.META.get("HTTP_REFERER", "/"))216 # account for short param names in URI217 get_params = request.GET.copy()218 get_params.setlist("case", request.GET.getlist("c"))219 del get_params["c"]220 clone_form = CloneCaseForm(get_params)221 clone_form.populate(case_ids=get_params.getlist("case"))222 context = {223 "form": clone_form,224 }225 return render(request, self.template_name, context)226 @staticmethod227 def _is_request_data_valid(request, field_name="case"):228 request_data = getattr(request, request.method)229 if field_name not in request_data:230 messages.add_message(231 request, messages.ERROR, _("At least one TestCase is required")232 )233 return False...

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