From 4df45418f2b27dde75364ab5803ebbc4b0cc9c0a Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Sun, 21 Aug 2011 18:09:08 +0000 Subject: [PATCH] Fixed #16644 -- Fixed one additional test that was failing in Oracle due to false assumptions about the primary keys of objects. Thanks Aymeric Augustin for report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16636 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/tests.py | 151 +++++++++++++------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py index 0831035a550..09a9d3f591a 100644 --- a/tests/modeltests/model_forms/tests.py +++ b/tests/modeltests/model_forms/tests.py @@ -658,21 +658,21 @@ class OldFormForXTests(TestCase): Pub date: Writer: Article: Categories:
Hold down "Control", or "Command" on a Mac, to select more than one. Status:''') +''' % (w_woodward.pk, w_royko.pk, c1.pk, c2.pk, c3.pk)) # You can restrict a form to a subset of the complete list of fields # by providing a 'fields' argument. If you try to save a @@ -706,21 +706,21 @@ class OldFormForXTests(TestCase):
  • Pub date:
  • Writer:
  • Article:
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • Status:
  • ''') +''' % (w_woodward.pk, w_royko.pk, c1.pk, c2.pk, c3.pk)) f = TestArticleForm({ 'headline': u'Test headline', 'slug': 'test-headline', @@ -760,21 +760,21 @@ class OldFormForXTests(TestCase):
  • Pub date:
  • Writer:
  • Article:
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • Status:
  • ''') +''' % (w_woodward.pk, w_royko.pk, c1.pk, c2.pk, c3.pk)) # Initial values can be provided for model forms f = TestArticleForm( @@ -788,21 +788,21 @@ class OldFormForXTests(TestCase):
  • Pub date:
  • Writer:
  • Article:
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • Status:
  • ''') +''' % (w_woodward.pk, w_royko.pk, c1.pk, c2.pk, c3.pk)) f = TestArticleForm({ 'headline': u'New headline', @@ -882,57 +882,58 @@ class OldFormForXTests(TestCase):
  • Pub date:
  • Writer:
  • Article:
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • Status:
  • ''') +''' % (w_woodward.pk, w_royko.pk, c1.pk, c2.pk, c3.pk)) c4 = Category.objects.create(name='Fourth', url='4th') self.assertEqual(c4.name, 'Fourth') - self.assertEqual(Writer.objects.create(name='Carl Bernstein').name, 'Carl Bernstein') + w_bernstein = Writer.objects.create(name='Carl Bernstein') + self.assertEqual(w_bernstein.name, 'Carl Bernstein') self.assertEqual(f.as_ul(), '''
  • Headline:
  • Slug:
  • Pub date:
  • Writer:
  • Article:
  • Categories: Hold down "Control", or "Command" on a Mac, to select more than one.
  • Status:
  • ''') +''' % (w_woodward.pk, w_bernstein.pk, w_royko.pk, c1.pk, c2.pk, c3.pk, c4.pk)) # ModelChoiceField ############################################################ f = forms.ModelChoiceField(Category.objects.all()) self.assertEqual(list(f.choices), [ (u'', u'---------'), - (1, u'Entertainment'), - (2, u"It's a test"), - (3, u'Third'), - (4, u'Fourth')]) + (c1.pk, u'Entertainment'), + (c2.pk, u"It's a test"), + (c3.pk, u'Third'), + (c4.pk, u'Fourth')]) with self.assertRaises(ValidationError): f.clean('') with self.assertRaises(ValidationError): @@ -967,9 +968,9 @@ class OldFormForXTests(TestCase): f.queryset = Category.objects.exclude(name='Fourth') self.assertEqual(list(f.choices), [ (u'', u'---------'), - (1, u'Entertainment'), - (2, u"It's a test"), - (3, u'Third')]) + (c1.pk, u'Entertainment'), + (c2.pk, u"It's a test"), + (c3.pk, u'Third')]) self.assertEqual(f.clean(c3.id).name, 'Third') with self.assertRaises(ValidationError): f.clean(c4.id) @@ -977,31 +978,31 @@ class OldFormForXTests(TestCase): # check that we can safely iterate choices repeatedly gen_one = list(f.choices) gen_two = f.choices - self.assertEqual(gen_one[2], (2, u"It's a test")) + self.assertEqual(gen_one[2], (c2.pk, u"It's a test")) self.assertEqual(list(gen_two), [ (u'', u'---------'), - (1, u'Entertainment'), - (2, u"It's a test"), - (3, u'Third')]) + (c1.pk, u'Entertainment'), + (c2.pk, u"It's a test"), + (c3.pk, u'Third')]) # check that we can override the label_from_instance method to print custom labels (#4620) f.queryset = Category.objects.all() f.label_from_instance = lambda obj: "category " + str(obj) self.assertEqual(list(f.choices), [ (u'', u'---------'), - (1, 'category Entertainment'), - (2, "category It's a test"), - (3, 'category Third'), - (4, 'category Fourth')]) + (c1.pk, 'category Entertainment'), + (c2.pk, "category It's a test"), + (c3.pk, 'category Third'), + (c4.pk, 'category Fourth')]) # ModelMultipleChoiceField #################################################### f = forms.ModelMultipleChoiceField(Category.objects.all()) self.assertEqual(list(f.choices), [ - (1, u'Entertainment'), - (2, u"It's a test"), - (3, u'Third'), - (4, u'Fourth')]) + (c1.pk, u'Entertainment'), + (c2.pk, u"It's a test"), + (c3.pk, u'Third'), + (c4.pk, u'Fourth')]) with self.assertRaises(ValidationError): f.clean(None) with self.assertRaises(ValidationError): @@ -1046,9 +1047,9 @@ class OldFormForXTests(TestCase): # queryset can be changed after the field is created. f.queryset = Category.objects.exclude(name='Fourth') self.assertEqual(list(f.choices), [ - (1, u'Entertainment'), - (2, u"It's a test"), - (3, u'Third')]) + (c1.pk, u'Entertainment'), + (c2.pk, u"It's a test"), + (c3.pk, u'Third')]) self.assertEqual(map(lambda o: o.name, f.clean([c3.id])), ["Third"]) with self.assertRaises(ValidationError): f.clean([c4.id]) @@ -1058,10 +1059,10 @@ class OldFormForXTests(TestCase): f.queryset = Category.objects.all() f.label_from_instance = lambda obj: "multicategory " + str(obj) self.assertEqual(list(f.choices), [ - (1, 'multicategory Entertainment'), - (2, "multicategory It's a test"), - (3, 'multicategory Third'), - (4, 'multicategory Fourth')]) + (c1.pk, 'multicategory Entertainment'), + (c2.pk, "multicategory It's a test"), + (c3.pk, 'multicategory Third'), + (c4.pk, 'multicategory Fourth')]) # OneToOneField ############################################################### @@ -1082,12 +1083,12 @@ class OldFormForXTests(TestCase): form = WriterProfileForm() self.assertEqual(form.as_p(), '''

    -

    ''') +

    ''' % (w_woodward.pk, w_bernstein.pk, bw.pk, w_royko.pk)) data = { 'writer': unicode(w_woodward.pk), @@ -1100,12 +1101,12 @@ class OldFormForXTests(TestCase): form = WriterProfileForm(instance=instance) self.assertEqual(form.as_p(), '''

    -

    ''') +

    ''' % (w_woodward.pk, w_bernstein.pk, bw.pk, w_royko.pk)) def test_phone_number_field(self): f = PhoneNumberForm({'phone': '(312) 555-1212', 'description': 'Assistance'})