How to use _fixture_setup method in Kiwi

Best Python code snippet using Kiwi_python

test_testplan.py

Source:test_testplan.py Github

copy

Full Screen

...13from tcms.tests.factories import (PlanTypeFactory, ProductFactory, TagFactory,14 TestCaseFactory, TestPlanFactory,15 UserFactory, VersionFactory)16class TestFilter(APITestCase):17 def _fixture_setup(self):18 super()._fixture_setup()19 self.product = ProductFactory()20 self.version = VersionFactory(product=self.product)21 self.tester = UserFactory()22 self.plan_type = PlanTypeFactory()23 self.plan_1 = TestPlanFactory(product_version=self.version,24 product=self.product,25 author=self.tester,26 type=self.plan_type)27 self.plan_2 = TestPlanFactory(product_version=self.version,28 product=self.product,29 author=self.tester,30 type=self.plan_type)31 def test_filter_plans(self):32 plans = self.rpc_client.TestPlan.filter({'pk__in': [self.plan_1.pk, self.plan_2.pk]})33 plan = plans[0]34 self.assertEqual(self.plan_1.name, plan['name'])35 self.assertEqual(self.plan_1.product_version.pk, plan['product_version_id'])36 self.assertEqual(self.plan_1.author.pk, plan['author_id'])37 def test_filter_out_all_plans(self):38 plans_total = TestPlan.objects.all().count()39 self.assertEqual(plans_total, len(self.rpc_client.TestPlan.filter()))40 self.assertEqual(plans_total, len(self.rpc_client.TestPlan.filter({})))41class TestAddTag(APITestCase):42 def _fixture_setup(self):43 super()._fixture_setup()44 self.product = ProductFactory()45 self.plans = [46 TestPlanFactory(author=self.api_user, product=self.product),47 TestPlanFactory(author=self.api_user, product=self.product),48 ]49 self.tag1 = TagFactory(name='xmlrpc_test_tag_1')50 self.tag2 = TagFactory(name='xmlrpc_test_tag_2')51 def test_add_tag(self):52 self.rpc_client.TestPlan.add_tag(self.plans[0].pk, self.tag1.name)53 tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists()54 self.assertTrue(tag_exists)55 def test_add_tag_without_permissions(self):56 unauthorized_user = UserFactory()57 unauthorized_user.set_password('api-testing')58 unauthorized_user.save()59 unauthorized_user.user_permissions.add(*Permission.objects.all())60 remove_perm_from_user(unauthorized_user, 'testplans.add_testplantag')61 rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username,62 'api-testing',63 '%s/xml-rpc/' % self.live_server_url).server64 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):65 rpc_client.TestPlan.add_tag(self.plans[0].pk, self.tag1.name)66 # tags were not modified67 tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists()68 self.assertFalse(tag_exists)69class TestRemoveTag(APITestCase):70 def _fixture_setup(self):71 super()._fixture_setup()72 self.product = ProductFactory()73 self.plans = [74 TestPlanFactory(author=self.api_user, product=self.product),75 TestPlanFactory(author=self.api_user, product=self.product),76 ]77 self.tag0 = TagFactory(name='xmlrpc_test_tag_0')78 self.tag1 = TagFactory(name='xmlrpc_test_tag_1')79 self.plans[0].add_tag(self.tag0)80 self.plans[1].add_tag(self.tag1)81 def test_remove_tag(self):82 self.rpc_client.TestPlan.remove_tag(self.plans[0].pk, self.tag0.name)83 tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag0.pk).exists()84 self.assertFalse(tag_exists)85 def test_remove_tag_without_permissions(self):86 unauthorized_user = UserFactory()87 unauthorized_user.set_password('api-testing')88 unauthorized_user.save()89 unauthorized_user.user_permissions.add(*Permission.objects.all())90 remove_perm_from_user(unauthorized_user, 'testplans.delete_testplantag')91 rpc_client = xmlrpc.TCMSXmlrpc(unauthorized_user.username,92 'api-testing',93 '%s/xml-rpc/' % self.live_server_url).server94 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):95 rpc_client.TestPlan.remove_tag(self.plans[0].pk, self.tag0.name)96 # tags were not modified97 tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag0.pk).exists()98 self.assertTrue(tag_exists)99 tag_exists = TestPlan.objects.filter(pk=self.plans[0].pk, tag__pk=self.tag1.pk).exists()100 self.assertFalse(tag_exists)101@override_settings(LANGUAGE_CODE='en')102class TestUpdate(APITestCase):103 def _fixture_setup(self):104 super()._fixture_setup()105 self.plan = TestPlanFactory()106 def test_not_exist_test_plan_id(self):107 err_msg = 'Internal error: TestPlan matching query does not exist.'108 with self.assertRaisesRegex(XmlRPCFault, err_msg):109 self.rpc_client.TestPlan.update(-1, {'text': 'This has been updated'})110 def test_invalid_field_value(self):111 err_msg = 'Select a valid choice. That choice is not one of the available choices.'112 with self.assertRaisesRegex(XmlRPCFault, err_msg):113 self.rpc_client.TestPlan.update(self.plan.pk, {'type': -1})114class TestUpdatePermission(APIPermissionsTestCase):115 permission_label = 'testplans.change_testplan'116 def _fixture_setup(self):117 super()._fixture_setup()118 self.plan = TestPlanFactory()119 def verify_api_with_permission(self):120 self.rpc_client.TestPlan.update(self.plan.pk, {'text': 'This has been updated'})121 # reload from db122 self.plan.refresh_from_db()123 # assert124 self.assertEqual('This has been updated', self.plan.text)125 def verify_api_without_permission(self):126 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):127 self.rpc_client.TestPlan.update(self.plan.pk, {'text': 'This has been updated'})128class TestRemoveCase(APITestCase):129 """ Test the XML-RPC method TestPlan.remove_case() """130 def _fixture_setup(self):131 super()._fixture_setup()132 self.testcase_1 = TestCaseFactory()133 self.testcase_2 = TestCaseFactory()134 self.plan_1 = TestPlanFactory()135 self.plan_2 = TestPlanFactory()136 self.plan_1.add_case(self.testcase_1)137 self.plan_1.add_case(self.testcase_2)138 self.plan_2.add_case(self.testcase_2)139 def test_remove_case_with_single_plan(self):140 self.rpc_client.TestPlan.remove_case(self.plan_1.pk, self.testcase_1.pk)141 self.assertEqual(0, self.testcase_1.plan.count()) # pylint: disable=no-member142 def test_remove_case_with_two_plans(self):143 self.assertEqual(2, self.testcase_2.plan.count()) # pylint: disable=no-member144 self.rpc_client.TestPlan.remove_case(self.plan_1.pk, self.testcase_2.pk)145 self.assertEqual(1, self.testcase_2.plan.count()) # pylint: disable=no-member146class TestAddCase(APITestCase):147 """ Test the XML-RPC method TestPlan.add_case() """148 def _fixture_setup(self):149 super()._fixture_setup()150 self.testcase_1 = TestCaseFactory()151 self.testcase_2 = TestCaseFactory()152 self.testcase_3 = TestCaseFactory()153 self.plan_1 = TestPlanFactory()154 self.plan_2 = TestPlanFactory()155 self.plan_3 = TestPlanFactory()156 # case 1 is already linked to plan 1157 self.plan_1.add_case(self.testcase_1)158 def test_ignores_existing_mappings(self):159 plans = [self.plan_1.pk, self.plan_2.pk, self.plan_3.pk]160 cases = [self.testcase_1.pk, self.testcase_2.pk, self.testcase_3.pk]161 for plan_id in plans:162 for case_id in cases:163 self.rpc_client.TestPlan.add_case(plan_id, case_id)164 # no duplicates for plan1/case1 were created165 self.assertEqual(166 1,167 TestCasePlan.objects.filter(168 plan=self.plan_1.pk,169 case=self.testcase_1.pk170 ).count()171 )172 # verify all case/plan combinations exist173 for plan_id in plans:174 for case_id in cases:175 self.assertEqual(176 1,177 TestCasePlan.objects.filter(178 plan=plan_id,179 case=case_id180 ).count()181 )182@override_settings(LANGUAGE_CODE='en')183class TestCreate(APITestCase):184 def test_create_plan_with_empty_required_field(self):185 product = ProductFactory()186 version = VersionFactory(product=product)187 plan_type = PlanTypeFactory()188 with self.assertRaisesRegex(XmlRPCFault, 'This field is required.'):189 self.rpc_client.TestPlan.create({190 'product': product.pk,191 'product_version': version.pk,192 'name': '',193 'type': plan_type.pk,194 'text': 'Testing TCMS',195 'parent': None,196 })197 def test_create_plan_with_different_user(self):198 product = ProductFactory()199 version = VersionFactory(product=product)200 plan_type = PlanTypeFactory()201 user = UserFactory()202 params = {203 'product': product.pk,204 'product_version': version.pk,205 'name': 'test plan',206 'type': plan_type.pk,207 'text': 'Testing TCMS',208 'parent': None,209 'author': user.pk210 }211 result = self.rpc_client.TestPlan.create(params)212 self.assertEqual(params['product'], result['product_id'])213 self.assertEqual(params['product_version'], result['product_version_id'])214 self.assertEqual(params['name'], result['name'])215 self.assertEqual(params['type'], result['type_id'])216 self.assertEqual(params['text'], result['text'])217 self.assertEqual(params['parent'], result['parent'])218 self.assertEqual(user.username, result['author'])219 self.assertEqual(user.pk, result['author_id'])220class TestCreatePermission(APIPermissionsTestCase):221 permission_label = 'testplans.add_testplan'222 def _fixture_setup(self):223 super()._fixture_setup()224 self.product = ProductFactory()225 self.version = VersionFactory(product=self.product)226 self.plan_type = PlanTypeFactory()227 self.params = {228 'product': self.product.pk,229 'product_version': self.version.pk,230 'name': 'Testplan foobar',231 'type': self.plan_type.pk,232 'text': 'Testing TCMS',233 'parent': None,234 }235 def verify_api_with_permission(self):236 result = self.rpc_client.TestPlan.create(self.params)237 self.assertEqual(self.params['product'], result['product_id'])238 self.assertEqual(self.params['product_version'], result['product_version_id'])239 self.assertEqual(self.params['name'], result['name'])240 self.assertEqual(self.params['type'], result['type_id'])241 self.assertEqual(self.params['text'], result['text'])242 self.assertEqual(self.params['parent'], result['parent'])243 self.assertEqual(self.tester.username, result['author'])244 # verify object from DB245 testplan = TestPlan.objects.get(name=self.params['name'])246 self.assertEqual(testplan.serialize(), result)247 def verify_api_without_permission(self):248 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):249 self.rpc_client.TestPlan.create(self.params)250@override_settings(LANGUAGE_CODE='en')251class TestListAttachments(APITestCase):252 def _fixture_setup(self):253 super()._fixture_setup()254 self.plan = TestPlanFactory()255 def test_list_attachments(self):256 file_name = 'attachment.txt'257 self.rpc_client.TestPlan.add_attachment(self.plan.pk, file_name, 'a2l3aXRjbXM=')258 attachments = self.rpc_client.TestPlan.list_attachments(self.plan.pk)259 self.assertEqual(1, len(attachments))260 def test_list_attachments_with_wrong_plan_id(self):261 with self.assertRaisesRegex(XmlRPCFault, 'TestPlan matching query does not exist'):262 self.rpc_client.TestPlan.list_attachments(-1)263class TestListAttachmentsPermissions(APIPermissionsTestCase):264 permission_label = 'attachments.view_attachment'265 def _fixture_setup(self):266 super()._fixture_setup()267 self.plan = TestPlanFactory()268 def verify_api_with_permission(self):269 attachments = self.rpc_client.TestPlan.list_attachments(self.plan.pk)270 self.assertEqual(0, len(attachments))271 def verify_api_without_permission(self):272 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):273 self.rpc_client.TestPlan.list_attachments(self.plan.pk)274class TestAddAttachmentPermissions(APIPermissionsTestCase):275 permission_label = 'attachments.add_attachment'276 def _fixture_setup(self):277 super()._fixture_setup()278 self.plan = TestPlanFactory()279 def verify_api_with_permission(self):280 file_name = 'attachment.txt'281 self.rpc_client.TestPlan.add_attachment(self.plan.pk, file_name, 'a2l3aXRjbXM=')282 attachments = Attachment.objects.attachments_for_object(self.plan)283 self.assertEqual(1, len(attachments))284 attachment = attachments[0]285 file_url = attachment.attachment_file.url286 self.assertTrue(file_url.startswith('/uploads/attachments/testplans_testplan/'))287 self.assertTrue(file_url.endswith(file_name))288 def verify_api_without_permission(self):289 with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):...

