Fix failing YAML tests

This commit is contained in:
José Padilla 2014-11-25 11:33:18 -04:00
parent e1b8412eed
commit 653d626b3c

View File

@ -9,7 +9,7 @@ from django.test import TestCase
from django.utils import six, unittest from django.utils import six, unittest
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import status, permissions from rest_framework import status, permissions
from rest_framework.compat import yaml, etree, StringIO from rest_framework.compat import yaml, etree, StringIO, BytesIO
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \ from rest_framework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \
@ -467,7 +467,7 @@ if yaml:
obj = {'foo': ['bar', 'baz']} obj = {'foo': ['bar', 'baz']}
renderer = YAMLRenderer() renderer = YAMLRenderer()
content = renderer.render(obj, 'application/yaml') content = renderer.render(obj, 'application/yaml')
self.assertEqual(content, _yaml_repr) self.assertEqual(content.decode('utf-8'), _yaml_repr)
def test_render_and_parse(self): def test_render_and_parse(self):
""" """
@ -480,7 +480,7 @@ if yaml:
parser = YAMLParser() parser = YAMLParser()
content = renderer.render(obj, 'application/yaml') content = renderer.render(obj, 'application/yaml')
data = parser.parse(StringIO(content)) data = parser.parse(BytesIO(content))
self.assertEqual(obj, data) self.assertEqual(obj, data)
def test_render_decimal(self): def test_render_decimal(self):
@ -489,7 +489,7 @@ if yaml:
""" """
renderer = YAMLRenderer() renderer = YAMLRenderer()
content = renderer.render({'field': Decimal('111.2')}, 'application/yaml') content = renderer.render({'field': Decimal('111.2')}, 'application/yaml')
self.assertYAMLContains(content, "field: '111.2'") self.assertYAMLContains(content.decode('utf-8'), "field: '111.2'")
def assertYAMLContains(self, content, string): def assertYAMLContains(self, content, string):
self.assertTrue(string in content, '%r not in %r' % (string, content)) self.assertTrue(string in content, '%r not in %r' % (string, content))