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
a68e78bd
Commit
a68e78bd
authored
Dec 16, 2014
by
Martin Maillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test integrated with middleware
parent
dbd057b9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
tests/test_middleware.py
+37
-0
No files found.
tests/test_middleware.py
0 → 100644
View file @
a68e78bd
from
django.conf.urls
import
patterns
,
url
from
django.contrib.auth.models
import
User
from
rest_framework.authentication
import
TokenAuthentication
from
rest_framework.authtoken.models
import
Token
from
rest_framework.test
import
APITestCase
from
rest_framework.views
import
APIView
urlpatterns
=
patterns
(
''
,
url
(
r'^$'
,
APIView
.
as_view
(
authentication_classes
=
(
TokenAuthentication
,))),
)
class
MyMiddleware
(
object
):
def
process_response
(
self
,
request
,
response
):
assert
hasattr
(
request
,
'user'
),
'`user` is not set on request'
assert
request
.
user
.
is_authenticated
(),
'`user` is not authenticated'
return
response
class
TestMiddleware
(
APITestCase
):
urls
=
'tests.test_middleware'
def
test_middleware_can_access_user_when_processing_response
(
self
):
user
=
User
.
objects
.
create_user
(
'john'
,
'john@example.com'
,
'password'
)
key
=
'abcd1234'
Token
.
objects
.
create
(
key
=
key
,
user
=
user
)
with
self
.
settings
(
MIDDLEWARE_CLASSES
=
(
'tests.test_middleware.MyMiddleware'
,)
):
auth
=
'Token '
+
key
self
.
client
.
get
(
'/'
,
HTTP_AUTHORIZATION
=
auth
)
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