paperwork: Suppress PermissionDenied exception logging during tests

This commit is contained in:
Adam Goldsmith 2024-08-26 19:11:14 -04:00
parent 612c126c9d
commit 017e70b7d1

View File

@ -1,3 +1,4 @@
import logging
from collections.abc import Callable
from itertools import chain
from typing import TypedDict
@ -60,10 +61,17 @@ class PermissionRequiredViewTestCaseMixin:
cls.user_with_permission.user_permissions.add(*resolved_permissions)
def test_missing_permission(self) -> None:
# suppress PermissionDenied messages
logger = logging.getLogger("django.request")
previous_log_level = logger.getEffectiveLevel()
logger.setLevel(logging.ERROR)
self.client.force_login(self.user_without_permission)
response = self.client.get(self.path)
self.assertEqual(response.status_code, 403)
logger.setLevel(previous_log_level)
class WaiverReportTestCase(PermissionRequiredViewTestCaseMixin, TestCase):
permissions = [{"model": Waiver, "codename": "view_waiver"}]