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
b09ef289
Commit
b09ef289
authored
Jan 24, 2015
by
Brandon Cazander
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add failing test for request.version AttributeError in BrowsableAPI.
parent
8f25c0c5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletions
+45
-1
tests/browsable_api/auth_urls.py
+8
-1
tests/browsable_api/test_browsable_api.py
+10
-0
tests/browsable_api/views.py
+27
-0
No files found.
tests/browsable_api/auth_urls.py
View file @
b09ef289
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
django.conf.urls
import
patterns
,
url
,
include
from
django.conf.urls
import
patterns
,
url
,
include
from
rest_framework
import
routers
from
.views
import
MockView
from
.views
import
MockView
,
FooViewSet
,
BarViewSet
router
=
routers
.
SimpleRouter
()
router
.
register
(
r'foo'
,
FooViewSet
)
router
.
register
(
r'bar'
,
BarViewSet
)
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
(
r'^$'
,
MockView
.
as_view
()),
(
r'^$'
,
MockView
.
as_view
()),
url
(
r'^'
,
include
(
router
.
urls
)),
url
(
r'^bar/(?P<pk>\d+)/$'
,
BarViewSet
,
name
=
'bar-list'
),
url
(
r'^auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
)),
url
(
r'^auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
)),
)
)
tests/browsable_api/test_browsable_api.py
View file @
b09ef289
...
@@ -3,6 +3,7 @@ from django.contrib.auth.models import User
...
@@ -3,6 +3,7 @@ from django.contrib.auth.models import User
from
django.test
import
TestCase
from
django.test
import
TestCase
from
rest_framework.test
import
APIClient
from
rest_framework.test
import
APIClient
from
.models
import
Foo
,
Bar
class
DropdownWithAuthTests
(
TestCase
):
class
DropdownWithAuthTests
(
TestCase
):
...
@@ -16,6 +17,8 @@ class DropdownWithAuthTests(TestCase):
...
@@ -16,6 +17,8 @@ class DropdownWithAuthTests(TestCase):
self
.
email
=
'lennon@thebeatles.com'
self
.
email
=
'lennon@thebeatles.com'
self
.
password
=
'password'
self
.
password
=
'password'
self
.
user
=
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
password
)
self
.
user
=
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
password
)
foo
=
Foo
.
objects
.
create
(
name
=
'Foo'
)
Bar
.
objects
.
create
(
foo
=
foo
)
def
tearDown
(
self
):
def
tearDown
(
self
):
self
.
client
.
logout
()
self
.
client
.
logout
()
...
@@ -25,6 +28,13 @@ class DropdownWithAuthTests(TestCase):
...
@@ -25,6 +28,13 @@ class DropdownWithAuthTests(TestCase):
response
=
self
.
client
.
get
(
'/'
)
response
=
self
.
client
.
get
(
'/'
)
self
.
assertContains
(
response
,
'john'
)
self
.
assertContains
(
response
,
'john'
)
def
test_bug_2455_clone_request
(
self
):
self
.
client
.
login
(
username
=
self
.
username
,
password
=
self
.
password
)
json_response
=
self
.
client
.
get
(
'/foo/1/?format=json'
)
self
.
assertEqual
(
json_response
.
status_code
,
200
)
browsable_api_response
=
self
.
client
.
get
(
'/foo/1/'
)
self
.
assertEqual
(
browsable_api_response
.
status_code
,
200
)
def
test_logout_shown_when_logged_in
(
self
):
def
test_logout_shown_when_logged_in
(
self
):
self
.
client
.
login
(
username
=
self
.
username
,
password
=
self
.
password
)
self
.
client
.
login
(
username
=
self
.
username
,
password
=
self
.
password
)
response
=
self
.
client
.
get
(
'/'
)
response
=
self
.
client
.
get
(
'/'
)
...
...
tests/browsable_api/views.py
View file @
b09ef289
from
__future__
import
unicode_literals
from
__future__
import
unicode_literals
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.viewsets
import
ModelViewSet
from
rest_framework
import
authentication
from
rest_framework
import
authentication
from
rest_framework
import
renderers
from
rest_framework
import
renderers
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.renderers
import
BrowsableAPIRenderer
,
JSONRenderer
from
rest_framework.versioning
import
NamespaceVersioning
from
.models
import
Foo
,
Bar
from
.serializers
import
FooSerializer
,
BarSerializer
class
MockView
(
APIView
):
class
MockView
(
APIView
):
...
@@ -13,3 +18,25 @@ class MockView(APIView):
...
@@ -13,3 +18,25 @@ class MockView(APIView):
def
get
(
self
,
request
):
def
get
(
self
,
request
):
return
Response
({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
return
Response
({
'a'
:
1
,
'b'
:
2
,
'c'
:
3
})
class
SerializerClassMixin
(
object
):
def
get_serializer_class
(
self
):
# Get base name of serializer
self
.
request
.
version
return
self
.
serializer_class
class
FooViewSet
(
SerializerClassMixin
,
ModelViewSet
):
versioning_class
=
NamespaceVersioning
model
=
Foo
queryset
=
Foo
.
objects
.
all
()
serializer_class
=
FooSerializer
renderer_classes
=
(
BrowsableAPIRenderer
,
JSONRenderer
)
class
BarViewSet
(
SerializerClassMixin
,
ModelViewSet
):
model
=
Bar
queryset
=
Bar
.
objects
.
all
()
serializer_class
=
BarSerializer
renderer_classes
=
(
BrowsableAPIRenderer
,
)
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