style: apply ruff auto-fix
- Auto-formatted code with ruff format - Applied ruff linting fixes with --fix Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -538,7 +538,8 @@ class TestTokenUtils:
|
|||||||
def test_generate_api_token_length(self):
|
def test_generate_api_token_length(self):
|
||||||
"""Generated tokens should have the exact expected length based on TOKEN_BYTES."""
|
"""Generated tokens should have the exact expected length based on TOKEN_BYTES."""
|
||||||
import math
|
import math
|
||||||
from app.api.api_tokens import generate_api_token, TOKEN_PREFIX, TOKEN_BYTES
|
|
||||||
|
from app.api.api_tokens import TOKEN_BYTES, TOKEN_PREFIX, generate_api_token
|
||||||
|
|
||||||
# base64url encoding of N bytes without padding: ceil(N * 4 / 3) characters
|
# base64url encoding of N bytes without padding: ceil(N * 4 / 3) characters
|
||||||
expected_b64_len = math.ceil(TOKEN_BYTES * 4 / 3)
|
expected_b64_len = math.ceil(TOKEN_BYTES * 4 / 3)
|
||||||
@@ -551,7 +552,8 @@ class TestTokenUtils:
|
|||||||
def test_generate_api_token_charset(self):
|
def test_generate_api_token_charset(self):
|
||||||
"""Generated tokens should only contain URL-safe base64 characters and the prefix."""
|
"""Generated tokens should only contain URL-safe base64 characters and the prefix."""
|
||||||
import re
|
import re
|
||||||
from app.api.api_tokens import generate_api_token, TOKEN_PREFIX
|
|
||||||
|
from app.api.api_tokens import TOKEN_PREFIX, generate_api_token
|
||||||
|
|
||||||
token = generate_api_token()
|
token = generate_api_token()
|
||||||
# Check it starts with prefix and the rest is base64url chars ([A-Za-z0-9_-])
|
# Check it starts with prefix and the rest is base64url chars ([A-Za-z0-9_-])
|
||||||
@@ -562,14 +564,14 @@ class TestTokenUtils:
|
|||||||
def test_generate_api_token_uses_secrets(self):
|
def test_generate_api_token_uses_secrets(self):
|
||||||
"""Generated tokens should use secrets.token_urlsafe with the correct number of bytes."""
|
"""Generated tokens should use secrets.token_urlsafe with the correct number of bytes."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
from app.api.api_tokens import generate_api_token, TOKEN_BYTES, TOKEN_PREFIX
|
|
||||||
|
from app.api.api_tokens import TOKEN_BYTES, TOKEN_PREFIX, generate_api_token
|
||||||
|
|
||||||
with patch("app.api.api_tokens.secrets.token_urlsafe", return_value="mocked_token") as mock_secrets:
|
with patch("app.api.api_tokens.secrets.token_urlsafe", return_value="mocked_token") as mock_secrets:
|
||||||
token = generate_api_token()
|
token = generate_api_token()
|
||||||
mock_secrets.assert_called_once_with(TOKEN_BYTES)
|
mock_secrets.assert_called_once_with(TOKEN_BYTES)
|
||||||
assert token == f"{TOKEN_PREFIX}mocked_token"
|
assert token == f"{TOKEN_PREFIX}mocked_token"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.unit
|
@pytest.mark.unit
|
||||||
def test_hash_token_deterministic(self):
|
def test_hash_token_deterministic(self):
|
||||||
"""Hashing the same token should always produce the same result."""
|
"""Hashing the same token should always produce the same result."""
|
||||||
|
|||||||
Reference in New Issue
Block a user