Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
21810d26
Commit
21810d26
authored
Apr 28, 2014
by
Xavier Ordoquy
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1549 from maxpeterson/decode-generate-key
Ensure Token.generate_key returns a string.
parents
4a1ef6d4
73597a16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
2 deletions
+8
-2
rest_framework/authtoken/models.py
+1
-1
rest_framework/tests/test_authentication.py
+7
-1
No files found.
rest_framework/authtoken/models.py
View file @
21810d26
...
@@ -34,7 +34,7 @@ class Token(models.Model):
...
@@ -34,7 +34,7 @@ class Token(models.Model):
return
super
(
Token
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
super
(
Token
,
self
)
.
save
(
*
args
,
**
kwargs
)
def
generate_key
(
self
):
def
generate_key
(
self
):
return
binascii
.
hexlify
(
os
.
urandom
(
20
))
return
binascii
.
hexlify
(
os
.
urandom
(
20
))
.
decode
()
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
key
return
self
.
key
rest_framework/tests/test_authentication.py
View file @
21810d26
...
@@ -19,7 +19,7 @@ from rest_framework.authentication import (
...
@@ -19,7 +19,7 @@ from rest_framework.authentication import (
OAuth2Authentication
OAuth2Authentication
)
)
from
rest_framework.authtoken.models
import
Token
from
rest_framework.authtoken.models
import
Token
from
rest_framework.compat
import
patterns
,
url
,
include
from
rest_framework.compat
import
patterns
,
url
,
include
,
six
from
rest_framework.compat
import
oauth2_provider
,
oauth2_provider_scope
from
rest_framework.compat
import
oauth2_provider
,
oauth2_provider_scope
from
rest_framework.compat
import
oauth
,
oauth_provider
from
rest_framework.compat
import
oauth
,
oauth_provider
from
rest_framework.test
import
APIRequestFactory
,
APIClient
from
rest_framework.test
import
APIRequestFactory
,
APIClient
...
@@ -195,6 +195,12 @@ class TokenAuthTests(TestCase):
...
@@ -195,6 +195,12 @@ class TokenAuthTests(TestCase):
token
=
Token
.
objects
.
create
(
user
=
self
.
user
)
token
=
Token
.
objects
.
create
(
user
=
self
.
user
)
self
.
assertTrue
(
bool
(
token
.
key
))
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
,
six
.
string_types
))
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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment