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

[pre-commit.ci] pre-commit autoupdate #1540

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
hooks:
- id: ruff
args: [ --fix ]
Expand Down
2 changes: 1 addition & 1 deletion oauth2_provider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def batch_delete(queryset, query):
flat_queryset = queryset.values_list("id", flat=True)[:CLEAR_EXPIRED_TOKENS_BATCH_SIZE]
batch_length = flat_queryset.count()
queryset.model.objects.filter(id__in=list(flat_queryset)).delete()
logger.debug(f"{batch_length} tokens deleted, {current_no-batch_length} left")
logger.debug(f"{batch_length} tokens deleted, {current_no - batch_length} left")
queryset = queryset.model.objects.filter(query)
time.sleep(CLEAR_EXPIRED_TOKENS_BATCH_INTERVAL)
current_no = queryset.count()
Expand Down
48 changes: 24 additions & 24 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,41 +433,41 @@ def test_clear_expired_tokens_with_tokens(self):
initial_at_count = AccessToken.objects.count()
assert initial_at_count == 2 * self.num_tokens, f"{2 * self.num_tokens} access tokens should exist."
initial_expired_at_count = AccessToken.objects.filter(expires__lte=self.now).count()
assert (
initial_expired_at_count == self.num_tokens
), f"{self.num_tokens} expired access tokens should exist."
assert initial_expired_at_count == self.num_tokens, (
f"{self.num_tokens} expired access tokens should exist."
)
initial_current_at_count = AccessToken.objects.filter(expires__gt=self.now).count()
assert (
initial_current_at_count == self.num_tokens
), f"{self.num_tokens} current access tokens should exist."
assert initial_current_at_count == self.num_tokens, (
f"{self.num_tokens} current access tokens should exist."
)
initial_rt_count = RefreshToken.objects.count()
assert (
initial_rt_count == self.num_tokens // 2
), f"{self.num_tokens // 2} refresh tokens should exist."
assert initial_rt_count == self.num_tokens // 2, (
f"{self.num_tokens // 2} refresh tokens should exist."
)
initial_rt_expired_at_count = RefreshToken.objects.filter(access_token__expires__lte=self.now).count()
assert (
initial_rt_expired_at_count == initial_rt_count / 2
), "half the refresh tokens should be for expired access tokens."
assert initial_rt_expired_at_count == initial_rt_count / 2, (
"half the refresh tokens should be for expired access tokens."
)
initial_rt_current_at_count = RefreshToken.objects.filter(access_token__expires__gt=self.now).count()
assert (
initial_rt_current_at_count == initial_rt_count / 2
), "half the refresh tokens should be for current access tokens."
assert initial_rt_current_at_count == initial_rt_count / 2, (
"half the refresh tokens should be for current access tokens."
)
initial_gt_count = Grant.objects.count()
assert initial_gt_count == self.num_tokens * 2, f"{self.num_tokens * 2} grants should exist."

clear_expired()

# after clear_expired():
remaining_at_count = AccessToken.objects.count()
assert (
remaining_at_count == initial_at_count // 2
), "half the initial access tokens should still exist."
assert remaining_at_count == initial_at_count // 2, (
"half the initial access tokens should still exist."
)
remaining_expired_at_count = AccessToken.objects.filter(expires__lte=self.now).count()
assert remaining_expired_at_count == 0, "no remaining expired access tokens should still exist."
remaining_current_at_count = AccessToken.objects.filter(expires__gt=self.now).count()
assert (
remaining_current_at_count == initial_current_at_count
), "all current access tokens should still exist."
assert remaining_current_at_count == initial_current_at_count, (
"all current access tokens should still exist."
)
remaining_rt_count = RefreshToken.objects.count()
assert remaining_rt_count == initial_rt_count // 2, "half the refresh tokens should still exist."
remaining_rt_expired_at_count = RefreshToken.objects.filter(
Expand All @@ -477,9 +477,9 @@ def test_clear_expired_tokens_with_tokens(self):
remaining_rt_current_at_count = RefreshToken.objects.filter(
access_token__expires__gt=self.now
).count()
assert (
remaining_rt_current_at_count == initial_rt_current_at_count
), "all the refresh tokens for current access tokens should still exist."
assert remaining_rt_current_at_count == initial_rt_current_at_count, (
"all the refresh tokens for current access tokens should still exist."
)
remaining_gt_count = Grant.objects.count()
assert remaining_gt_count == initial_gt_count // 2, "half the remaining grants should still exist."

Expand Down
Loading