Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[py3] Fixed serializers tests

  • Loading branch information...
commit f2fe7a3e36bebb529f33f5b702b7643a3db85c72 1 parent 7d48e07
@claudep claudep authored
View
6 django/core/serializers/base.py
@@ -2,8 +2,6 @@
Module for abstract serializer/unserializer base classes.
"""
-from io import BytesIO
-
from django.db import models
from django.utils.encoding import smart_text
from django.utils import six
@@ -35,7 +33,7 @@ def serialize(self, queryset, **options):
"""
self.options = options
- self.stream = options.pop("stream", BytesIO())
+ self.stream = options.pop("stream", six.StringIO())
self.selected_fields = options.pop("fields", None)
self.use_natural_keys = options.pop("use_natural_keys", False)
@@ -125,7 +123,7 @@ def __init__(self, stream_or_string, **options):
"""
self.options = options
if isinstance(stream_or_string, six.string_types):
- self.stream = BytesIO(stream_or_string)
+ self.stream = six.StringIO(stream_or_string)
else:
self.stream = stream_or_string
# hack to make sure that the models have all been loaded before
View
18 tests/modeltests/serializers/tests.py
@@ -114,8 +114,8 @@ def test_altering_serialized_output(self):
Tests the ability to create new objects by
modifying serialized content.
"""
- old_headline = b"Poker has no place on ESPN"
- new_headline = b"Poker has no place on television"
+ old_headline = "Poker has no place on ESPN"
+ new_headline = "Poker has no place on television"
serial_str = serializers.serialize(self.serializer_name,
Article.objects.all())
serial_str = serial_str.replace(old_headline, new_headline)
@@ -285,7 +285,7 @@ def test_forward_refs(self):
class XmlSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "xml"
- pkless_str = b"""<?xml version="1.0" encoding="utf-8"?>
+ pkless_str = """<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object model="serializers.category">
<field type="CharField" name="name">Reference</field>
@@ -331,7 +331,7 @@ def _get_field_values(serial_str, field_name):
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "xml"
- fwd_ref_str = b"""<?xml version="1.0" encoding="utf-8"?>
+ fwd_ref_str = """<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
<object pk="1" model="serializers.article">
<field to="serializers.author" name="author" rel="ManyToOneRel">1</field>
@@ -351,7 +351,7 @@ class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, Transacti
class JsonSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "json"
- pkless_str = b"""[{"pk": null, "model": "serializers.category", "fields": {"name": "Reference"}}]"""
+ pkless_str = """[{"pk": null, "model": "serializers.category", "fields": {"name": "Reference"}}]"""
@staticmethod
def _validate_output(serial_str):
@@ -381,7 +381,7 @@ def _get_field_values(serial_str, field_name):
class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "json"
- fwd_ref_str = b"""[
+ fwd_ref_str = """[
{
"pk": 1,
"model": "serializers.article",
@@ -414,7 +414,7 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
else:
class YamlSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "yaml"
- fwd_ref_str = b"""- fields:
+ fwd_ref_str = """- fields:
headline: Forward references pose no problem
pub_date: 2006-06-16 15:00:00
categories: [1]
@@ -430,7 +430,7 @@ class YamlSerializerTestCase(SerializersTestBase, TestCase):
pk: 1
model: serializers.author"""
- pkless_str = b"""- fields:
+ pkless_str = """- fields:
name: Reference
pk: null
model: serializers.category"""
@@ -470,7 +470,7 @@ def _get_field_values(serial_str, field_name):
class YamlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "yaml"
- fwd_ref_str = b"""- fields:
+ fwd_ref_str = """- fields:
headline: Forward references pose no problem
pub_date: 2006-06-16 15:00:00
categories: [1]
View
8 tests/regressiontests/serializers_regress/tests.py
@@ -10,7 +10,6 @@
import datetime
import decimal
-from io import BytesIO
try:
import yaml
@@ -23,6 +22,7 @@
from django.db import connection, models
from django.http import HttpResponse
from django.test import TestCase
+from django.utils import six
from django.utils.functional import curry
from django.utils.unittest import skipUnless
@@ -502,17 +502,17 @@ def streamTest(format, self):
obj.save_base(raw=True)
# Serialize the test database to a stream
- for stream in (BytesIO(), HttpResponse()):
+ for stream in (six.StringIO(), HttpResponse()):
serializers.serialize(format, [obj], indent=2, stream=stream)
# Serialize normally for a comparison
string_data = serializers.serialize(format, [obj], indent=2)
# Check that the two are the same
- if isinstance(stream, BytesIO):
+ if isinstance(stream, six.StringIO):
self.assertEqual(string_data, stream.getvalue())
else:
- self.assertEqual(string_data, stream.content)
+ self.assertEqual(string_data, stream.content.decode('utf-8'))
stream.close()
for format in serializers.get_serializer_formats():
Please sign in to comment.
Something went wrong with that request. Please try again.