From 97fcf36c75140fed88a9b494f90c36c4d266ce8d Mon Sep 17 00:00:00 2001 From: Mfon Eti-mfon Date: Sun, 12 Jul 2020 00:11:17 +0100 Subject: [PATCH] api: Add tests for tcms.bugs.api.remove -- Refs #1597 --- tcms/bugs/tests/test_api.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tcms/bugs/tests/test_api.py b/tcms/bugs/tests/test_api.py index 5b5ef6fc7b..52bb59443a 100644 --- a/tcms/bugs/tests/test_api.py +++ b/tcms/bugs/tests/test_api.py @@ -9,6 +9,7 @@ if "tcms.bugs.apps.AppConfig" not in settings.INSTALLED_APPS: raise unittest.SkipTest("tcms.bugs is disabled") +from tcms.bugs.models import Bug # noqa: E402 from tcms.bugs.tests.factory import BugFactory # noqa: E402 from tcms.rpc.tests.utils import APITestCase, APIPermissionsTestCase # noqa: E402 from tcms.tests.factories import TagFactory # noqa: E402 @@ -67,3 +68,28 @@ def verify_api_with_permission(self): def verify_api_without_permission(self): with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): self.rpc_client.Bug.remove_tag(self.bug.pk, self.tag.name) + + +class TestRemovePermissions(APIPermissionsTestCase): + """Test permissions of Bug.remove""" + + permission_label = "bugs.delete_bug" + + def _fixture_setup(self): + super()._fixture_setup() + + self.bug = BugFactory() + self.another_bug = BugFactory() + self.yet_another_bug = BugFactory() + + def verify_api_with_permission(self): + self.rpc_client.Bug.remove({"pk__in": [self.bug.pk, self.another_bug.pk]}) + + bugs = Bug.objects.all() + self.assertNotIn(self.bug, bugs) + self.assertNotIn(self.another_bug, bugs) + self.assertIn(self.yet_another_bug, bugs) + + def verify_api_without_permission(self): + with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): + self.rpc_client.Bug.remove({"pk__in": [self.bug.pk, self.another_bug.pk]})