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
905dd2ed
Commit
905dd2ed
authored
Jan 13, 2012
by
Marko Tibold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Got rid of more duplicate tests and put back the tests for #122.
parent
c2041015
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
74 deletions
+20
-74
djangorestframework/tests/renderers.py
+20
-74
No files found.
djangorestframework/tests/renderers.py
View file @
905dd2ed
...
@@ -57,6 +57,7 @@ class HTMLView(View):
...
@@ -57,6 +57,7 @@ class HTMLView(View):
def
get
(
self
,
request
,
**
kwargs
):
def
get
(
self
,
request
,
**
kwargs
):
return
'text'
return
'text'
class
HTMLView1
(
View
):
class
HTMLView1
(
View
):
renderers
=
(
DocumentingHTMLRenderer
,
JSONRenderer
)
renderers
=
(
DocumentingHTMLRenderer
,
JSONRenderer
)
...
@@ -283,80 +284,6 @@ if YAMLRenderer:
...
@@ -283,80 +284,6 @@ if YAMLRenderer:
self
.
assertEquals
(
obj
,
data
)
self
.
assertEquals
(
obj
,
data
)
urlpatterns
+=
patterns
(
''
,
url
(
r'^/html$'
,
HTMLView
.
as_view
()),
)
class
Issue122Tests
(
TestCase
):
"""
Tests that cover issues.
"""
urls
=
'djangorestframework.tests.renderers'
def
test_without_callback_with_json_renderer
(
self
):
"""
Test JSONP rendering with View JSON Renderer.
"""
resp
=
self
.
client
.
get
(
'/jsonp/jsonrenderer'
,
HTTP_ACCEPT
=
'application/json-p'
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
self
.
assertEquals
(
resp
[
'Content-Type'
],
'application/json-p'
)
self
.
assertEquals
(
resp
.
content
,
'callback(
%
s);'
%
_flat_repr
)
def
test_without_callback_without_json_renderer
(
self
):
"""
Test JSONP rendering without View JSON Renderer.
"""
resp
=
self
.
client
.
get
(
'/jsonp/nojsonrenderer'
,
HTTP_ACCEPT
=
'application/json-p'
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
self
.
assertEquals
(
resp
[
'Content-Type'
],
'application/json-p'
)
self
.
assertEquals
(
resp
.
content
,
'callback(
%
s);'
%
_flat_repr
)
def
test_with_callback
(
self
):
"""
Test JSONP rendering with callback function name.
"""
callback_func
=
'myjsonpcallback'
resp
=
self
.
client
.
get
(
'/jsonp/nojsonrenderer?callback='
+
callback_func
,
HTTP_ACCEPT
=
'application/json-p'
)
self
.
assertEquals
(
resp
.
status_code
,
200
)
self
.
assertEquals
(
resp
[
'Content-Type'
],
'application/json-p'
)
self
.
assertEquals
(
resp
.
content
,
'
%
s(
%
s);'
%
(
callback_func
,
_flat_repr
))
if
YAMLRenderer
:
_yaml_repr
=
'foo: [bar, baz]
\n
'
class
YAMLRendererTests
(
TestCase
):
"""
Tests specific to the JSON Renderer
"""
def
test_render
(
self
):
"""
Test basic YAML rendering.
"""
obj
=
{
'foo'
:
[
'bar'
,
'baz'
]}
renderer
=
YAMLRenderer
(
None
)
content
=
renderer
.
render
(
obj
,
'application/yaml'
)
self
.
assertEquals
(
content
,
_yaml_repr
)
def
test_render_and_parse
(
self
):
"""
Test rendering and then parsing returns the original object.
IE obj -> render -> parse -> obj.
"""
obj
=
{
'foo'
:
[
'bar'
,
'baz'
]}
renderer
=
YAMLRenderer
(
None
)
parser
=
YAMLParser
(
None
)
content
=
renderer
.
render
(
obj
,
'application/yaml'
)
(
data
,
files
)
=
parser
.
parse
(
StringIO
(
content
))
self
.
assertEquals
(
obj
,
data
)
class
XMLRendererTestCase
(
TestCase
):
class
XMLRendererTestCase
(
TestCase
):
"""
"""
...
@@ -453,3 +380,22 @@ class XMLRendererTestCase(TestCase):
...
@@ -453,3 +380,22 @@ class XMLRendererTestCase(TestCase):
self
.
assertTrue
(
xml
.
startswith
(
'<?xml version="1.0" encoding="utf-8"?>
\n
<root>'
))
self
.
assertTrue
(
xml
.
startswith
(
'<?xml version="1.0" encoding="utf-8"?>
\n
<root>'
))
self
.
assertTrue
(
xml
.
endswith
(
'</root>'
))
self
.
assertTrue
(
xml
.
endswith
(
'</root>'
))
self
.
assertTrue
(
string
in
xml
,
'
%
r not in
%
r'
%
(
string
,
xml
))
self
.
assertTrue
(
string
in
xml
,
'
%
r not in
%
r'
%
(
string
,
xml
))
class
Issue122Tests
(
TestCase
):
"""
Tests that covers #122.
"""
urls
=
'djangorestframework.tests.renderers'
def
test_only_html_renderer
(
self
):
"""
Test if no infinite recursion occurs.
"""
resp
=
self
.
client
.
get
(
'/html'
)
def
test_html_renderer_is_first
(
self
):
"""
Test if no infinite recursion occurs.
"""
resp
=
self
.
client
.
get
(
'/html1'
)
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