From 017e70b7d119fc5d40a83dc689e3b3f86d06e9bb Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 26 Aug 2024 19:11:14 -0400 Subject: [PATCH] paperwork: Suppress PermissionDenied exception logging during tests --- paperwork/tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/paperwork/tests.py b/paperwork/tests.py index 8d29b71..1b540d1 100644 --- a/paperwork/tests.py +++ b/paperwork/tests.py @@ -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"}]