mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Change Token.generate_key to a Classmethod (#7502)
* adds classmethod decorator to generate_key and test to confirm change is acceptable * self -> cls
This commit is contained in:
parent
f323049ecc
commit
35c0abf24e
|
@ -32,7 +32,8 @@ class Token(models.Model):
|
||||||
self.key = self.generate_key()
|
self.key = self.generate_key()
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
def generate_key(self):
|
@classmethod
|
||||||
|
def generate_key(cls):
|
||||||
return binascii.hexlify(os.urandom(20)).decode()
|
return binascii.hexlify(os.urandom(20)).decode()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -397,6 +397,10 @@ class TokenAuthTests(BaseTokenAuthTests, TestCase):
|
||||||
key = token.generate_key()
|
key = token.generate_key()
|
||||||
assert isinstance(key, str)
|
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):
|
def test_token_login_json(self):
|
||||||
"""Ensure token login view using JSON POST works."""
|
"""Ensure token login view using JSON POST works."""
|
||||||
client = APIClient(enforce_csrf_checks=True)
|
client = APIClient(enforce_csrf_checks=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user