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
08533165
Commit
08533165
authored
Sep 28, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests for generic views
parent
6cf2874c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
10 deletions
+36
-10
rest_framework/tests/generics.py
+36
-10
No files found.
rest_framework/tests/generics.py
View file @
08533165
...
@@ -29,14 +29,14 @@ class TestRootView(TestCase):
...
@@ -29,14 +29,14 @@ class TestRootView(TestCase):
{
'id'
:
obj
.
id
,
'text'
:
obj
.
text
}
{
'id'
:
obj
.
id
,
'text'
:
obj
.
text
}
for
obj
in
self
.
objects
.
all
()
for
obj
in
self
.
objects
.
all
()
]
]
self
.
view
=
RootView
.
as_view
()
def
test_get_root_view
(
self
):
def
test_get_root_view
(
self
):
"""
"""
GET requests to RootAPIView should return list of objects.
GET requests to RootAPIView should return list of objects.
"""
"""
view
=
RootView
.
as_view
()
request
=
factory
.
get
(
'/'
)
request
=
factory
.
get
(
'/'
)
response
=
view
(
request
)
.
render
()
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
data
,
self
.
data
)
self
.
assertEquals
(
response
.
data
,
self
.
data
)
...
@@ -44,15 +44,33 @@ class TestRootView(TestCase):
...
@@ -44,15 +44,33 @@ class TestRootView(TestCase):
"""
"""
POST requests to RootAPIView should create a new object.
POST requests to RootAPIView should create a new object.
"""
"""
view
=
RootView
.
as_view
()
content
=
{
'text'
:
'foobar'
}
content
=
{
'text'
:
'foobar'
}
request
=
factory
.
post
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
request
=
factory
.
post
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
view
(
request
)
.
render
()
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertEquals
(
response
.
data
,
{
'id'
:
4
,
'text'
:
u'foobar'
})
self
.
assertEquals
(
response
.
data
,
{
'id'
:
4
,
'text'
:
u'foobar'
})
created
=
self
.
objects
.
get
(
id
=
4
)
created
=
self
.
objects
.
get
(
id
=
4
)
self
.
assertEquals
(
created
.
text
,
'foobar'
)
self
.
assertEquals
(
created
.
text
,
'foobar'
)
def
test_put_root_view
(
self
):
"""
PUT requests to RootAPIView should not be allowed
"""
content
=
{
'text'
:
'foobar'
}
request
=
factory
.
put
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
PUT
\'
not allowed."}'
)
def
test_delete_root_view
(
self
):
"""
DELETE requests to RootAPIView should not be allowed
"""
request
=
factory
.
delete
(
'/'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
DELETE
\'
not allowed."}'
)
class
TestInstanceView
(
TestCase
):
class
TestInstanceView
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -67,25 +85,34 @@ class TestInstanceView(TestCase):
...
@@ -67,25 +85,34 @@ class TestInstanceView(TestCase):
{
'id'
:
obj
.
id
,
'text'
:
obj
.
text
}
{
'id'
:
obj
.
id
,
'text'
:
obj
.
text
}
for
obj
in
self
.
objects
.
all
()
for
obj
in
self
.
objects
.
all
()
]
]
self
.
view
=
InstanceView
.
as_view
()
def
test_get_instance_view
(
self
):
def
test_get_instance_view
(
self
):
"""
"""
GET requests to InstanceAPIView should return a single object.
GET requests to InstanceAPIView should return a single object.
"""
"""
view
=
InstanceView
.
as_view
()
request
=
factory
.
get
(
'/1'
)
request
=
factory
.
get
(
'/1'
)
response
=
view
(
request
,
pk
=
1
)
.
render
()
response
=
self
.
view
(
request
,
pk
=
1
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
data
,
self
.
data
[
0
])
self
.
assertEquals
(
response
.
data
,
self
.
data
[
0
])
def
test_post_instance_view
(
self
):
"""
POST requests to InstanceAPIView should not be allowed
"""
content
=
{
'text'
:
'foobar'
}
request
=
factory
.
post
(
'/'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
self
.
view
(
request
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
self
.
assertEquals
(
response
.
content
,
'{"detail": "Method
\'
POST
\'
not allowed."}'
)
def
test_put_instance_view
(
self
):
def
test_put_instance_view
(
self
):
"""
"""
PUT requests to InstanceAPIView should update an object.
PUT requests to InstanceAPIView should update an object.
"""
"""
view
=
InstanceView
.
as_view
()
content
=
{
'text'
:
'foobar'
}
content
=
{
'text'
:
'foobar'
}
request
=
factory
.
put
(
'/1'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
request
=
factory
.
put
(
'/1'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
response
=
view
(
request
,
pk
=
1
)
.
render
()
response
=
self
.
view
(
request
,
pk
=
1
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEquals
(
response
.
data
,
{
'id'
:
1
,
'text'
:
'foobar'
})
self
.
assertEquals
(
response
.
data
,
{
'id'
:
1
,
'text'
:
'foobar'
})
updated
=
self
.
objects
.
get
(
id
=
1
)
updated
=
self
.
objects
.
get
(
id
=
1
)
...
@@ -95,9 +122,8 @@ class TestInstanceView(TestCase):
...
@@ -95,9 +122,8 @@ class TestInstanceView(TestCase):
"""
"""
DELETE requests to InstanceAPIView should delete an object.
DELETE requests to InstanceAPIView should delete an object.
"""
"""
view
=
InstanceView
.
as_view
()
request
=
factory
.
delete
(
'/1'
)
request
=
factory
.
delete
(
'/1'
)
response
=
view
(
request
,
pk
=
1
)
.
render
()
response
=
self
.
view
(
request
,
pk
=
1
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
)
self
.
assertEquals
(
response
.
content
,
''
)
self
.
assertEquals
(
response
.
content
,
''
)
ids
=
[
obj
.
id
for
obj
in
self
.
objects
.
all
()]
ids
=
[
obj
.
id
for
obj
in
self
.
objects
.
all
()]
...
...
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