How to use plan_from_request_or_none method in Kiwi

Best Python code snippet using Kiwi_python

views.py

Source:views.py Github

copy

Full Screen

...17 TestCaseForm,18)19from tcms.testcases.models import Template, TestCase20from tcms.testplans.models import TestPlan21def plan_from_request_or_none(request): # pylint: disable=missing-permission-required22 """Get TestPlan from REQUEST23 This method relies on the existence of from_plan within REQUEST.24 """25 test_plan_id = request.POST.get("from_plan") or request.GET.get("from_plan")26 if not test_plan_id:27 return None28 return get_object_or_404(TestPlan, pk=test_plan_id)29@method_decorator(permission_required("testcases.add_testcase"), name="dispatch")30class NewCaseView(CreateView):31 model = TestCase32 form_class = TestCaseForm33 template_name = "testcases/mutable.html"34 def get_form(self, form_class=None):35 form = super().get_form(form_class)36 # clear fields which are set dynamically via JavaScript37 form.populate(self.request.POST.get("product", -1))38 return form39 def get_form_kwargs(self):40 kwargs = super().get_form_kwargs()41 kwargs["initial"].update( # pylint: disable=objects-update-used42 {43 "author": self.request.user,44 }45 )46 test_plan = plan_from_request_or_none(self.request)47 if test_plan:48 kwargs["initial"]["product"] = test_plan.product_id49 return kwargs50 def get_context_data(self, **kwargs):51 context = super().get_context_data(**kwargs)52 context["test_plan"] = plan_from_request_or_none(self.request)53 context["notify_formset"] = kwargs.get("notify_formset") or CaseNotifyFormSet()54 context["templates"] = Template.objects.all()55 return context56 def form_valid(self, form):57 test_plan = plan_from_request_or_none(self.request)58 notify_formset = CaseNotifyFormSet(self.request.POST)59 if notify_formset.is_valid():60 test_case = form.save()61 if test_plan:62 test_plan.add_case(test_case)63 notify_formset.instance = test_case64 notify_formset.save()65 return HttpResponseRedirect(reverse("testcases-get", args=[test_case.pk]))66 # taken from FormMixin.form_invalid()67 return self.render_to_response(68 self.get_context_data(notify_formset=notify_formset)69 )70@method_decorator(permission_required("testcases.view_testcase"), name="dispatch")71class TestCaseSearchView(TemplateView):...

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