Best Python code snippet using Kiwi_python
test_api.py
Source:test_api.py
...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 = []...
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!!