Skip to content

Commit

Permalink
Add test when no userid field is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobichaud committed Jan 11, 2025
1 parent 194b918 commit eab1f86
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test_app/tests/middlewares/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ def get_response(_request: HttpRequest) -> HttpResponse:
self.assertIn("user_id", record.msg)
self.assertIsNone(record.msg["user_id"])

@override_settings(
USER_ID_FIELD=None,
)
def test_process_request_no_user_id_field(self) -> None:
def get_response(_request: HttpRequest) -> HttpResponse:
with self.assertLogs(__name__, logging.INFO) as log_results:
self.logger.info("hello")
self.log_results = log_results
return HttpResponse()

request = self.factory.get("/foo")

middleware = RequestMiddleware(get_response)
response = middleware(request)
self.assertEqual(200, cast(HttpResponse, response).status_code)

self.assertEqual(1, len(self.log_results.records))
record = self.log_results.records[0]

self.assertEqual("INFO", record.levelname)

self.assertNotIn("user_id", record.msg)

def test_log_user_in_request_finished(self) -> None:
mock_response = Mock()
mock_response.status_code = 200
Expand Down

0 comments on commit eab1f86

Please sign in to comment.