Best Python code snippet using Kiwi_python
views.py
Source: views.py
...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):...
Check out the latest blogs from LambdaTest on this topic:
Howdy testers! If you’re reading this article I suggest you keep a diary & a pen handy because we’ve added numerous exciting features to our cross browser testing cloud and I am about to share them with you right away!
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.
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!!