mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Marked bytestrings with b prefix. Refs #18269
This is a preparation for unicode literals general usage in Django (Python 3 compatibility).
This commit is contained in:
@@ -1126,7 +1126,7 @@ class OldFormForXTests(TestCase):
|
||||
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test1.txt', 'hello world')})
|
||||
files={'file': SimpleUploadedFile('test1.txt', b'hello world')})
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
||||
instance = f.save()
|
||||
@@ -1135,7 +1135,7 @@ class OldFormForXTests(TestCase):
|
||||
instance.file.delete()
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test1.txt', 'hello world')})
|
||||
files={'file': SimpleUploadedFile('test1.txt', b'hello world')})
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
self.assertEqual(type(f.cleaned_data['file']), SimpleUploadedFile)
|
||||
instance = f.save()
|
||||
@@ -1144,7 +1144,7 @@ class OldFormForXTests(TestCase):
|
||||
# Check if the max_length attribute has been inherited from the model.
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test-maxlength.txt', 'hello world')})
|
||||
files={'file': SimpleUploadedFile('test-maxlength.txt', b'hello world')})
|
||||
self.assertEqual(f.is_valid(), False)
|
||||
|
||||
# Edit an instance that already has the file defined in the model. This will not
|
||||
@@ -1165,7 +1165,7 @@ class OldFormForXTests(TestCase):
|
||||
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test2.txt', 'hello world')}, instance=instance)
|
||||
files={'file': SimpleUploadedFile('test2.txt', b'hello world')}, instance=instance)
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
instance = f.save()
|
||||
self.assertEqual(instance.file.name, 'tests/test2.txt')
|
||||
@@ -1174,7 +1174,7 @@ class OldFormForXTests(TestCase):
|
||||
instance.file.delete()
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test2.txt', 'hello world')})
|
||||
files={'file': SimpleUploadedFile('test2.txt', b'hello world')})
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
instance = f.save()
|
||||
self.assertEqual(instance.file.name, 'tests/test2.txt')
|
||||
@@ -1193,7 +1193,7 @@ class OldFormForXTests(TestCase):
|
||||
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test3.txt', 'hello world')}, instance=instance)
|
||||
files={'file': SimpleUploadedFile('test3.txt', b'hello world')}, instance=instance)
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
instance = f.save()
|
||||
self.assertEqual(instance.file.name, 'tests/test3.txt')
|
||||
@@ -1215,7 +1215,7 @@ class OldFormForXTests(TestCase):
|
||||
|
||||
f = TextFileForm(
|
||||
data={'description': u'Assistance'},
|
||||
files={'file': SimpleUploadedFile('test3.txt', 'hello world')})
|
||||
files={'file': SimpleUploadedFile('test3.txt', b'hello world')})
|
||||
self.assertEqual(f.is_valid(), True)
|
||||
instance = f.save()
|
||||
self.assertEqual(instance.file.name, 'tests/test3.txt')
|
||||
|
||||
@@ -113,8 +113,8 @@ class SerializersTestBase(object):
|
||||
Tests the ability to create new objects by
|
||||
modifying serialized content.
|
||||
"""
|
||||
old_headline = "Poker has no place on ESPN"
|
||||
new_headline = "Poker has no place on television"
|
||||
old_headline = b"Poker has no place on ESPN"
|
||||
new_headline = b"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)
|
||||
@@ -284,7 +284,7 @@ class SerializersTransactionTestBase(object):
|
||||
|
||||
class XmlSerializerTestCase(SerializersTestBase, TestCase):
|
||||
serializer_name = "xml"
|
||||
pkless_str = """<?xml version="1.0" encoding="utf-8"?>
|
||||
pkless_str = b"""<?xml version="1.0" encoding="utf-8"?>
|
||||
<django-objects version="1.0">
|
||||
<object model="serializers.category">
|
||||
<field type="CharField" name="name">Reference</field>
|
||||
@@ -330,7 +330,7 @@ class XmlSerializerTestCase(SerializersTestBase, TestCase):
|
||||
|
||||
class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
||||
serializer_name = "xml"
|
||||
fwd_ref_str = """<?xml version="1.0" encoding="utf-8"?>
|
||||
fwd_ref_str = b"""<?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>
|
||||
@@ -350,7 +350,7 @@ class XmlSerializerTransactionTestCase(SerializersTransactionTestBase, Transacti
|
||||
|
||||
class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
||||
serializer_name = "json"
|
||||
pkless_str = """[{"pk": null, "model": "serializers.category", "fields": {"name": "Reference"}}]"""
|
||||
pkless_str = b"""[{"pk": null, "model": "serializers.category", "fields": {"name": "Reference"}}]"""
|
||||
|
||||
@staticmethod
|
||||
def _validate_output(serial_str):
|
||||
@@ -380,7 +380,7 @@ class JsonSerializerTestCase(SerializersTestBase, TestCase):
|
||||
|
||||
class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
||||
serializer_name = "json"
|
||||
fwd_ref_str = """[
|
||||
fwd_ref_str = b"""[
|
||||
{
|
||||
"pk": 1,
|
||||
"model": "serializers.article",
|
||||
@@ -413,7 +413,7 @@ except ImportError:
|
||||
else:
|
||||
class YamlSerializerTestCase(SerializersTestBase, TestCase):
|
||||
serializer_name = "yaml"
|
||||
fwd_ref_str = """- fields:
|
||||
fwd_ref_str = b"""- fields:
|
||||
headline: Forward references pose no problem
|
||||
pub_date: 2006-06-16 15:00:00
|
||||
categories: [1]
|
||||
@@ -429,7 +429,7 @@ else:
|
||||
pk: 1
|
||||
model: serializers.author"""
|
||||
|
||||
pkless_str = """- fields:
|
||||
pkless_str = b"""- fields:
|
||||
name: Reference
|
||||
pk: null
|
||||
model: serializers.category"""
|
||||
@@ -469,7 +469,7 @@ else:
|
||||
|
||||
class YamlSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
|
||||
serializer_name = "yaml"
|
||||
fwd_ref_str = """- fields:
|
||||
fwd_ref_str = b"""- fields:
|
||||
headline: Forward references pose no problem
|
||||
pub_date: 2006-06-16 15:00:00
|
||||
categories: [1]
|
||||
|
||||
@@ -11,11 +11,11 @@ from .models import Article, InternationalArticle
|
||||
class SimpleTests(TestCase):
|
||||
def test_basic(self):
|
||||
a = Article.objects.create(
|
||||
headline='Area man programs in Python',
|
||||
headline=b'Area man programs in Python',
|
||||
pub_date=datetime.datetime(2005, 7, 28)
|
||||
)
|
||||
self.assertEqual(str(a), 'Area man programs in Python')
|
||||
self.assertEqual(repr(a), '<Article: Area man programs in Python>')
|
||||
self.assertEqual(str(a), b'Area man programs in Python')
|
||||
self.assertEqual(repr(a), b'<Article: Area man programs in Python>')
|
||||
|
||||
def test_international(self):
|
||||
a = InternationalArticle.objects.create(
|
||||
@@ -23,4 +23,4 @@ class SimpleTests(TestCase):
|
||||
pub_date=datetime.datetime(2005, 7, 28)
|
||||
)
|
||||
# The default str() output will be the UTF-8 encoded output of __unicode__().
|
||||
self.assertEqual(str(a), 'Girl wins \xe2\x82\xac12.500 in lottery')
|
||||
self.assertEqual(str(a), b'Girl wins \xe2\x82\xac12.500 in lottery')
|
||||
|
||||
Reference in New Issue
Block a user