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
90bc07f3
Commit
90bc07f3
authored
Jun 29, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addeded 'APITestClient.credentials()'
parent
f585480e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
rest_framework/test.py
+29
-0
rest_framework/tests/test_testing.py
+32
-0
No files found.
rest_framework/test.py
View file @
90bc07f3
# -- coding: utf-8 --
# Note that we use `DjangoRequestFactory` and `DjangoClient` names in order
# to make it harder for the user to import the wrong thing without realizing.
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.test.client
import
Client
as
DjangoClient
from
rest_framework.compat
import
RequestFactory
as
DjangoRequestFactory
...
...
@@ -72,31 +75,57 @@ class APIRequestFactory(DjangoRequestFactory):
class
APIClient
(
APIRequestFactory
,
DjangoClient
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_credentials
=
{}
super
(
APIClient
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
credentials
(
self
,
**
kwargs
):
self
.
_credentials
=
kwargs
def
get
(
self
,
path
,
data
=
{},
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
get
(
path
,
data
=
data
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
head
(
self
,
path
,
data
=
{},
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
head
(
path
,
data
=
data
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
post
(
self
,
path
,
data
=
None
,
format
=
None
,
content_type
=
None
,
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
post
(
path
,
data
=
data
,
format
=
format
,
content_type
=
content_type
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
put
(
self
,
path
,
data
=
None
,
format
=
None
,
content_type
=
None
,
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
post
(
path
,
data
=
data
,
format
=
format
,
content_type
=
content_type
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
patch
(
self
,
path
,
data
=
None
,
format
=
None
,
content_type
=
None
,
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
post
(
path
,
data
=
data
,
format
=
format
,
content_type
=
content_type
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
delete
(
self
,
path
,
data
=
None
,
format
=
None
,
content_type
=
None
,
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
post
(
path
,
data
=
data
,
format
=
format
,
content_type
=
content_type
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
return
response
def
options
(
self
,
path
,
data
=
None
,
format
=
None
,
content_type
=
None
,
follow
=
False
,
**
extra
):
extra
.
update
(
self
.
_credentials
)
response
=
super
(
APIClient
,
self
)
.
post
(
path
,
data
=
data
,
format
=
format
,
content_type
=
content_type
,
**
extra
)
if
follow
:
response
=
self
.
_handle_redirects
(
response
,
**
extra
)
...
...
rest_framework/tests/test_testing.py
0 → 100644
View file @
90bc07f3
# -- coding: utf-8 --
from
__future__
import
unicode_literals
from
django.test
import
TestCase
from
rest_framework.compat
import
patterns
,
url
from
rest_framework.decorators
import
api_view
from
rest_framework.response
import
Response
from
rest_framework.test
import
APIClient
@api_view
([
'GET'
])
def
mirror
(
request
):
return
Response
({
'auth'
:
request
.
META
.
get
(
'HTTP_AUTHORIZATION'
,
b
''
)
})
urlpatterns
=
patterns
(
''
,
url
(
r'^view/$'
,
mirror
),
)
class
CheckTestClient
(
TestCase
):
urls
=
'rest_framework.tests.test_testing'
def
setUp
(
self
):
self
.
client
=
APIClient
()
def
test_credentials
(
self
):
self
.
client
.
credentials
(
HTTP_AUTHORIZATION
=
'example'
)
response
=
self
.
client
.
get
(
'/view/'
)
self
.
assertEqual
(
response
.
data
[
'auth'
],
'example'
)
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