From 905dd2ed9d74c660cc59be87a816326841db2fcb Mon Sep 17 00:00:00 2001 From: Marko Tibold Date: Fri, 13 Jan 2012 21:57:49 +0100 Subject: [PATCH] Got rid of more duplicate tests and put back the tests for #122. --- djangorestframework/tests/renderers.py | 96 ++++++-------------------- 1 file changed, 21 insertions(+), 75 deletions(-) diff --git a/djangorestframework/tests/renderers.py b/djangorestframework/tests/renderers.py index 142791e48..9e10a32cf 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('\n')) self.assertTrue(xml.endswith('')) - 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')