aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/tests/renderers.py
diff options
context:
space:
mode:
authorMarko Tibold2012-01-13 21:57:49 +0100
committerMarko Tibold2012-01-13 21:57:49 +0100
commit905dd2ed9d74c660cc59be87a816326841db2fcb (patch)
tree29732dd95da0426ff79c4f65ea5914ba435cbff0 /djangorestframework/tests/renderers.py
parentc204101563bce0997e46ad5381d6d410f570b233 (diff)
downloaddjango-rest-framework-905dd2ed9d74c660cc59be87a816326841db2fcb.tar.bz2
Got rid of more duplicate tests and put back the tests for #122.
Diffstat (limited to 'djangorestframework/tests/renderers.py')
-rw-r--r--djangorestframework/tests/renderers.py96
1 files changed, 21 insertions, 75 deletions
diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py
index 142791e4..9e10a32c 100644
--- a/djangorestframework/tests/renderers.py
+++ b/djangorestframework/tests/renderers.py
@@ -57,6 +57,7 @@ class HTMLView(View):
def get(self, request, **kwargs):
return 'text'
+
class HTMLView1(View):
renderers = (DocumentingHTMLRenderer, JSONRenderer)
@@ -283,80 +284,6 @@ if YAMLRenderer:
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):
"""
@@ -452,4 +379,23 @@ class XMLRendererTestCase(TestCase):
def assertXMLContains(self, xml, string):
self.assertTrue(xml.startswith('<?xml version="1.0" encoding="utf-8"?>\n<root>'))
self.assertTrue(xml.endswith('</root>'))
- self.assertTrue(string in xml, '%r not in %r' % (string, xml)) \ No newline at end of file
+ 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')