Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes request.path to url #679

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading