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
023c0089
Commit
023c0089
authored
Feb 23, 2012
by
Sébastien Piquemal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed permissions examples + sanity test
parent
afd49023
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
3 deletions
+30
-3
examples/permissionsexample/tests.py
+27
-0
examples/permissionsexample/views.py
+2
-2
examples/sandbox/views.py
+1
-1
No files found.
examples/permissionsexample/tests.py
0 → 100644
View file @
023c0089
from
django.test
import
TestCase
from
django.core.urlresolvers
import
reverse
from
django.test.client
import
Client
class
NaviguatePermissionsExamples
(
TestCase
):
"""
Sanity checks for permissions examples
"""
def
test_throttled_resource
(
self
):
url
=
reverse
(
'throttled-resource'
)
for
i
in
range
(
0
,
10
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
503
)
def
test_loggedin_resource
(
self
):
url
=
reverse
(
'loggedin-resource'
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
403
)
loggedin_client
=
Client
()
loggedin_client
.
login
(
username
=
'test'
,
password
=
'test'
)
response
=
loggedin_client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
examples/permissionsexample/views.py
View file @
023c0089
...
@@ -30,7 +30,7 @@ class ThrottlingExampleView(View):
...
@@ -30,7 +30,7 @@ class ThrottlingExampleView(View):
throttle will be applied until 60 seconds have passed since the first request.
throttle will be applied until 60 seconds have passed since the first request.
"""
"""
permissions
=
(
PerUserThrottling
,)
permissions
_classes
=
(
PerUserThrottling
,)
throttle
=
'10/min'
throttle
=
'10/min'
def
get
(
self
,
request
):
def
get
(
self
,
request
):
...
@@ -47,7 +47,7 @@ class LoggedInExampleView(View):
...
@@ -47,7 +47,7 @@ class LoggedInExampleView(View):
`curl -X GET -H 'Accept: application/json' -u test:test http://localhost:8000/permissions-example`
`curl -X GET -H 'Accept: application/json' -u test:test http://localhost:8000/permissions-example`
"""
"""
permissions
=
(
IsAuthenticated
,
)
permissions
_classes
=
(
IsAuthenticated
,
)
def
get
(
self
,
request
):
def
get
(
self
,
request
):
return
Response
(
'You have permission to view this resource'
)
return
Response
(
'You have permission to view this resource'
)
examples/sandbox/views.py
View file @
023c0089
...
@@ -54,7 +54,7 @@ class Sandbox(View):
...
@@ -54,7 +54,7 @@ class Sandbox(View):
'url'
:
reverse
(
'model-resource-root'
,
request
)},
'url'
:
reverse
(
'model-resource-root'
,
request
)},
{
'name'
:
'Simple Mixin-only example'
,
{
'name'
:
'Simple Mixin-only example'
,
'url'
:
reverse
(
'mixin-view'
,
request
)},
'url'
:
reverse
(
'mixin-view'
,
request
)},
{
'name'
:
'Object store API'
{
'name'
:
'Object store API'
,
'url'
:
reverse
(
'object-store-root'
,
request
)},
'url'
:
reverse
(
'object-store-root'
,
request
)},
{
'name'
:
'Code highlighting API'
,
{
'name'
:
'Code highlighting API'
,
'url'
:
reverse
(
'pygments-root'
,
request
)},
'url'
:
reverse
(
'pygments-root'
,
request
)},
...
...
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