mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
Fixed #18269 -- Applied unicode_literals for Python 3 compatibility.
Thanks Vinay Sajip for the support of his django3 branch and Jannis Leidel for the review.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
import re
|
||||
@@ -23,12 +23,12 @@ class DeletionTests(TestCase):
|
||||
PoetFormSet = modelformset_factory(Poet, can_delete=True)
|
||||
poet = Poet.objects.create(name='test')
|
||||
data = {
|
||||
'form-TOTAL_FORMS': u'1',
|
||||
'form-INITIAL_FORMS': u'1',
|
||||
'form-MAX_NUM_FORMS': u'0',
|
||||
'form-TOTAL_FORMS': '1',
|
||||
'form-INITIAL_FORMS': '1',
|
||||
'form-MAX_NUM_FORMS': '0',
|
||||
'form-0-id': str(poet.pk),
|
||||
'form-0-name': u'test',
|
||||
'form-0-DELETE': u'on',
|
||||
'form-0-name': 'test',
|
||||
'form-0-DELETE': 'on',
|
||||
}
|
||||
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
||||
formset.save()
|
||||
@@ -42,11 +42,11 @@ class DeletionTests(TestCase):
|
||||
"""
|
||||
PoetFormSet = modelformset_factory(Poet, can_delete=True)
|
||||
data = {
|
||||
'form-TOTAL_FORMS': u'1',
|
||||
'form-INITIAL_FORMS': u'0',
|
||||
'form-MAX_NUM_FORMS': u'0',
|
||||
'form-0-id': u'',
|
||||
'form-0-name': u'x' * 1000,
|
||||
'form-TOTAL_FORMS': '1',
|
||||
'form-INITIAL_FORMS': '0',
|
||||
'form-MAX_NUM_FORMS': '0',
|
||||
'form-0-id': '',
|
||||
'form-0-name': 'x' * 1000,
|
||||
}
|
||||
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
||||
# Make sure this form doesn't pass validation.
|
||||
@@ -69,11 +69,11 @@ class DeletionTests(TestCase):
|
||||
PoetFormSet = modelformset_factory(Poet, can_delete=True)
|
||||
poet = Poet.objects.create(name='test')
|
||||
data = {
|
||||
'form-TOTAL_FORMS': u'1',
|
||||
'form-INITIAL_FORMS': u'1',
|
||||
'form-MAX_NUM_FORMS': u'0',
|
||||
'form-TOTAL_FORMS': '1',
|
||||
'form-INITIAL_FORMS': '1',
|
||||
'form-MAX_NUM_FORMS': '0',
|
||||
'form-0-id': unicode(poet.id),
|
||||
'form-0-name': u'x' * 1000,
|
||||
'form-0-name': 'x' * 1000,
|
||||
}
|
||||
formset = PoetFormSet(data, queryset=Poet.objects.all())
|
||||
# Make sure this form doesn't pass validation.
|
||||
@@ -245,7 +245,7 @@ class ModelFormsetTest(TestCase):
|
||||
|
||||
# create an Author instance to add to the meeting.
|
||||
|
||||
author4 = Author.objects.create(name=u'John Steinbeck')
|
||||
author4 = Author.objects.create(name='John Steinbeck')
|
||||
|
||||
AuthorMeetingFormSet = modelformset_factory(AuthorMeeting, extra=1, can_delete=True)
|
||||
data = {
|
||||
@@ -329,7 +329,7 @@ class ModelFormsetTest(TestCase):
|
||||
def save(self, commit=True):
|
||||
# change the name to "Vladimir Mayakovsky" just to be a jerk.
|
||||
author = super(PoetForm, self).save(commit=False)
|
||||
author.name = u"Vladimir Mayakovsky"
|
||||
author.name = "Vladimir Mayakovsky"
|
||||
if commit:
|
||||
author.save()
|
||||
return author
|
||||
@@ -640,7 +640,7 @@ class ModelFormsetTest(TestCase):
|
||||
def save(self, commit=True):
|
||||
# change the name to "Brooklyn Bridge" just to be a jerk.
|
||||
poem = super(PoemForm, self).save(commit=False)
|
||||
poem.name = u"Brooklyn Bridge"
|
||||
poem.name = "Brooklyn Bridge"
|
||||
if commit:
|
||||
poem.save()
|
||||
return poem
|
||||
@@ -731,7 +731,7 @@ class ModelFormsetTest(TestCase):
|
||||
|
||||
# Custom primary keys with ForeignKey, OneToOneField and AutoField ############
|
||||
|
||||
place = Place.objects.create(pk=1, name=u'Giordanos', city=u'Chicago')
|
||||
place = Place.objects.create(pk=1, name='Giordanos', city='Chicago')
|
||||
|
||||
FormSet = inlineformset_factory(Place, Owner, extra=2, can_delete=False)
|
||||
formset = FormSet(instance=place)
|
||||
@@ -746,7 +746,7 @@ class ModelFormsetTest(TestCase):
|
||||
'owner_set-INITIAL_FORMS': '0',
|
||||
'owner_set-MAX_NUM_FORMS': '',
|
||||
'owner_set-0-auto_id': '',
|
||||
'owner_set-0-name': u'Joe Perry',
|
||||
'owner_set-0-name': 'Joe Perry',
|
||||
'owner_set-1-auto_id': '',
|
||||
'owner_set-1-name': '',
|
||||
}
|
||||
@@ -773,9 +773,9 @@ class ModelFormsetTest(TestCase):
|
||||
'owner_set-INITIAL_FORMS': '1',
|
||||
'owner_set-MAX_NUM_FORMS': '',
|
||||
'owner_set-0-auto_id': unicode(owner1.auto_id),
|
||||
'owner_set-0-name': u'Joe Perry',
|
||||
'owner_set-0-name': 'Joe Perry',
|
||||
'owner_set-1-auto_id': '',
|
||||
'owner_set-1-name': u'Jack Berry',
|
||||
'owner_set-1-name': 'Jack Berry',
|
||||
'owner_set-2-auto_id': '',
|
||||
'owner_set-2-name': '',
|
||||
}
|
||||
@@ -800,7 +800,7 @@ class ModelFormsetTest(TestCase):
|
||||
'<p><label for="id_form-0-age">Age:</label> <input type="text" name="form-0-age" id="id_form-0-age" /></p>'
|
||||
% (owner1.auto_id, owner2.auto_id))
|
||||
|
||||
owner1 = Owner.objects.get(name=u'Joe Perry')
|
||||
owner1 = Owner.objects.get(name='Joe Perry')
|
||||
FormSet = inlineformset_factory(Owner, OwnerProfile, max_num=1, can_delete=False)
|
||||
self.assertEqual(FormSet.max_num, 1)
|
||||
|
||||
@@ -815,7 +815,7 @@ class ModelFormsetTest(TestCase):
|
||||
'ownerprofile-INITIAL_FORMS': '0',
|
||||
'ownerprofile-MAX_NUM_FORMS': '1',
|
||||
'ownerprofile-0-owner': '',
|
||||
'ownerprofile-0-age': u'54',
|
||||
'ownerprofile-0-age': '54',
|
||||
}
|
||||
formset = FormSet(data, instance=owner1)
|
||||
self.assertTrue(formset.is_valid())
|
||||
@@ -836,7 +836,7 @@ class ModelFormsetTest(TestCase):
|
||||
'ownerprofile-INITIAL_FORMS': '1',
|
||||
'ownerprofile-MAX_NUM_FORMS': '1',
|
||||
'ownerprofile-0-owner': unicode(owner1.auto_id),
|
||||
'ownerprofile-0-age': u'55',
|
||||
'ownerprofile-0-age': '55',
|
||||
}
|
||||
formset = FormSet(data, instance=owner1)
|
||||
self.assertTrue(formset.is_valid())
|
||||
@@ -849,7 +849,7 @@ class ModelFormsetTest(TestCase):
|
||||
def test_unique_true_enforces_max_num_one(self):
|
||||
# ForeignKey with unique=True should enforce max_num=1
|
||||
|
||||
place = Place.objects.create(pk=1, name=u'Giordanos', city=u'Chicago')
|
||||
place = Place.objects.create(pk=1, name='Giordanos', city='Chicago')
|
||||
|
||||
FormSet = inlineformset_factory(Place, Location, can_delete=False)
|
||||
self.assertEqual(FormSet.max_num, 1)
|
||||
@@ -887,7 +887,7 @@ class ModelFormsetTest(TestCase):
|
||||
}
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset.errors, [{'slug': [u'Product with this Slug already exists.']}])
|
||||
self.assertEqual(formset.errors, [{'slug': ['Product with this Slug already exists.']}])
|
||||
|
||||
def test_unique_together_validation(self):
|
||||
FormSet = modelformset_factory(Price, extra=1)
|
||||
@@ -895,7 +895,7 @@ class ModelFormsetTest(TestCase):
|
||||
'form-TOTAL_FORMS': '1',
|
||||
'form-INITIAL_FORMS': '0',
|
||||
'form-MAX_NUM_FORMS': '',
|
||||
'form-0-price': u'12.00',
|
||||
'form-0-price': '12.00',
|
||||
'form-0-quantity': '1',
|
||||
}
|
||||
formset = FormSet(data)
|
||||
@@ -910,17 +910,17 @@ class ModelFormsetTest(TestCase):
|
||||
'form-TOTAL_FORMS': '1',
|
||||
'form-INITIAL_FORMS': '0',
|
||||
'form-MAX_NUM_FORMS': '',
|
||||
'form-0-price': u'12.00',
|
||||
'form-0-price': '12.00',
|
||||
'form-0-quantity': '1',
|
||||
}
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset.errors, [{'__all__': [u'Price with this Price and Quantity already exists.']}])
|
||||
self.assertEqual(formset.errors, [{'__all__': ['Price with this Price and Quantity already exists.']}])
|
||||
|
||||
def test_unique_together_with_inlineformset_factory(self):
|
||||
# Also see bug #8882.
|
||||
|
||||
repository = Repository.objects.create(name=u'Test Repo')
|
||||
repository = Repository.objects.create(name='Test Repo')
|
||||
FormSet = inlineformset_factory(Repository, Revision, extra=1)
|
||||
data = {
|
||||
'revision_set-TOTAL_FORMS': '1',
|
||||
@@ -949,7 +949,7 @@ class ModelFormsetTest(TestCase):
|
||||
}
|
||||
formset = FormSet(data, instance=repository)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset.errors, [{'__all__': [u'Revision with this Repository and Revision already exists.']}])
|
||||
self.assertEqual(formset.errors, [{'__all__': ['Revision with this Repository and Revision already exists.']}])
|
||||
|
||||
# unique_together with inlineformset_factory with overridden form fields
|
||||
# Also see #9494
|
||||
@@ -1040,7 +1040,7 @@ class ModelFormsetTest(TestCase):
|
||||
def test_inlineformset_factory_with_null_fk(self):
|
||||
# inlineformset_factory tests with fk having null=True. see #9462.
|
||||
# create some data that will exbit the issue
|
||||
team = Team.objects.create(name=u"Red Vipers")
|
||||
team = Team.objects.create(name="Red Vipers")
|
||||
Player(name="Timmy").save()
|
||||
Player(name="Bobby", team=team).save()
|
||||
|
||||
@@ -1073,7 +1073,7 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for slug.'])
|
||||
['Please correct the duplicate data for slug.'])
|
||||
|
||||
FormSet = modelformset_factory(Price, extra=2)
|
||||
data = {
|
||||
@@ -1088,7 +1088,7 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for price and quantity, which must be unique.'])
|
||||
['Please correct the duplicate data for price and quantity, which must be unique.'])
|
||||
|
||||
# Only the price field is specified, this should skip any unique checks since
|
||||
# the unique_together is not fulfilled. This will fail with a KeyError if broken.
|
||||
@@ -1126,9 +1126,9 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data=data, instance=author)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for title.'])
|
||||
['Please correct the duplicate data for title.'])
|
||||
self.assertEqual(formset.errors,
|
||||
[{}, {'__all__': [u'Please correct the duplicate values below.']}])
|
||||
[{}, {'__all__': ['Please correct the duplicate values below.']}])
|
||||
|
||||
FormSet = modelformset_factory(Post, extra=2)
|
||||
data = {
|
||||
@@ -1148,9 +1148,9 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for title which must be unique for the date in posted.'])
|
||||
['Please correct the duplicate data for title which must be unique for the date in posted.'])
|
||||
self.assertEqual(formset.errors,
|
||||
[{}, {'__all__': [u'Please correct the duplicate values below.']}])
|
||||
[{}, {'__all__': ['Please correct the duplicate values below.']}])
|
||||
|
||||
data = {
|
||||
'form-TOTAL_FORMS': '2',
|
||||
@@ -1169,7 +1169,7 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for slug which must be unique for the year in posted.'])
|
||||
['Please correct the duplicate data for slug which must be unique for the year in posted.'])
|
||||
|
||||
data = {
|
||||
'form-TOTAL_FORMS': '2',
|
||||
@@ -1188,4 +1188,4 @@ class ModelFormsetTest(TestCase):
|
||||
formset = FormSet(data)
|
||||
self.assertFalse(formset.is_valid())
|
||||
self.assertEqual(formset._non_form_errors,
|
||||
[u'Please correct the duplicate data for subtitle which must be unique for the month in posted.'])
|
||||
['Please correct the duplicate data for subtitle which must be unique for the month in posted.'])
|
||||
|
||||
Reference in New Issue
Block a user