mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 16:40:03 +03:00
adds classmethod decorator to generate_key and test to confirm change is acceptable
This commit is contained in:
parent
7f3a3557a0
commit
5c86a31481
|
@ -32,6 +32,7 @@ class Token(models.Model):
|
|||
self.key = self.generate_key()
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def generate_key(self):
|
||||
return binascii.hexlify(os.urandom(20)).decode()
|
||||
|
||||
|
|
|
@ -397,6 +397,10 @@ class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
|||
key = token.generate_key()
|
||||
assert isinstance(key, str)
|
||||
|
||||
def test_generate_key_accessible_as_classmethod(self):
|
||||
key = self.model.generate_key()
|
||||
assert isinstance(key, str)
|
||||
|
||||
def test_token_login_json(self):
|
||||
"""Ensure token login view using JSON POST works."""
|
||||
client = APIClient(enforce_csrf_checks=True)
|
||||
|
|
Loading…
Reference in New Issue
Block a user