How to use test_invalid_testcase_id method in Kiwi

Best Python code snippet using Kiwi_python

test_testcase.py

Source:test_testcase.py Github

copy

Full Screen

...50 self.rpc_client.TestCase.add_notification_cc(51 self.testcase.pk, [self.default_cc]52 )53class TestAddNotificationCC(APITestCase):54 def test_invalid_testcase_id(self):55 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):56 self.rpc_client.TestCase.add_notification_cc(-1, ["example@example.com"])57class TestGetNotificationCCPermission(APIPermissionsTestCase):58 permission_label = "testcases.view_testcase"59 def _fixture_setup(self):60 super()._fixture_setup()61 self.default_cc = "example@example.com"62 self.testcase = TestCaseFactory()63 self.testcase.emailing.add_cc(self.default_cc)64 def verify_api_with_permission(self):65 result = self.rpc_client.TestCase.get_notification_cc(self.testcase.pk)66 self.assertListEqual(result, [self.default_cc])67 def verify_api_without_permission(self):68 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):69 self.rpc_client.TestCase.get_notification_cc(self.testcase.pk)70class TestGetNotificationCC(APITestCase):71 def test_invalid_testcase_id(self):72 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):73 self.rpc_client.TestCase.get_notification_cc(-1)74class TestRemoveNotificationCCPermission(APIPermissionsTestCase):75 permission_label = "testcases.change_testcase"76 def _fixture_setup(self):77 super()._fixture_setup()78 self.default_cc = "example@example.com"79 self.testcase = TestCaseFactory()80 self.testcase.emailing.add_cc(self.default_cc)81 def verify_api_with_permission(self):82 self.rpc_client.TestCase.remove_notification_cc(83 self.testcase.pk, [self.default_cc]84 )85 self.testcase.emailing.refresh_from_db()86 self.assertEqual([], self.testcase.emailing.get_cc_list())87 def verify_api_without_permission(self):88 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):89 self.rpc_client.TestCase.remove_notification_cc(90 self.testcase.pk, [self.default_cc]91 )92class TestRemoveNotificationCC(APITestCase):93 def test_invalid_testcase_id(self):94 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):95 self.rpc_client.TestCase.remove_notification_cc(-1, ["example@example.com"])96class TestCaseFilter(APITestCase):97 def _fixture_setup(self):98 super()._fixture_setup()99 self.tester = UserFactory(username="great tester")100 self.product = ProductFactory(name="StarCraft")101 self.version = VersionFactory(value="0.1", product=self.product)102 self.plan = TestPlanFactory(103 name="Test product.get_cases",104 author=self.tester,105 product=self.product,106 product_version=self.version,107 )108 self.case_category = CategoryFactory(product=self.product)109 self.cases_count = 10110 self.cases = []111 for _ in range(self.cases_count):112 test_case = TestCaseFactory(113 category=self.case_category,114 author=self.tester,115 reviewer=self.tester,116 default_tester=None,117 plan=[self.plan],118 )119 self.cases.append(test_case)120 def test_filter_query_none(self):121 result = self.rpc_client.TestCase.filter()122 self.assertIsNotNone(result)123 self.assertGreater(len(result), 0)124 self.assertIn("id", result[0])125 self.assertIn("create_date", result[0])126 self.assertIn("is_automated", result[0])127 self.assertIn("script", result[0])128 self.assertIn("arguments", result[0])129 self.assertIn("extra_link", result[0])130 self.assertIn("summary", result[0])131 self.assertIn("requirement", result[0])132 self.assertIn("notes", result[0])133 self.assertIn("text", result[0])134 self.assertIn("case_status", result[0])135 self.assertIn("category", result[0])136 self.assertIn("priority", result[0])137 self.assertIn("author", result[0])138 self.assertIn("default_tester", result[0])139 self.assertIn("reviewer", result[0])140 self.assertIn("setup_duration", result[0])141 self.assertIn("testing_duration", result[0])142 self.assertIn("expected_duration", result[0])143 def test_filter_by_product_id(self):144 cases = self.rpc_client.TestCase.filter({"category__product": self.product.pk})145 self.assertIsNotNone(cases)146 self.assertEqual(len(cases), self.cases_count)147 @parameterized.expand(148 [149 ("both_values_are_not_set", {}, None, None, 0),150 (151 "setup_duration_is_not_set",152 {"testing_duration": timedelta(minutes=5)},153 None,154 300,155 300,156 ),157 (158 "testing_duration_is_not_set",159 {"setup_duration": timedelta(seconds=45)},160 45,161 None,162 45,163 ),164 (165 "both_values_are_set",166 {167 "setup_duration": timedelta(seconds=45),168 "testing_duration": timedelta(minutes=5),169 },170 45,171 300,172 345,173 ),174 ]175 )176 def test_duration_properties_in_result(177 self, _name, init_dict, setup_duration, testing_duration, expected_duration178 ):179 testcase = TestCaseFactory(**init_dict)180 result = self.rpc_client.TestCase.filter({"pk": testcase.pk})181 self.assertIsNotNone(result)182 self.assertEqual(result[0]["setup_duration"], setup_duration)183 self.assertEqual(result[0]["testing_duration"], testing_duration)184 self.assertEqual(result[0]["expected_duration"], expected_duration)185class TestUpdate(APITestCase):186 non_existing_username = "FakeUsername"187 non_existing_user_id = 999188 non_existing_email = "fake@email.com"189 def _fixture_setup(self):190 super()._fixture_setup()191 self.testcase = TestCaseFactory(192 summary="Sanity test case", text="Given-When-Then", default_tester=None193 )194 self.new_author = UserFactory()195 def test_update_text_and_product(self):196 author_pk = self.testcase.author.pk197 self.assertEqual("Sanity test case", self.testcase.summary)198 self.assertEqual("Given-When-Then", self.testcase.text)199 # update the test case200 result = self.rpc_client.TestCase.update( # pylint: disable=objects-update-used201 self.testcase.pk,202 {203 "setup_duration": "1 10:00:00",204 "summary": "This was updated",205 "testing_duration": "00:01:00",206 "text": "new TC text",207 },208 )209 self.testcase.refresh_from_db()210 self.assertEqual(result["id"], self.testcase.pk)211 self.assertEqual("This was updated", self.testcase.summary)212 self.assertEqual("new TC text", self.testcase.text)213 # FK for author not passed above. Make sure it didn't change!214 self.assertEqual(author_pk, self.testcase.author.pk)215 self.assertIn("author", result)216 self.assertIn("create_date", result)217 self.assertIn("is_automated", result)218 self.assertIn("script", result)219 self.assertIn("arguments", result)220 self.assertIn("extra_link", result)221 self.assertIn("summary", result)222 self.assertIn("requirement", result)223 self.assertIn("notes", result)224 self.assertIn("setup_duration", result)225 self.assertIn("testing_duration", result)226 self.assertEqual(result["text"], self.testcase.text)227 self.assertEqual(result["case_status"], self.testcase.case_status.pk)228 self.assertEqual(result["category"], self.testcase.category.pk)229 self.assertEqual(result["priority"], self.testcase.priority.pk)230 self.assertEqual(str(self.testcase.setup_duration), "1 day, 10:00:00")231 self.assertEqual(self.testcase.testing_duration, timedelta(minutes=1))232 self.assertIn("default_tester", result)233 self.assertIn("reviewer", result)234 def test_update_author_issue_630(self):235 self.assertNotEqual(self.new_author, self.testcase.author)236 # update the test case237 updated = (238 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used239 self.testcase.pk,240 {241 "author": self.new_author.pk,242 },243 )244 )245 self.testcase.refresh_from_db()246 self.assertEqual(self.new_author, self.testcase.author)247 self.assertEqual(self.new_author.pk, updated["author"])248 def test_update_author_should_fail_for_non_existing_user_id(self):249 initial_author_id = self.testcase.author.pk250 with self.assertRaises(Fault):251 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used252 self.testcase.pk,253 {254 "author": self.non_existing_user_id,255 },256 )257 self.testcase.refresh_from_db()258 self.assertEqual(initial_author_id, self.testcase.author.pk)259 def test_update_author_accepts_username(self):260 self.assertNotEqual(self.new_author, self.testcase.author)261 # update the test case262 updated = (263 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used264 self.testcase.pk,265 {266 "author": self.new_author.username,267 },268 )269 )270 self.testcase.refresh_from_db()271 self.assertEqual(self.new_author, self.testcase.author)272 self.assertEqual(self.new_author.pk, updated["author"])273 def test_update_author_should_fail_for_non_existing_username(self):274 initial_author_username = self.testcase.author.username275 with self.assertRaises(Fault):276 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used277 self.testcase.pk,278 {279 "author": self.non_existing_username,280 },281 )282 self.testcase.refresh_from_db()283 self.assertEqual(initial_author_username, self.testcase.author.username)284 def test_update_author_accepts_email(self):285 self.assertNotEqual(self.new_author, self.testcase.author)286 # update the test case287 updated = (288 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used289 self.testcase.pk,290 {291 "author": self.new_author.email,292 },293 )294 )295 self.testcase.refresh_from_db()296 self.assertEqual(self.new_author, self.testcase.author)297 self.assertEqual(self.new_author.pk, updated["author"])298 def test_update_author_should_fail_for_non_existing_email(self):299 initial_author_email = self.testcase.author.email300 with self.assertRaises(Fault):301 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used302 self.testcase.pk,303 {304 "author": self.non_existing_email,305 },306 )307 self.testcase.refresh_from_db()308 self.assertEqual(initial_author_email, self.testcase.author.email)309 def test_update_priority_issue_1318(self):310 expected_priority = Priority.objects.exclude(311 pk=self.testcase.priority.pk312 ).first()313 self.assertNotEqual(expected_priority.pk, self.testcase.priority.pk)314 self.assertEqual("Sanity test case", self.testcase.summary)315 self.assertEqual("Given-When-Then", self.testcase.text)316 # update the test case317 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used318 self.testcase.pk,319 {320 "priority": expected_priority.pk,321 },322 )323 self.testcase.refresh_from_db()324 # priority has changed325 self.assertEqual(expected_priority.pk, self.testcase.priority.pk)326 # but nothing else changed, issue #1318327 self.assertEqual("Sanity test case", self.testcase.summary)328 self.assertEqual("Given-When-Then", self.testcase.text)329 def test_update_default_tester_accepts_user_id(self):330 self.assertIsNone(self.testcase.default_tester)331 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used332 self.testcase.pk,333 {334 "default_tester": self.new_author.pk,335 },336 )337 self.testcase.refresh_from_db()338 self.assertEqual(self.new_author.pk, self.testcase.default_tester.pk)339 def test_update_default_tester_should_fail_with_non_existing_user_id(self):340 self.assertIsNone(self.testcase.default_tester)341 with self.assertRaises(Fault):342 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used343 self.testcase.pk,344 {345 "default_tester": self.non_existing_user_id,346 },347 )348 self.testcase.refresh_from_db()349 self.assertIsNone(self.testcase.default_tester)350 def test_update_default_tester_accepts_username(self):351 self.assertIsNone(self.testcase.default_tester)352 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used353 self.testcase.pk,354 {355 "default_tester": self.new_author.username,356 },357 )358 self.testcase.refresh_from_db()359 self.assertEqual(self.new_author.pk, self.testcase.default_tester.pk)360 def test_update_default_tester_should_fail_with_non_existing_username(self):361 self.assertIsNone(self.testcase.default_tester)362 with self.assertRaises(Fault):363 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used364 self.testcase.pk,365 {366 "default_tester": self.non_existing_username,367 },368 )369 self.testcase.refresh_from_db()370 self.assertIsNone(self.testcase.default_tester)371 def test_update_default_tester_accepts_email(self):372 self.assertIsNone(self.testcase.default_tester)373 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used374 self.testcase.pk,375 {376 "default_tester": self.new_author.email,377 },378 )379 self.testcase.refresh_from_db()380 self.assertEqual(self.new_author.pk, self.testcase.default_tester.pk)381 def test_update_default_tester_should_fail_with_non_existing_email(self):382 self.assertIsNone(self.testcase.default_tester)383 with self.assertRaises(Fault):384 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used385 self.testcase.pk,386 {387 "default_tester": self.non_existing_email,388 },389 )390 self.testcase.refresh_from_db()391 self.assertIsNone(self.testcase.default_tester)392 def test_update_reviewer_accepts_user_id(self):393 self.assertNotEqual(self.new_author, self.testcase.reviewer)394 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used395 self.testcase.pk,396 {397 "reviewer": self.new_author.pk,398 },399 )400 self.testcase.refresh_from_db()401 self.assertEqual(self.new_author.pk, self.testcase.reviewer.pk)402 def test_update_reviewer_should_fail_with_non_existing_user_id(self):403 initial_reviewer_id = self.testcase.reviewer.pk404 with self.assertRaises(Fault):405 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used406 self.testcase.pk,407 {408 "reviewer": self.non_existing_user_id,409 },410 )411 self.testcase.refresh_from_db()412 self.assertEqual(initial_reviewer_id, self.testcase.reviewer.pk)413 def test_update_reviewer_accepts_username(self):414 self.assertNotEqual(self.new_author, self.testcase.reviewer)415 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used416 self.testcase.pk,417 {418 "reviewer": self.new_author.username,419 },420 )421 self.testcase.refresh_from_db()422 self.assertEqual(self.new_author, self.testcase.reviewer)423 def test_update_reviewer_should_fail_for_non_existing_username(self):424 initial_reviewer_username = self.testcase.reviewer.username425 with self.assertRaises(Fault):426 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used427 self.testcase.pk,428 {429 "reviewer": self.non_existing_username,430 },431 )432 self.testcase.refresh_from_db()433 self.assertEqual(initial_reviewer_username, self.testcase.reviewer.username)434 def test_update_reviewer_accepts_email(self):435 self.assertNotEqual(self.new_author, self.testcase.author)436 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used437 self.testcase.pk,438 {439 "reviewer": self.new_author.email,440 },441 )442 self.testcase.refresh_from_db()443 self.assertEqual(self.new_author, self.testcase.reviewer)444 def test_update_reviewer_should_fail_for_non_existing_email(self):445 initial_reviewer_email = self.testcase.reviewer.email446 with self.assertRaises(Fault):447 self.rpc_client.TestCase.update( # pylint: disable=objects-update-used448 self.testcase.pk,449 {450 "reviewer": self.non_existing_email,451 },452 )453 self.testcase.refresh_from_db()454 self.assertEqual(initial_reviewer_email, self.testcase.reviewer.email)455class TestCreate(APITestCase):456 def _fixture_setup(self):457 super()._fixture_setup()458 for _ in range(5):459 CategoryFactory()460 def test_passes_with_valid_data(self):461 result = self.rpc_client.TestCase.create(462 {463 "summary": "Newly created TC via API",464 "text": "Given-When-Then",465 "case_status": TestCaseStatus.objects.first().pk,466 "priority": Priority.objects.first().pk,467 "category": Category.objects.first().pk,468 "setup_duration": "2 20:10:00",469 "testing_duration": "00:00:30",470 }471 )472 tc_from_db = TestCase.objects.get(473 summary=result["summary"], text=result["text"]474 )475 self.assertEqual(result["id"], tc_from_db.pk)476 # author field is auto-configured if not passed477 self.assertEqual(result["author"], tc_from_db.author.pk)478 self.assertEqual(self.api_user, tc_from_db.author)479 self.assertIn("arguments", result)480 self.assertIn("create_date", result)481 self.assertIn("default_tester", result)482 self.assertIn("extra_link", result)483 self.assertIn("is_automated", result)484 self.assertIn("notes", result)485 self.assertIn("requirement", result)486 self.assertIn("reviewer", result)487 self.assertIn("script", result)488 self.assertIn("setup_duration", result)489 self.assertIn("testing_duration", result)490 self.assertEqual(result["case_status"], tc_from_db.case_status.pk)491 self.assertEqual(result["category"], tc_from_db.category.pk)492 self.assertEqual(result["priority"], tc_from_db.priority.pk)493 self.assertEqual(result["summary"], tc_from_db.summary)494 self.assertEqual(result["text"], tc_from_db.text)495 self.assertEqual(str(tc_from_db.setup_duration), "2 days, 20:10:00")496 self.assertEqual(tc_from_db.testing_duration, timedelta(seconds=30))497 def test_author_can_be_specified(self):498 new_author = UserFactory()499 result = self.rpc_client.TestCase.create(500 {501 "summary": "TC via API with author",502 "case_status": TestCaseStatus.objects.last().pk,503 "priority": Priority.objects.last().pk,504 "category": Category.objects.last().pk,505 "author": new_author.pk,506 }507 )508 tc_from_db = TestCase.objects.get(summary=result["summary"], author=new_author)509 self.assertEqual(result["id"], tc_from_db.pk)510 self.assertEqual(new_author, tc_from_db.author)511 def test_fails_when_mandatory_fields_not_specified(self):512 with self.assertRaises(Fault):513 self.rpc_client.TestCase.create(514 {515 "summary": "TC via API without mandatory FK fields",516 }517 )518class TestRemovePermissions(APIPermissionsTestCase):519 permission_label = "testcases.delete_testcase"520 def _fixture_setup(self):521 super()._fixture_setup()522 self.case_1 = TestCaseFactory()523 self.case_2 = TestCaseFactory()524 self.case_3 = TestCaseFactory()525 self.query = {"pk__in": [self.case_1.pk, self.case_2.pk, self.case_3.pk]}526 def verify_api_with_permission(self):527 num_deleted, _ = self.rpc_client.TestCase.remove(self.query)528 self.assertEqual(num_deleted, 3)529 def verify_api_without_permission(self):530 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):531 self.rpc_client.TestCase.remove(self.query)532class TestAddTag(APITestCase):533 def _fixture_setup(self):534 super()._fixture_setup()535 self.testcase = TestCaseFactory()536 self.tag1 = TagFactory()537 self.tag2 = TagFactory()538 def test_add_tag(self):539 self.rpc_client.TestCase.add_tag(self.testcase.pk, self.tag1.name)540 tag_exists = TestCase.objects.filter(541 pk=self.testcase.pk, tag__pk=self.tag1.pk542 ).exists()543 self.assertTrue(tag_exists)544 def test_add_tag_without_permissions(self):545 unauthorized_user = UserFactory()546 unauthorized_user.set_password("api-testing")547 unauthorized_user.save()548 unauthorized_user.user_permissions.add(*Permission.objects.all())549 remove_perm_from_user(unauthorized_user, "testcases.add_testcasetag")550 rpc_client = xmlrpc.TCMSXmlrpc(551 unauthorized_user.username,552 "api-testing",553 f"{self.live_server_url}/xml-rpc/",554 ).server555 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):556 rpc_client.TestCase.add_tag(self.testcase.pk, self.tag1.name)557 # tags were not modified558 tag_exists = TestCase.objects.filter(559 pk=self.testcase.pk, tag__pk=self.tag1.pk560 ).exists()561 self.assertFalse(tag_exists)562class TestRemoveTag(APITestCase):563 def _fixture_setup(self):564 super()._fixture_setup()565 self.tag0 = TagFactory()566 self.tag1 = TagFactory()567 self.testcase = TestCaseFactory()568 self.testcase.add_tag(self.tag0)569 def test_remove_tag(self):570 self.rpc_client.TestCase.remove_tag(self.testcase.pk, self.tag0.name)571 tag_exists = TestCase.objects.filter(572 pk=self.testcase.pk, tag__pk=self.tag0.pk573 ).exists()574 self.assertFalse(tag_exists)575 def test_remove_tag_without_permissions(self):576 unauthorized_user = UserFactory()577 unauthorized_user.set_password("api-testing")578 unauthorized_user.save()579 unauthorized_user.user_permissions.add(*Permission.objects.all())580 remove_perm_from_user(unauthorized_user, "testcases.delete_testcasetag")581 rpc_client = xmlrpc.TCMSXmlrpc(582 unauthorized_user.username,583 "api-testing",584 f"{self.live_server_url}/xml-rpc/",585 ).server586 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):587 rpc_client.TestCase.remove_tag(self.testcase.pk, self.tag0.name)588 # tags were not modified589 tag_exists = TestCase.objects.filter(590 pk=self.testcase.pk, tag__pk=self.tag0.pk591 ).exists()592 self.assertTrue(tag_exists)593 tag_exists = TestCase.objects.filter(594 pk=self.testcase.pk, tag__pk=self.tag1.pk595 ).exists()596 self.assertFalse(tag_exists)597class TestAddComponent(APITestCase):598 def _fixture_setup(self):599 super()._fixture_setup()600 self.test_case = TestCaseFactory()601 self.good_component = ComponentFactory(product=self.test_case.category.product)602 self.bad_component = ComponentFactory()603 def test_add_component_from_same_product_is_allowed(self):604 result = self.rpc_client.TestCase.add_component(605 self.test_case.pk, self.good_component.name606 )607 self.assertEqual(result["id"], self.good_component.pk)608 self.assertEqual(result["name"], self.good_component.name)609 def test_add_component_from_another_product_is_not_allowed(self):610 with self.assertRaisesRegex(Fault, "Component matching query does not exist"):611 self.rpc_client.TestCase.add_component(612 self.test_case.pk, self.bad_component.name613 )614class TestRemoveComponentPermission(APIPermissionsTestCase):615 permission_label = "testcases.delete_testcasecomponent"616 def _fixture_setup(self):617 super()._fixture_setup()618 self.test_case = TestCaseFactory()619 self.good_component = ComponentFactory(product=self.test_case.category.product)620 self.bad_component = ComponentFactory(product=self.test_case.category.product)621 self.test_case.add_component(self.good_component)622 self.test_case.add_component(self.bad_component)623 def verify_api_with_permission(self):624 self.rpc_client.TestCase.remove_component(625 self.test_case.pk, self.bad_component.pk626 )627 result = self.test_case.component628 self.assertEqual(result.count(), 1)629 self.assertEqual(result.first(), self.good_component)630 def verify_api_without_permission(self):631 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):632 self.rpc_client.TestCase.remove_component(633 self.test_case.pk, self.good_component.pk634 )635class TestRemoveComponent(APITestCase):636 def test_invalid_testcase_id(self):637 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):638 self.rpc_client.TestCase.remove_component(-1, -1)639class TestAddCommentPermissions(APIPermissionsTestCase):640 permission_label = "django_comments.add_comment"641 def _fixture_setup(self):642 super()._fixture_setup()643 self.case = TestCaseFactory()644 def verify_api_with_permission(self):645 created_comment = self.rpc_client.TestCase.add_comment(646 self.case.pk, "Hello World!"647 )648 result = comments.get_comments(self.case)649 self.assertEqual(1, result.count())650 first_comment = result.first()651 self.assertEqual("Hello World!", first_comment.comment)652 self.assertEqual("Hello World!", created_comment["comment"])653 def verify_api_without_permission(self):654 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):655 self.rpc_client.TestCase.add_comment(self.case.pk, "Hello World!")656class TestAddComment(APITestCase):657 def test_invalid_testcase_id(self):658 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):659 self.rpc_client.TestCase.add_comment(-1, "Hello World!")660class TestRemoveCommentPermissions(APIPermissionsTestCase):661 permission_label = "django_comments.delete_comment"662 def _fixture_setup(self):663 super()._fixture_setup()664 self.case = TestCaseFactory()665 self.comment_1 = comments.add_comment([self.case], "First one", self.tester)[0]666 self.comment_2 = comments.add_comment([self.case], "Second one", self.tester)[0]667 self.comment_3 = comments.add_comment([self.case], "Third one", self.tester)[0]668 def verify_api_with_permission(self):669 # Remove a specific comment670 self.rpc_client.TestCase.remove_comment(self.case.pk, self.comment_1.pk)671 self.assertEqual(len(comments.get_comments(self.case)), 2)672 # Remove all comments673 self.rpc_client.TestCase.remove_comment(self.case.pk)674 self.assertEqual(len(comments.get_comments(self.case)), 0)675 def verify_api_without_permission(self):676 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):677 self.rpc_client.TestCase.remove_comment(self.case.pk)678class TestRemoveComment(APITestCase):679 def test_invalid_testcase_id(self):680 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):681 self.rpc_client.TestCase.remove_comment(-1)682class TestCaseSortkeysPermissions(APIPermissionsTestCase):683 permission_label = "testcases.view_testcase"684 def _fixture_setup(self):685 super()._fixture_setup()686 self.plan = TestPlanFactory()687 # add TCs with non-standard sortkeys688 self.case_1 = TestCaseFactory()689 self.plan.add_case(self.case_1, sortkey=5)690 self.case_2 = TestCaseFactory()691 self.plan.add_case(self.case_2, sortkey=15)692 self.case_3 = TestCaseFactory()693 self.plan.add_case(self.case_3, sortkey=25)694 def verify_api_with_permission(self):695 result = self.rpc_client.TestCase.sortkeys(696 {697 "plan": self.plan.pk,698 }699 )700 # note: keys are of type str()701 self.assertEqual(result[str(self.case_1.pk)], 5)702 self.assertEqual(result[str(self.case_2.pk)], 15)703 self.assertEqual(result[str(self.case_3.pk)], 25)704 # Test query None705 result = self.rpc_client.TestCase.sortkeys()706 self.assertIsNotNone(result)707 self.assertGreater(len(result), 0)708 def verify_api_without_permission(self):709 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):710 self.rpc_client.TestCase.sortkeys(711 {712 "plan": self.plan.pk,713 }714 )715class TestCaseCommentPermissions(APIPermissionsTestCase):716 permission_label = "django_comments.view_comment"717 def _fixture_setup(self):718 super()._fixture_setup()719 self.case = TestCaseFactory()720 comments.add_comment([self.case], "First one", self.tester)721 comments.add_comment([self.case], "Second one", self.tester)722 def verify_api_with_permission(self):723 result = self.rpc_client.TestCase.comments(self.case.pk)724 self.assertEqual(2, len(result))725 # also takes case to verify functionality b/c the target726 # method under test is very simple727 self.assertEqual(result[0]["comment"], "First one")728 self.assertEqual(result[1]["comment"], "Second one")729 for entry in result:730 self.assertEqual(entry["object_pk"], str(self.case.pk))731 self.assertEqual(entry["user"], self.tester.pk)732 self.assertEqual(entry["user_name"], self.tester.username)733 def verify_api_without_permission(self):734 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):735 self.rpc_client.TestCase.comments(self.case.pk)736class TestAddAttachmentPermissions(APIPermissionsTestCase):737 permission_label = "attachments.add_attachment"738 def _fixture_setup(self):739 super()._fixture_setup()740 self.case = TestCaseFactory()741 def verify_api_with_permission(self):742 self.rpc_client.TestCase.add_attachment(743 self.case.pk, "test.txt", "a2l3aXRjbXM="744 )745 attachments = Attachment.objects.attachments_for_object(self.case)746 self.assertEqual(len(attachments), 1)747 self.assertEqual(attachments[0].object_id, str(self.case.pk))748 def verify_api_without_permission(self):749 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):750 self.rpc_client.TestCase.add_attachment(751 self.case.pk, "test.txt", "a2l3aXRjbXM="752 )753class TestListAttachments(APITestCase):754 def _fixture_setup(self):755 super()._fixture_setup()756 self.case = TestCaseFactory()757 def test_list_attachments(self):758 self.rpc_client.TestCase.add_attachment(759 self.case.pk, "attachment.txt", "a2l3aXRjbXM="760 )761 attachments = self.rpc_client.TestCase.list_attachments(self.case.pk)762 self.assertEqual(len(attachments), 1)763 def test_invalid_testcase_id(self):764 with self.assertRaisesRegex(Fault, "TestCase matching query does not exist"):765 self.rpc_client.TestCase.list_attachments(-1)766class TestListAttachmentPermissions(APIPermissionsTestCase):767 permission_label = "attachments.view_attachment"768 def _fixture_setup(self):769 super()._fixture_setup()770 self.case = TestCaseFactory()771 def verify_api_with_permission(self):772 attachments = self.rpc_client.TestCase.list_attachments(self.case.pk)773 self.assertEqual(len(attachments), 0)774 def verify_api_without_permission(self):775 with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):...

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