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
dac7eb09
Commit
dac7eb09
authored
Jun 09, 2011
by
markotibold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed the blogpost-tests
parent
cf637e88
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
10 deletions
+13
-10
examples/blogpost/tests.py
+13
-10
No files found.
examples/blogpost/tests.py
View file @
dac7eb09
...
@@ -7,9 +7,10 @@ from django.core.urlresolvers import reverse
...
@@ -7,9 +7,10 @@ from django.core.urlresolvers import reverse
from
django.utils
import
simplejson
as
json
from
django.utils
import
simplejson
as
json
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.compat
import
RequestFactory
from
djangorestframework.views
import
InstanceModelView
,
ListOrCreateModelView
from
blogpost
import
models
from
blogpost
import
models
,
urls
import
blogpost
#
import blogpost
# class AcceptHeaderTests(TestCase):
# class AcceptHeaderTests(TestCase):
...
@@ -178,32 +179,33 @@ class TestRotation(TestCase):
...
@@ -178,32 +179,33 @@ class TestRotation(TestCase):
models
.
BlogPost
.
objects
.
all
()
.
delete
()
models
.
BlogPost
.
objects
.
all
()
.
delete
()
def
test_get_to_root
(
self
):
def
test_get_to_root
(
self
):
'''Simple
test to demonstrate how the requestfactory needs to be used
'''
'''Simple
get to the *root* url of blogposts
'''
request
=
self
.
factory
.
get
(
'/blog-post'
)
request
=
self
.
factory
.
get
(
'/blog-post'
)
view
=
views
.
BlogPosts
.
as_view
(
)
view
=
ListOrCreateModelView
.
as_view
(
resource
=
urls
.
BlogPostResource
)
response
=
view
(
request
)
response
=
view
(
request
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_blogposts_not_exceed_MAX_POSTS
(
self
):
def
test_blogposts_not_exceed_MAX_POSTS
(
self
):
'''Posting blog-posts should not result in more than MAX_POSTS items stored.'''
'''Posting blog-posts should not result in more than MAX_POSTS items stored.'''
for
post
in
range
(
view
s
.
MAX_POSTS
+
5
):
for
post
in
range
(
model
s
.
MAX_POSTS
+
5
):
form_data
=
{
'title'
:
'This is post #
%
s'
%
post
,
'content'
:
'This is the content of post #
%
s'
%
post
}
form_data
=
{
'title'
:
'This is post #
%
s'
%
post
,
'content'
:
'This is the content of post #
%
s'
%
post
}
request
=
self
.
factory
.
post
(
'/blog-post'
,
data
=
form_data
)
request
=
self
.
factory
.
post
(
'/blog-post'
,
data
=
form_data
)
view
=
views
.
BlogPosts
.
as_view
(
)
view
=
ListOrCreateModelView
.
as_view
(
resource
=
urls
.
BlogPostResource
)
view
(
request
)
view
(
request
)
self
.
assertEquals
(
len
(
models
.
BlogPost
.
objects
.
all
()),
view
s
.
MAX_POSTS
)
self
.
assertEquals
(
len
(
models
.
BlogPost
.
objects
.
all
()),
model
s
.
MAX_POSTS
)
def
test_fifo_behaviour
(
self
):
def
test_fifo_behaviour
(
self
):
'''It's fine that the Blogposts are capped off at MAX_POSTS. But we want to make sure we see FIFO behaviour.'''
'''It's fine that the Blogposts are capped off at MAX_POSTS. But we want to make sure we see FIFO behaviour.'''
for
post
in
range
(
15
):
for
post
in
range
(
15
):
form_data
=
{
'title'
:
'
%
s'
%
post
,
'content'
:
'This is the content of post #
%
s'
%
post
}
form_data
=
{
'title'
:
'
%
s'
%
post
,
'content'
:
'This is the content of post #
%
s'
%
post
}
request
=
self
.
factory
.
post
(
'/blog-post'
,
data
=
form_data
)
request
=
self
.
factory
.
post
(
'/blog-post'
,
data
=
form_data
)
view
=
views
.
BlogPosts
.
as_view
(
)
view
=
ListOrCreateModelView
.
as_view
(
resource
=
urls
.
BlogPostResource
)
view
(
request
)
view
(
request
)
request
=
self
.
factory
.
get
(
'/blog-post'
)
request
=
self
.
factory
.
get
(
'/blog-post'
)
view
=
views
.
BlogPosts
.
as_view
(
)
view
=
ListOrCreateModelView
.
as_view
(
resource
=
urls
.
BlogPostResource
)
response
=
view
(
request
)
response
=
view
(
request
)
response_posts
=
json
.
loads
(
response
.
content
)
response_posts
=
json
.
loads
(
response
.
content
)
response_titles
=
[
d
[
'title'
]
for
d
in
response_posts
]
response_titles
=
[
d
[
'title'
]
for
d
in
response_posts
]
self
.
assertEquals
(
response_titles
,
[
'
%
s'
%
i
for
i
in
range
(
views
.
MAX_POSTS
-
5
,
views
.
MAX_POSTS
+
5
)])
response_titles
.
reverse
()
self
.
assertEquals
(
response_titles
,
[
'
%
s'
%
i
for
i
in
range
(
models
.
MAX_POSTS
-
5
,
models
.
MAX_POSTS
+
5
)])
\ No newline at end of file
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