Best Python code snippet using Kiwi_python
tests.py
Source:tests.py  
...206            '<input type="text" id="id_name" name="name" value="{}" '207            'class="form-control" required>'.format(self.plan.make_cloned_name()),208            html=True,209        )210    def verify_cloned_plan(self, original_plan, cloned_plan, copy_cases=None):211        self.assertEqual("Copy of {}".format(original_plan.name), cloned_plan.name)212        self.assertEqual(cloned_plan.text, original_plan.text)213        self.assertEqual(Product.objects.get(pk=self.product.pk), cloned_plan.product)214        self.assertEqual(215            Version.objects.get(pk=self.version.pk), cloned_plan.product_version216        )217        self._verify_options(original_plan, cloned_plan, copy_cases)218    def _verify_options(self, original_plan, cloned_plan, copy_cases):219        # number of TCs should always be the same220        self.assertEqual(cloned_plan.cases.count(), original_plan.cases.count())221        # Verify option set_parent222        self.assertEqual(TestPlan.objects.get(pk=original_plan.pk), cloned_plan.parent)223        # Verify option copy_testcases224        for case in cloned_plan.cases.all():225            is_case_linked = TestCasePlan.objects.filter(226                plan=original_plan, case=case227            ).exists()228            if copy_cases:229                # Ensure cases of original plan are not linked to cloned plan230                self.assertFalse(is_case_linked)231                # verify author was updated232                self.assertEqual(self.plan_tester, case.author)233            else:234                self.assertTrue(is_case_linked)235            for original_case, copied_case in zip(236                original_plan.cases.all(), cloned_plan.cases.all()237            ):238                # default tester is always kept239                self.assertEqual(240                    original_case.default_tester, copied_case.default_tester241                )242                if not copy_cases:243                    # when linking TCs author doesn't change244                    self.assertEqual(original_case.author, copied_case.author)245    def test_clone_a_plan_with_default_options(self):246        post_data = {247            "name": self.third_plan.make_cloned_name(),248            "product": self.product.pk,249            "version": self.version.pk,250            "set_parent": "on",251            "submit": "Clone",252        }253        self.client.login(  # nosec:B106:hardcoded_password_funcarg254            username=self.plan_tester.username, password="password"255        )256        response = self.client.post(257            reverse("plans-clone", args=[self.third_plan.pk]), post_data258        )259        cloned_plan = TestPlan.objects.get(name=self.third_plan.make_cloned_name())260        self.assertRedirects(261            response,262            reverse("test_plan_url_short", args=[cloned_plan.pk]),263            target_status_code=HTTPStatus.MOVED_PERMANENTLY,264        )265        self.verify_cloned_plan(self.third_plan, cloned_plan)266    def test_clone_a_plan_by_copying_cases(self):267        post_data = {268            "name": self.totally_new_plan.make_cloned_name(),269            "product": self.product.pk,270            "version": self.version.pk,271            "set_parent": "on",272            "submit": "Clone",273            "copy_testcases": "on",274        }275        self.client.login(  # nosec:B106:hardcoded_password_funcarg276            username=self.plan_tester.username, password="password"277        )278        self.client.post(279            reverse("plans-clone", args=[self.totally_new_plan.pk]), post_data280        )281        cloned_plan = TestPlan.objects.get(282            name=self.totally_new_plan.make_cloned_name()283        )284        self.verify_cloned_plan(self.totally_new_plan, cloned_plan, copy_cases=True)285    def test_clone_a_plan_by_setting_me_to_copied_cases_author_default_tester(self):286        post_data = {287            "name": self.totally_new_plan.make_cloned_name(),288            "product": self.product.pk,289            "version": self.version.pk,290            "set_parent": "on",291            "submit": "Clone",292            "copy_testcases": "on",293        }294        self.client.login(  # nosec:B106:hardcoded_password_funcarg295            username=self.plan_tester.username, password="password"296        )297        self.client.post(298            reverse("plans-clone", args=[self.totally_new_plan.pk]), post_data299        )300        cloned_plan = TestPlan.objects.get(301            name=self.totally_new_plan.make_cloned_name()302        )...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!!
