Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 13, 2025
1 parent 5d18618 commit 643bc13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
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 643bc13

Please sign in to comment.