aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework
diff options
context:
space:
mode:
authorMax Peterson2014-04-28 12:35:55 +0100
committerMax Peterson2014-04-28 12:35:55 +0100
commit1c777ffe8b67c342bc1b27fefe67d1094a2f6b07 (patch)
treef2a84ac17d4a8c442e079f7104a23f14402d576c /rest_framework
parent4a1ef6d4b15c504881662a2667564394cb333b6b (diff)
downloaddjango-rest-framework-1c777ffe8b67c342bc1b27fefe67d1094a2f6b07.tar.bz2
Ensure Token.generate_key returns a string.
Diffstat (limited to 'rest_framework')
-rw-r--r--rest_framework/authtoken/models.py2
-rw-r--r--rest_framework/tests/test_authentication.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/rest_framework/authtoken/models.py b/rest_framework/authtoken/models.py
index 8eac2cc4..167fa531 100644
--- a/rest_framework/authtoken/models.py
+++ b/rest_framework/authtoken/models.py
@@ -34,7 +34,7 @@ class Token(models.Model):
return super(Token, self).save(*args, **kwargs)
def generate_key(self):
- return binascii.hexlify(os.urandom(20))
+ return binascii.hexlify(os.urandom(20)).decode()
def __unicode__(self):
return self.key
diff --git a/rest_framework/tests/test_authentication.py b/rest_framework/tests/test_authentication.py
index c37d2a51..8773f580 100644
--- a/rest_framework/tests/test_authentication.py
+++ b/rest_framework/tests/test_authentication.py
@@ -195,6 +195,12 @@ class TokenAuthTests(TestCase):
token = Token.objects.create(user=self.user)
self.assertTrue(bool(token.key))
+ def test_generate_key_returns_string(self):
+ """Ensure generate_key returns a string"""
+ token = Token()
+ key = token.generate_key()
+ self.assertTrue(isinstance(key, str))
+
def test_token_login_json(self):
"""Ensure token login view using JSON POST works."""
client = APIClient(enforce_csrf_checks=True)