Skip to content

Commit

Permalink
changes request.path to url
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrasca committed Nov 29, 2024
1 parent 9215b16 commit 1a8cf96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/main/middlewares/log_page_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def wrapper(*args, **kwargs):
log_data = {
"event": "api_request",
"user_id": user_id,
"route": request.path,
"route": request.url,
"method": request.method,
}
current_app.audit_logger.info(json.dumps(log_data))
Expand Down
8 changes: 5 additions & 3 deletions app/tests/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from app.main.middlewares.log_page_view import log_page_view

host = "http://localhost"


@pytest.mark.parametrize(
"route_path, method, session_object, route_function, expected_response, expected_log",
Expand All @@ -14,23 +16,23 @@
{"user_id": "test_user"},
lambda: "Test Response",
b"Test Response",
'{"event": "api_request", "user_id": "test_user", "route": "/test_route", "method": "GET"}',
'{"event": "api_request", "user_id": "test_user", "route": "{host}/test_route", "method": "GET"}',
),
(
"/anonymous_route",
"GET",
{},
lambda: "Anonymous Response",
b"Anonymous Response",
'{"event": "api_request", "user_id": "anonymous", "route": "/anonymous_route", "method": "GET"}',
'{"event": "api_request", "user_id": "anonymous", "route": "{host}/anonymous_route", "method": "GET"}',
),
(
"/post_route",
"POST",
{"user_id": "test_user"},
lambda: "Post Response",
b"Post Response",
'{"event": "api_request", "user_id": "test_user", "route": "/post_route", "method": "POST"}',
'{"event": "api_request", "user_id": "test_user", "route": "{host}/post_route", "method": "POST"}',
),
],
)
Expand Down

0 comments on commit 1a8cf96

Please sign in to comment.