Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1540)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](astral-sh/ruff-pre-commit@v0.8.6...v0.9.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jan 13, 2025
1 parent c61d852 commit 1b0520a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
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

0 comments on commit 1b0520a

Please sign in to comment.