mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-13 16:54:47 +03:00
Fix code style: remove trailing whitespace and unused imports
This commit is contained in:
parent
d381901de4
commit
06b0441969
|
@ -29,7 +29,7 @@ class Token(models.Model):
|
|||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Save the token instance.
|
||||
|
||||
|
||||
If no key is provided, generates a cryptographically secure key.
|
||||
For existing tokens with cleared keys, regenerates the key.
|
||||
For new tokens, ensures they are inserted as new (not updated).
|
||||
|
@ -45,10 +45,10 @@ class Token(models.Model):
|
|||
def generate_key(cls):
|
||||
"""
|
||||
Generate a cryptographically secure token key.
|
||||
|
||||
|
||||
Uses secrets.token_hex(20) which provides 40 hexadecimal characters
|
||||
(160 bits of entropy) suitable for authentication tokens.
|
||||
|
||||
|
||||
Returns:
|
||||
str: A 40-character hexadecimal string
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import importlib
|
||||
import secrets
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
|
||||
|
@ -75,7 +74,7 @@ class AuthTokenTests(TestCase):
|
|||
"""
|
||||
user2 = User.objects.create_user('user2', 'user2@example.com', 'p')
|
||||
existing_token = Token.objects.create(user=user2)
|
||||
|
||||
|
||||
# Try to create another token with the same key
|
||||
with self.assertRaises(IntegrityError):
|
||||
Token.objects.create(key=existing_token.key, user=self.user)
|
||||
|
@ -90,11 +89,11 @@ class AuthTokenTests(TestCase):
|
|||
token = Token(user=self.user)
|
||||
token.key = "" # Explicitly clear the key
|
||||
token.save()
|
||||
|
||||
|
||||
# Verify the key was generated
|
||||
self.assertEqual(len(token.key), 40)
|
||||
self.assertEqual(token.user, self.user)
|
||||
|
||||
|
||||
# Verify it's saved in the database
|
||||
token.refresh_from_db()
|
||||
self.assertEqual(len(token.key), 40)
|
||||
|
|
Loading…
Reference in New Issue
Block a user