@@ -44,7 +44,7 @@ def test_process_exception_logs_with_authenticated_user(
4444 ):
4545 user = self .DummyUser (is_authenticated = True )
4646 request = self .DummyRequest (user = user , correlation_id = "corr-id-123" )
47- exception = Exception ("Something went wrong" )
47+ exception = RuntimeError ("Something went wrong" )
4848
4949 mock_logger = mock .Mock ()
5050 monkeypatch .setattr (
@@ -55,20 +55,20 @@ def test_process_exception_logs_with_authenticated_user(
5555 middleware .process_exception (request , exception )
5656
5757 mock_logger .exception .assert_called_once_with (
58- "url=/test/, method=GET, user=testuser, correlation_id=corr-id-123, exception_type=Exception Something went wrong" ,
58+ "url=/test/, method=GET, user=testuser, correlation_id=corr-id-123, exception_type=RuntimeError Something went wrong" ,
5959 extra = {
6060 "url" : "/test/" ,
6161 "method" : "GET" ,
6262 "user" : "testuser" ,
6363 "correlation_id" : "corr-id-123" ,
64- "exception_type" : "Exception " ,
64+ "exception_type" : "RuntimeError " ,
6565 },
6666 )
6767
6868 def test_process_exception_logs_with_anonymous_user (self , monkeypatch , middleware ):
6969 user = self .DummyUser (is_authenticated = False )
7070 request = self .DummyRequest (user = user , correlation_id = None )
71- exception = Exception ("Details of exception" )
71+ exception = RuntimeError ("Details of exception" )
7272
7373 mock_logger = mock .Mock ()
7474 monkeypatch .setattr (
@@ -79,19 +79,19 @@ def test_process_exception_logs_with_anonymous_user(self, monkeypatch, middlewar
7979 middleware .process_exception (request , exception )
8080
8181 mock_logger .exception .assert_called_once_with (
82- "url=/test/, method=GET, user=Anonymous, correlation_id=None, exception_type=Exception Details of exception" ,
82+ "url=/test/, method=GET, user=Anonymous, correlation_id=None, exception_type=RuntimeError Details of exception" ,
8383 extra = {
8484 "url" : "/test/" ,
8585 "method" : "GET" ,
8686 "user" : "Anonymous" ,
8787 "correlation_id" : None ,
88- "exception_type" : "Exception " ,
88+ "exception_type" : "RuntimeError " ,
8989 },
9090 )
9191
9292 def test_process_exception_logs_with_no_user (self , monkeypatch , middleware ):
9393 request = self .DummyRequest (user = None , correlation_id = "abc" )
94- exception = Exception ("Fail" )
94+ exception = RuntimeError ("Fail" )
9595
9696 mock_logger = mock .Mock ()
9797 monkeypatch .setattr (
@@ -102,19 +102,19 @@ def test_process_exception_logs_with_no_user(self, monkeypatch, middleware):
102102 middleware .process_exception (request , exception )
103103
104104 mock_logger .exception .assert_called_once_with (
105- "url=/test/, method=GET, user=Anonymous, correlation_id=abc, exception_type=Exception Fail" ,
105+ "url=/test/, method=GET, user=Anonymous, correlation_id=abc, exception_type=RuntimeError Fail" ,
106106 extra = {
107107 "url" : "/test/" ,
108108 "method" : "GET" ,
109109 "user" : "Anonymous" ,
110110 "correlation_id" : "abc" ,
111- "exception_type" : "Exception " ,
111+ "exception_type" : "RuntimeError " ,
112112 },
113113 )
114114
115115 def test_process_exception_returns_none (self , middleware ):
116116 request = self .DummyRequest ()
117- exception = Exception ("Some error" )
117+ exception = RuntimeError ("Some error" )
118118 result = middleware .process_exception (request , exception )
119119 assert result is None
120120
@@ -146,7 +146,7 @@ def test_process_exception_logs_correct_path_and_method(
146146 request = self .DummyRequest (
147147 path = path , method = method , user = user , correlation_id = "x"
148148 )
149- exception = Exception ("err" )
149+ exception = RuntimeError ("err" )
150150
151151 mock_logger = mock .Mock ()
152152 monkeypatch .setattr (
@@ -157,13 +157,13 @@ def test_process_exception_logs_correct_path_and_method(
157157 middleware .process_exception (request , exception )
158158
159159 mock_logger .exception .assert_called_once_with (
160- f"url={ path } , method={ method } , user=testuser, correlation_id=x, exception_type=Exception err" ,
160+ f"url={ path } , method={ method } , user=testuser, correlation_id=x, exception_type=RuntimeError err" ,
161161 extra = {
162162 "url" : path ,
163163 "method" : method ,
164164 "user" : "testuser" ,
165165 "correlation_id" : "x" ,
166- "exception_type" : "Exception " ,
166+ "exception_type" : "RuntimeError " ,
167167 },
168168 )
169169
0 commit comments