feat: add UserTimezoneMiddleware#255
Open
xogas wants to merge 3 commits intoTencentBlueKing:masterfrom
Open
Conversation
piglei
reviewed
Feb 3, 2026
| return | ||
|
|
||
| # Fallback to default timezone when time_zone is empty or invalid | ||
| dj_timezone.activate(dj_timezone.get_default_timezone()) |
Collaborator
There was a problem hiding this comment.
这一行需要手动调用吗?Django 默认是不是已经激活这个
Contributor
Author
There was a problem hiding this comment.
当打开 USE_TZ = True 时, 会使用 settings.TIME_ZONE 的时区, 但这里显式设置是为了明确这一点
| ], | ||
| ids=["invalid_timezone", "empty_string", "none_value", "no_attr"], | ||
| ) | ||
| def test_fallback_to_default_timezone(self, rf, authenticated_user, time_zone_value, has_attr): |
Collaborator
There was a problem hiding this comment.
Nit:以上测试均使用 mock 去验证以 activate 作为切入点,是否被 call,call 参数如何。但是考虑到测试已经构建起一个有效 Django App 的条件下,是否采用 override settings 去直接去除所有 mock,调用 middleware 然后获取当前 timezone 是否被改变是否更好?更符合“测试验证行为而不是实现”(假如实现复杂很多的情况下另说)。
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.
No description provided.