Open
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements a redirect from the root path ('/') to '/app' using a 303 See Other status code and adds a corresponding test case to verify the functionality. The reviewer suggests improving the maintainability of the code by replacing hardcoded strings and status codes with constants in both the application logic and the test suite.
app/main.py
Outdated
|
|
||
| @app.get("/", include_in_schema=False) | ||
| def root_redirect() -> RedirectResponse: | ||
| return RedirectResponse("/app", status_code=303) |
Contributor
There was a problem hiding this comment.
This line uses hardcoded values for the path ("/app") and status code (303). For better maintainability and readability, it's recommended to:
- Define
"/app"as a constant and reuse it here and in the tests. - Use the symbolic constant
status.HTTP_303_SEE_OTHERfromfastapiinstead of the number303. You'll need to importstatusfromfastapi.
tests/test_auth_requester.py
Outdated
Comment on lines
+544
to
+545
| assert response.status_code == 303 | ||
| assert response.headers["location"] == "/app" |
Contributor
There was a problem hiding this comment.
These assertions use hardcoded values (303 and "/app"). To make the test more robust and maintainable, consider using constants instead:
- Assert against
status.HTTP_303_SEE_OTHERfromfastapifor the status code. - Assert against the same path constant suggested for the application code for the location header.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
/), which should instead take users to the main UI at/app.Description
@app.get("/", include_in_schema=False)that returns aRedirectResponseto/appwith HTTP303.RedirectResponsefromfastapi.responsesto support the redirect.test_root_route_redirects_to_appasserting thatGET /responds with status303andLocation: /app.Testing
pytest -q tests/test_auth_requester.py -k root_route_redirects_to_app -rs, which was skipped in this environment becausefastapiis not installed.python -m compileall app/main.py tests/test_auth_requester.py, which succeeded.Codex Task