Full Screen

Full Screen

test_api.py

Source:test_api.py Github

copy

Full Screen

...12from tcms.tests.factories import TagFactory # noqa: E40213class TestAddTagPermissions(APIPermissionsTestCase):14 """Test Bug.add_tag"""15 permission_label = "bugs.add_bug_tags"16 def _fixture_setup(self):17 super()._fixture_setup()18 self.bug = BugFactory()19 self.tag = TagFactory()20 def verify_api_with_permission(self):21 self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name)22 self.assertIn(self.tag, self.bug.tags.all())23 def verify_api_without_permission(self):24 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):25 self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name)26class TestAddTag(APITestCase):27 """Test Bug.add_tag"""28 def _fixture_setup(self):29 super()._fixture_setup()30 self.bug = BugFactory()31 self.tag = TagFactory()32 def test_add_tag_to_non_existent_bug(self):33 with self.assertRaisesRegex(XmlRPCFault, 'Bug matching query does not exist'):34 self.rpc_client.Bug.add_tag(-9, self.tag.name)35class TestRemoveTagPermissions(APIPermissionsTestCase):36 """Test Bug.remove_tag"""37 permission_label = "bugs.delete_bug_tags"38 def _fixture_setup(self):39 super()._fixture_setup()40 self.bug = BugFactory()41 self.tag = TagFactory()42 self.bug.tags.add(self.tag)43 def verify_api_with_permission(self):44 self.rpc_client.Bug.remove_tag(self.bug.pk, self.tag.name)45 self.assertNotIn(self.tag, self.bug.tags.all())46 def verify_api_without_permission(self):47 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):48 self.rpc_client.Bug.remove_tag(self.bug.pk, self.tag.name)49class TestRemovePermissions(APIPermissionsTestCase):50 """Test permissions of Bug.remove"""51 permission_label = "bugs.delete_bug"52 def _fixture_setup(self):53 super()._fixture_setup()54 self.bug = BugFactory()55 self.another_bug = BugFactory()56 self.yet_another_bug = BugFactory()57 def verify_api_with_permission(self):58 self.rpc_client.Bug.remove({"pk__in": [self.bug.pk, self.another_bug.pk]})59 bugs = Bug.objects.all()60 self.assertNotIn(self.bug, bugs)61 self.assertNotIn(self.another_bug, bugs)62 self.assertIn(self.yet_another_bug, bugs)63 def verify_api_without_permission(self):64 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):65 self.rpc_client.Bug.remove({"pk__in": [self.bug.pk, self.another_bug.pk]})66class TestFilter(APITestCase):67 """Test Bug.filter"""68 def _fixture_setup(self):69 super()._fixture_setup()70 self.bug = BugFactory(status=False)71 self.another_bug = BugFactory(status=True)72 self.yet_another_bug = BugFactory(status=True)73 def test_filter(self):74 result = self.rpc_client.Bug.filter({"status": True})75 self.assertIsInstance(result, list)76 self.assertEqual(len(result), 2)77 pks = []78 for item in result:79 pks.append(item["pk"])80 self.assertNotIn(self.bug.pk, pks)81 self.assertIn(self.another_bug.pk, pks)82 self.assertIn(self.yet_another_bug.pk, pks)83 def test_filter_non_existing(self):...

Full Screen

Full Screen

testcases.py

Source:testcases.py Github

copy

Full Screen

...25 class MyTestCase(TransactionTestCase, NonFlushingTransactionTestCaseMixin):26 Source:27 https://github.com/brightinteractive/django-test-extras/blob/master/test_extras/testcases.py28 """29 def _fixture_setup(self):30 """31 Overrides TransactionTestCase._fixture_setup() and replaces the flush32 command with a dummy command whilst it is running to prevent it from33 flushing the database.34 """35 with SkipFlushCommand():36 super(NonFlushingTransactionTestCaseMixin, self)._fixture_setup()37 def _fixture_teardown(self):38 with SkipFlushCommand():...

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