Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed a bunch more tests that were failing in Oracle due to f…

…alse assumptions about the primary keys of objects.

Backport of r15789 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15790 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ec7dd583f2b33aa9a575530fbec215426348fdf6 1 parent 317f30a
Ian Kelly authored March 10, 2011
2  tests/modeltests/field_subclassing/tests.py
@@ -55,7 +55,7 @@ def test_custom_field(self):
55 55
 
56 56
         # Serialization works, too.
57 57
         stream = serializers.serialize("json", MyModel.objects.all())
58  
-        self.assertEqual(stream, '[{"pk": 1, "model": "field_subclassing.mymodel", "fields": {"data": "12", "name": "m"}}]')
  58
+        self.assertEqual(stream, '[{"pk": %d, "model": "field_subclassing.mymodel", "fields": {"data": "12", "name": "m"}}]' % m1.pk)
59 59
 
60 60
         obj = list(serializers.deserialize("json", stream))[0]
61 61
         self.assertEqual(obj.object, m)
2  tests/modeltests/fixtures/tests.py
@@ -3,6 +3,7 @@
3 3
 
4 4
 from django.test import TestCase, TransactionTestCase
5 5
 from django.conf import settings
  6
+from django.contrib.sites.models import Site
6 7
 from django.core import management
7 8
 from django.db import DEFAULT_DB_ALIAS
8 9
 
@@ -38,6 +39,7 @@ def test_initial_data(self):
38 39
     def test_loading_and_dumping(self):
39 40
         new_io = StringIO.StringIO()
40 41
 
  42
+        Site.objects.all().delete()
41 43
         # Load fixture 1. Single JSON file, with two objects.
42 44
         management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
43 45
         self.assertQuerysetEqual(Article.objects.all(), [
187  tests/modeltests/model_forms/models.py
@@ -472,8 +472,8 @@ class FlexibleDatePost(models.Model):
472 472
 u'Entertainment'
473 473
 >>> f.cleaned_data['slug']
474 474
 u'entertainment'
475  
->>> obj = f.save()
476  
->>> obj
  475
+>>> c1 = f.save()
  476
+>>> c1
477 477
 <Category: Entertainment>
478 478
 >>> Category.objects.all()
479 479
 [<Category: Entertainment>]
@@ -487,8 +487,8 @@ class FlexibleDatePost(models.Model):
487 487
 u"It's a test"
488 488
 >>> f.cleaned_data['slug']
489 489
 u'its-test'
490  
->>> obj = f.save()
491  
->>> obj
  490
+>>> c2 = f.save()
  491
+>>> c2
492 492
 <Category: It's a test>
493 493
 >>> Category.objects.order_by('name')
494 494
 [<Category: Entertainment>, <Category: It's a test>]
@@ -505,12 +505,12 @@ class FlexibleDatePost(models.Model):
505 505
 u'Third test'
506 506
 >>> f.cleaned_data['slug']
507 507
 u'third-test'
508  
->>> obj = f.save(commit=False)
509  
->>> obj
  508
+>>> c3 = f.save(commit=False)
  509
+>>> c3
510 510
 <Category: Third test>
511 511
 >>> Category.objects.order_by('name')
512 512
 [<Category: Entertainment>, <Category: It's a test>]
513  
->>> obj.save()
  513
+>>> c3.save()
514 514
 >>> Category.objects.order_by('name')
515 515
 [<Category: Entertainment>, <Category: It's a test>, <Category: Third test>]
516 516
 
@@ -563,9 +563,9 @@ class FlexibleDatePost(models.Model):
563 563
 <option value="3">Live</option>
564 564
 </select></td></tr>
565 565
 <tr><th>Categories:</th><td><select multiple="multiple" name="categories">
566  
-<option value="1">Entertainment</option>
567  
-<option value="2">It&#39;s a test</option>
568  
-<option value="3">Third test</option>
  566
+<option value="...">Entertainment</option>
  567
+<option value="...">It&#39;s a test</option>
  568
+<option value="...">Third test</option>
569 569
 </select><br /> Hold down "Control", or "Command" on a Mac, to select more than one.</td></tr>
570 570
 
571 571
 You can restrict a form to a subset of the complete list of fields
@@ -595,8 +595,9 @@ class FlexibleDatePost(models.Model):
595 595
 
596 596
 >>> art = Article(headline='Test article', slug='test-article', pub_date=datetime.date(1988, 1, 4), writer=w, article='Hello.')
597 597
 >>> art.save()
598  
->>> art.id
599  
-1
  598
+>>> art_id_1 = art.id
  599
+>>> art_id_1 is not None
  600
+True
600 601
 >>> class TestArticleForm(ModelForm):
601 602
 ...     class Meta:
602 603
 ...         model = Article
@@ -618,9 +619,9 @@ class FlexibleDatePost(models.Model):
618 619
 <option value="3">Live</option>
619 620
 </select></li>
620 621
 <li>Categories: <select multiple="multiple" name="categories">
621  
-<option value="1">Entertainment</option>
622  
-<option value="2">It&#39;s a test</option>
623  
-<option value="3">Third test</option>
  622
+<option value="...">Entertainment</option>
  623
+<option value="...">It&#39;s a test</option>
  624
+<option value="...">Third test</option>
624 625
 </select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
625 626
 >>> f = TestArticleForm({'headline': u'Test headline', 'slug': 'test-headline', 'pub_date': u'1984-02-06', 'writer': unicode(w_royko.pk), 'article': 'Hello.'}, instance=art)
626 627
 >>> f.errors
@@ -628,9 +629,9 @@ class FlexibleDatePost(models.Model):
628 629
 >>> f.is_valid()
629 630
 True
630 631
 >>> test_art = f.save()
631  
->>> test_art.id
632  
-1
633  
->>> test_art = Article.objects.get(id=1)
  632
+>>> test_art.id == art_id_1
  633
+True
  634
+>>> test_art = Article.objects.get(id=art_id_1)
634 635
 >>> test_art.headline
635 636
 u'Test headline'
636 637
 
@@ -648,9 +649,9 @@ class FlexibleDatePost(models.Model):
648 649
 >>> f.is_valid()
649 650
 True
650 651
 >>> new_art = f.save()
651  
->>> new_art.id
652  
-1
653  
->>> new_art = Article.objects.get(id=1)
  652
+>>> new_art.id == art_id_1
  653
+True
  654
+>>> new_art = Article.objects.get(id=art_id_1)
654 655
 >>> new_art.headline
655 656
 u'New headline'
656 657
 
@@ -681,13 +682,13 @@ class FlexibleDatePost(models.Model):
681 682
 <option value="3">Live</option>
682 683
 </select></li>
683 684
 <li>Categories: <select multiple="multiple" name="categories">
684  
-<option value="1" selected="selected">Entertainment</option>
685  
-<option value="2">It&#39;s a test</option>
686  
-<option value="3">Third test</option>
  685
+<option value="..." selected="selected">Entertainment</option>
  686
+<option value="...">It&#39;s a test</option>
  687
+<option value="...">Third test</option>
687 688
 </select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
688 689
 
689 690
 Initial values can be provided for model forms
690  
->>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': ['1','2']})
  691
+>>> f = TestArticleForm(auto_id=False, initial={'headline': 'Your headline here', 'categories': [str(c1.id), str(c2.id)]})
691 692
 >>> print f.as_ul()
692 693
 <li>Headline: <input type="text" name="headline" value="Your headline here" maxlength="50" /></li>
693 694
 <li>Slug: <input type="text" name="slug" maxlength="50" /></li>
@@ -705,17 +706,17 @@ class FlexibleDatePost(models.Model):
705 706
 <option value="3">Live</option>
706 707
 </select></li>
707 708
 <li>Categories: <select multiple="multiple" name="categories">
708  
-<option value="1" selected="selected">Entertainment</option>
709  
-<option value="2" selected="selected">It&#39;s a test</option>
710  
-<option value="3">Third test</option>
  709
+<option value="..." selected="selected">Entertainment</option>
  710
+<option value="..." selected="selected">It&#39;s a test</option>
  711
+<option value="...">Third test</option>
711 712
 </select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
712 713
 
713 714
 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
714  
-...     'writer': unicode(w_royko.pk), 'article': u'Hello.', 'categories': [u'1', u'2']}, instance=new_art)
  715
+...     'writer': unicode(w_royko.pk), 'article': u'Hello.', 'categories': [unicode(c1.id), unicode(c2.id)]}, instance=new_art)
715 716
 >>> new_art = f.save()
716  
->>> new_art.id
717  
-1
718  
->>> new_art = Article.objects.get(id=1)
  717
+>>> new_art.id == art_id_1
  718
+True
  719
+>>> new_art = Article.objects.get(id=art_id_1)
719 720
 >>> new_art.categories.order_by('name')
720 721
 [<Category: Entertainment>, <Category: It's a test>]
721 722
 
@@ -723,9 +724,9 @@ class FlexibleDatePost(models.Model):
723 724
 >>> f = TestArticleForm({'headline': u'New headline', 'slug': u'new-headline', 'pub_date': u'1988-01-04',
724 725
 ...     'writer': unicode(w_royko.pk), 'article': u'Hello.'}, instance=new_art)
725 726
 >>> new_art = f.save()
726  
->>> new_art.id
727  
-1
728  
->>> new_art = Article.objects.get(id=1)
  727
+>>> new_art.id == art_id_1
  728
+True
  729
+>>> new_art = Article.objects.get(id=art_id_1)
729 730
 >>> new_art.categories.all()
730 731
 []
731 732
 
@@ -734,11 +735,12 @@ class FlexibleDatePost(models.Model):
734 735
 ...     class Meta:
735 736
 ...         model = Article
736 737
 >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01',
737  
-...     'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']})
  738
+...     'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [unicode(c1.id), unicode(c2.id)]})
738 739
 >>> new_art = f.save()
739  
->>> new_art.id
740  
-2
741  
->>> new_art = Article.objects.get(id=2)
  740
+>>> art_id_2 = new_art.id
  741
+>>> art_id_2 not in (None, art_id_1)
  742
+True
  743
+>>> new_art = Article.objects.get(id=art_id_2)
742 744
 >>> new_art.categories.order_by('name')
743 745
 [<Category: Entertainment>, <Category: It's a test>]
744 746
 
@@ -749,9 +751,10 @@ class FlexibleDatePost(models.Model):
749 751
 >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': u'walrus-was-paul', 'pub_date': u'1967-11-01',
750 752
 ...     'writer': unicode(w_royko.pk), 'article': u'Test.'})
751 753
 >>> new_art = f.save()
752  
->>> new_art.id
753  
-3
754  
->>> new_art = Article.objects.get(id=3)
  754
+>>> art_id_3 = new_art.id
  755
+>>> art_id_3 not in (None, art_id_1, art_id_2)
  756
+True
  757
+>>> new_art = Article.objects.get(id=art_id_3)
755 758
 >>> new_art.categories.all()
756 759
 []
757 760
 
@@ -761,16 +764,17 @@ class FlexibleDatePost(models.Model):
761 764
 ...     class Meta:
762 765
 ...         model = Article
763 766
 >>> f = ArticleForm({'headline': u'The walrus was Paul', 'slug': 'walrus-was-paul', 'pub_date': u'1967-11-01',
764  
-...     'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [u'1', u'2']})
  767
+...     'writer': unicode(w_royko.pk), 'article': u'Test.', 'categories': [unicode(c1.id), unicode(c2.id)]})
765 768
 >>> new_art = f.save(commit=False)
766 769
 
767 770
 # Manually save the instance
768 771
 >>> new_art.save()
769  
->>> new_art.id
770  
-4
  772
+>>> art_id_4 = new_art.id
  773
+>>> art_id_4 not in (None, art_id_1, art_id_2, art_id_3)
  774
+True
771 775
 
772 776
 # The instance doesn't have m2m data yet
773  
->>> new_art = Article.objects.get(id=4)
  777
+>>> new_art = Article.objects.get(id=art_id_4)
774 778
 >>> new_art.categories.all()
775 779
 []
776 780
 
@@ -789,12 +793,12 @@ class FlexibleDatePost(models.Model):
789 793
 >>> cat = Category.objects.get(name='Third test')
790 794
 >>> cat
791 795
 <Category: Third test>
792  
->>> cat.id
793  
-3
  796
+>>> cat.id == c3.id
  797
+True
794 798
 >>> form = ShortCategory({'name': 'Third', 'slug': 'third', 'url': '3rd'}, instance=cat)
795 799
 >>> form.save()
796 800
 <Category: Third>
797  
->>> Category.objects.get(id=3)
  801
+>>> Category.objects.get(id=c3.id)
798 802
 <Category: Third>
799 803
 
800 804
 Here, we demonstrate that choices for a ForeignKey ChoiceField are determined
@@ -821,11 +825,12 @@ class FlexibleDatePost(models.Model):
821 825
 <option value="3">Live</option>
822 826
 </select></li>
823 827
 <li>Categories: <select multiple="multiple" name="categories">
824  
-<option value="1">Entertainment</option>
825  
-<option value="2">It&#39;s a test</option>
826  
-<option value="3">Third</option>
  828
+<option value="...">Entertainment</option>
  829
+<option value="...">It&#39;s a test</option>
  830
+<option value="...">Third</option>
827 831
 </select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
828  
->>> Category.objects.create(name='Fourth', url='4th')
  832
+>>> c4 = Category.objects.create(name='Fourth', url='4th')
  833
+>>> c4
829 834
 <Category: Fourth>
830 835
 >>> Writer.objects.create(name='Carl Bernstein')
831 836
 <Writer: Carl Bernstein>
@@ -847,10 +852,10 @@ class FlexibleDatePost(models.Model):
847 852
 <option value="3">Live</option>
848 853
 </select></li>
849 854
 <li>Categories: <select multiple="multiple" name="categories">
850  
-<option value="1">Entertainment</option>
851  
-<option value="2">It&#39;s a test</option>
852  
-<option value="3">Third</option>
853  
-<option value="4">Fourth</option>
  855
+<option value="...">Entertainment</option>
  856
+<option value="...">It&#39;s a test</option>
  857
+<option value="...">Third</option>
  858
+<option value="...">Fourth</option>
854 859
 </select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>
855 860
 
856 861
 # ModelChoiceField ############################################################
@@ -859,7 +864,7 @@ class FlexibleDatePost(models.Model):
859 864
 
860 865
 >>> f = ModelChoiceField(Category.objects.all())
861 866
 >>> list(f.choices)
862  
-[(u'', u'---------'), (1, u'Entertainment'), (2, u"It's a test"), (3, u'Third'), (4, u'Fourth')]
  867
+[(u'', u'---------'), (..., u'Entertainment'), (..., u"It's a test"), (..., u'Third'), (..., u'Fourth')]
863 868
 >>> f.clean('')
864 869
 Traceback (most recent call last):
865 870
 ...
@@ -872,33 +877,34 @@ class FlexibleDatePost(models.Model):
872 877
 Traceback (most recent call last):
873 878
 ...
874 879
 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.']
875  
->>> f.clean(3)
  880
+>>> f.clean(c3.id)
876 881
 <Category: Third>
877  
->>> f.clean(2)
  882
+>>> f.clean(c2.id)
878 883
 <Category: It's a test>
879 884
 
880 885
 # Add a Category object *after* the ModelChoiceField has already been
881 886
 # instantiated. This proves clean() checks the database during clean() rather
882 887
 # than caching it at time of instantiation.
883  
->>> Category.objects.create(name='Fifth', url='5th')
  888
+>>> c5 = Category.objects.create(name='Fifth', url='5th')
  889
+>>> c5
884 890
 <Category: Fifth>
885  
->>> f.clean(5)
  891
+>>> f.clean(c5.id)
886 892
 <Category: Fifth>
887 893
 
888 894
 # Delete a Category object *after* the ModelChoiceField has already been
889 895
 # instantiated. This proves clean() checks the database during clean() rather
890 896
 # than caching it at time of instantiation.
891 897
 >>> Category.objects.get(url='5th').delete()
892  
->>> f.clean(5)
  898
+>>> f.clean(c5.id)
893 899
 Traceback (most recent call last):
894 900
 ...
895 901
 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.']
896 902
 
897  
->>> f = ModelChoiceField(Category.objects.filter(pk=1), required=False)
  903
+>>> f = ModelChoiceField(Category.objects.filter(pk=c1.id), required=False)
898 904
 >>> print f.clean('')
899 905
 None
900 906
 >>> f.clean('')
901  
->>> f.clean('1')
  907
+>>> f.clean(str(c1.id))
902 908
 <Category: Entertainment>
903 909
 >>> f.clean('100')
904 910
 Traceback (most recent call last):
@@ -908,10 +914,10 @@ class FlexibleDatePost(models.Model):
908 914
 # queryset can be changed after the field is created.
909 915
 >>> f.queryset = Category.objects.exclude(name='Fourth')
910 916
 >>> list(f.choices)
911  
-[(u'', u'---------'), (1, u'Entertainment'), (2, u"It's a test"), (3, u'Third')]
912  
->>> f.clean(3)
  917
+[(u'', u'---------'), (..., u'Entertainment'), (..., u"It's a test"), (..., u'Third')]
  918
+>>> f.clean(c3.id)
913 919
 <Category: Third>
914  
->>> f.clean(4)
  920
+>>> f.clean(c4.id)
915 921
 Traceback (most recent call last):
916 922
 ...
917 923
 ValidationError: [u'Select a valid choice. That choice is not one of the available choices.']
@@ -920,21 +926,21 @@ class FlexibleDatePost(models.Model):
920 926
 >>> gen_one = list(f.choices)
921 927
 >>> gen_two = f.choices
922 928
 >>> gen_one[2]
923  
-(2L, u"It's a test")
  929
+(..., u"It's a test")
924 930
 >>> list(gen_two)
925  
-[(u'', u'---------'), (1L, u'Entertainment'), (2L, u"It's a test"), (3L, u'Third')]
  931
+[(u'', u'---------'), (..., u'Entertainment'), (..., u"It's a test"), (..., u'Third')]
926 932
 
927 933
 # check that we can override the label_from_instance method to print custom labels (#4620)
928 934
 >>> f.queryset = Category.objects.all()
929 935
 >>> f.label_from_instance = lambda obj: "category " + str(obj)
930 936
 >>> list(f.choices)
931  
-[(u'', u'---------'), (1L, 'category Entertainment'), (2L, "category It's a test"), (3L, 'category Third'), (4L, 'category Fourth')]
  937
+[(u'', u'---------'), (..., 'category Entertainment'), (..., "category It's a test"), (..., 'category Third'), (..., 'category Fourth')]
932 938
 
933 939
 # ModelMultipleChoiceField ####################################################
934 940
 
935 941
 >>> f = ModelMultipleChoiceField(Category.objects.all())
936 942
 >>> list(f.choices)
937  
-[(1, u'Entertainment'), (2, u"It's a test"), (3, u'Third'), (4, u'Fourth')]
  943
+[(..., u'Entertainment'), (..., u"It's a test"), (..., u'Third'), (..., u'Fourth')]
938 944
 >>> f.clean(None)
939 945
 Traceback (most recent call last):
940 946
 ...
@@ -943,17 +949,17 @@ class FlexibleDatePost(models.Model):
943 949
 Traceback (most recent call last):
944 950
 ...
945 951
 ValidationError: [u'This field is required.']
946  
->>> f.clean([1])
  952
+>>> f.clean([c1.id])
947 953
 [<Category: Entertainment>]
948  
->>> f.clean([2])
  954
+>>> f.clean([c2.id])
949 955
 [<Category: It's a test>]
950  
->>> f.clean(['1'])
  956
+>>> f.clean([str(c1.id)])
951 957
 [<Category: Entertainment>]
952  
->>> f.clean(['1', '2'])
  958
+>>> f.clean([str(c1.id), str(c2.id)])
953 959
 [<Category: Entertainment>, <Category: It's a test>]
954  
->>> f.clean([1, '2'])
  960
+>>> f.clean([c1.id, str(c2.id)])
955 961
 [<Category: Entertainment>, <Category: It's a test>]
956  
->>> f.clean((1, '2'))
  962
+>>> f.clean((c1.id, str(c2.id)))
957 963
 [<Category: Entertainment>, <Category: It's a test>]
958 964
 >>> f.clean(['100'])
959 965
 Traceback (most recent call last):
@@ -971,16 +977,17 @@ class FlexibleDatePost(models.Model):
971 977
 # Add a Category object *after* the ModelMultipleChoiceField has already been
972 978
 # instantiated. This proves clean() checks the database during clean() rather
973 979
 # than caching it at time of instantiation.
974  
->>> Category.objects.create(id=6, name='Sixth', url='6th')
  980
+>>> c6 = Category.objects.create(id=6, name='Sixth', url='6th')
  981
+>>> c6
975 982
 <Category: Sixth>
976  
->>> f.clean([6])
  983
+>>> f.clean([c6.id])
977 984
 [<Category: Sixth>]
978 985
 
979 986
 # Delete a Category object *after* the ModelMultipleChoiceField has already been
980 987
 # instantiated. This proves clean() checks the database during clean() rather
981 988
 # than caching it at time of instantiation.
982 989
 >>> Category.objects.get(url='6th').delete()
983  
->>> f.clean([6])
  990
+>>> f.clean([c6.id])
984 991
 Traceback (most recent call last):
985 992
 ...
986 993
 ValidationError: [u'Select a valid choice. 6 is not one of the available choices.']
@@ -994,11 +1001,11 @@ class FlexibleDatePost(models.Model):
994 1001
 Traceback (most recent call last):
995 1002
 ...
996 1003
 ValidationError: [u'Select a valid choice. 10 is not one of the available choices.']
997  
->>> f.clean(['3', '10'])
  1004
+>>> f.clean([str(c3.id), '10'])
998 1005
 Traceback (most recent call last):
999 1006
 ...
1000 1007
 ValidationError: [u'Select a valid choice. 10 is not one of the available choices.']
1001  
->>> f.clean(['1', '10'])
  1008
+>>> f.clean([str(c1.id), '10'])
1002 1009
 Traceback (most recent call last):
1003 1010
 ...
1004 1011
 ValidationError: [u'Select a valid choice. 10 is not one of the available choices.']
@@ -1006,22 +1013,22 @@ class FlexibleDatePost(models.Model):
1006 1013
 # queryset can be changed after the field is created.
1007 1014
 >>> f.queryset = Category.objects.exclude(name='Fourth')
1008 1015
 >>> list(f.choices)
1009  
-[(1, u'Entertainment'), (2, u"It's a test"), (3, u'Third')]
1010  
->>> f.clean([3])
  1016
+[(..., u'Entertainment'), (..., u"It's a test"), (..., u'Third')]
  1017
+>>> f.clean([c3.id])
1011 1018
 [<Category: Third>]
1012  
->>> f.clean([4])
  1019
+>>> f.clean([c4.id])
1013 1020
 Traceback (most recent call last):
1014 1021
 ...
1015  
-ValidationError: [u'Select a valid choice. 4 is not one of the available choices.']
1016  
->>> f.clean(['3', '4'])
  1022
+ValidationError: [u'Select a valid choice. ... is not one of the available choices.']
  1023
+>>> f.clean([str(c3.id), str(c4.id)])
1017 1024
 Traceback (most recent call last):
1018 1025
 ...
1019  
-ValidationError: [u'Select a valid choice. 4 is not one of the available choices.']
  1026
+ValidationError: [u'Select a valid choice. ... is not one of the available choices.']
1020 1027
 
1021 1028
 >>> f.queryset = Category.objects.all()
1022 1029
 >>> f.label_from_instance = lambda obj: "multicategory " + str(obj)
1023 1030
 >>> list(f.choices)
1024  
-[(1L, 'multicategory Entertainment'), (2L, "multicategory It's a test"), (3L, 'multicategory Third'), (4L, 'multicategory Fourth')]
  1031
+[(..., 'multicategory Entertainment'), (..., "multicategory It's a test"), (..., 'multicategory Third'), (..., 'multicategory Fourth')]
1025 1032
 
1026 1033
 # OneToOneField ###############################################################
1027 1034
 
6  tests/modeltests/proxy_models/tests.py
@@ -39,11 +39,11 @@ def test_basic_proxy(self):
39 39
         """
40 40
         Creating a Person makes them accessible through the MyPerson proxy.
41 41
         """
42  
-        Person.objects.create(name="Foo McBar")
  42
+        person = Person.objects.create(name="Foo McBar")
43 43
         self.assertEqual(len(Person.objects.all()), 1)
44 44
         self.assertEqual(len(MyPerson.objects.all()), 1)
45  
-        self.assertEqual(MyPerson.objects.get(name="Foo McBar").id, 1)
46  
-        self.assertFalse(MyPerson.objects.get(id=1).has_special_name())
  45
+        self.assertEqual(MyPerson.objects.get(name="Foo McBar").id, person.id)
  46
+        self.assertFalse(MyPerson.objects.get(id=person.id).has_special_name())
47 47
 
48 48
     def test_no_proxy(self):
49 49
         """
6  tests/regressiontests/admin_changelist/tests.py
@@ -32,7 +32,7 @@ def test_result_list_empty_changelist_value(self):
32 32
         template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
33 33
         context = Context({'cl': cl})
34 34
         table_output = template.render(context)
35  
-        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">(None)</td></tr></tbody>'
  35
+        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % (new_child.id, new_child.id)
36 36
         self.assertFalse(table_output.find(row_html) == -1,
37 37
             'Failed to find expected row element: %s' % table_output)
38 38
 
@@ -53,7 +53,7 @@ def test_result_list_html(self):
53 53
         template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
54 54
         context = Context({'cl': cl})
55 55
         table_output = template.render(context)
56  
-        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>'
  56
+        row_html = '<tbody><tr class="row1"><td class="action-checkbox"><input type="checkbox" class="action-select" value="%d" name="_selected_action" /></td><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % (new_child.id, new_child.id)
57 57
         self.assertFalse(table_output.find(row_html) == -1,
58 58
             'Failed to find expected row element: %s' % table_output)
59 59
 
@@ -84,7 +84,7 @@ def test_result_list_editable_html(self):
84 84
         context = Context({'cl': cl})
85 85
         table_output = template.render(context)
86 86
         # make sure that hidden fields are in the correct place
87  
-        hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>'
  87
+        hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /></div>' % new_child.id
88 88
         self.assertFalse(table_output.find(hiddenfields_div) == -1,
89 89
             'Failed to find hidden fields in: %s' % table_output)
90 90
         # make sure that list editable fields are rendered in divs correctly
5  tests/regressiontests/fixtures_regress/tests.py
@@ -349,7 +349,7 @@ def test_proxy_model_included(self):
349 349
         """
350 350
         stdout = StringIO()
351 351
         # Create an instance of the concrete class
352  
-        Widget(name='grommet').save()
  352
+        widget = Widget.objects.create(name='grommet')
353 353
         management.call_command(
354 354
             'dumpdata',
355 355
             'fixtures_regress.widget',
@@ -359,7 +359,8 @@ def test_proxy_model_included(self):
359 359
         )
360 360
         self.assertEqual(
361 361
             stdout.getvalue(),
362  
-            """[{"pk": 1, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]"""
  362
+            """[{"pk": %d, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]"""
  363
+            % widget.pk
363 364
             )
364 365
 
365 366
 
4  tests/regressiontests/model_fields/tests.py
@@ -115,8 +115,8 @@ def test_distinct_choice_limit(self):
115 115
         bar_b = Bar.objects.create(b='bla', a=b)
116 116
         form = BazForm()
117 117
         fk_field = str(form['foo'])
118  
-        self.assertEqual(len(re.findall(r'value="2"', fk_field)), 0)
119  
-        self.assertEqual(len(re.findall(r'value="1"', fk_field)), 1)
  118
+        self.assertEqual(len(re.findall(r'value="%d"' % b.pk, fk_field)), 0)
  119
+        self.assertEqual(len(re.findall(r'value="%d"' % a.pk, fk_field)), 1)
120 120
 
121 121
 class DateTimeFieldTests(unittest.TestCase):
122 122
     def test_datetimefield_to_python_usecs(self):
20  tests/regressiontests/model_forms_regress/tests.py
@@ -23,12 +23,11 @@ def test_model_multiple_choice_number_of_queries(self):
23 23
         Test that ModelMultipleChoiceField does O(1) queries instead of
24 24
         O(n) (#10156).
25 25
         """
26  
-        for i in range(30):
27  
-            Person.objects.create(name="Person %s" % i)
  26
+        persons = [Person.objects.create(name="Person %s" % i) for i in range(30)]
28 27
 
29 28
         db.reset_queries()
30 29
         f = forms.ModelMultipleChoiceField(queryset=Person.objects.all())
31  
-        selected = f.clean([1, 3, 5, 7, 9])
  30
+        selected = f.clean([p.pk for p in persons[1:11:2]])
32 31
         self.assertEquals(len(db.connection.queries), 1)
33 32
 
34 33
     def test_model_multiple_choice_run_validators(self):
@@ -133,19 +132,20 @@ def formfield_for_dbfield(db_field, **kwargs):
133 132
             return db_field.formfield(**kwargs)
134 133
 
135 134
         # Set up some Publications to use as data
136  
-        Publication(title="First Book", date_published=date(2007,1,1)).save()
137  
-        Publication(title="Second Book", date_published=date(2008,1,1)).save()
138  
-        Publication(title="Third Book", date_published=date(2009,1,1)).save()
  135
+        book1 = Publication.objects.create(title="First Book", date_published=date(2007,1,1))
  136
+        book2 = Publication.objects.create(title="Second Book", date_published=date(2008,1,1))
  137
+        book3 = Publication.objects.create(title="Third Book", date_published=date(2009,1,1))
139 138
 
140 139
         # Create a ModelForm, instantiate it, and check that the output is as expected
141 140
         ModelForm = modelform_factory(Article, formfield_callback=formfield_for_dbfield)
142 141
         form = ModelForm()
143 142
         self.assertEquals(form.as_ul(), u"""<li><label for="id_headline">Headline:</label> <input id="id_headline" type="text" name="headline" maxlength="100" /></li>
144 143
 <li><label for="id_publications">Publications:</label> <select multiple="multiple" name="publications" id="id_publications">
145  
-<option value="1" selected="selected">First Book</option>
146  
-<option value="2" selected="selected">Second Book</option>
147  
-<option value="3">Third Book</option>
148  
-</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>""")
  144
+<option value="%d" selected="selected">First Book</option>
  145
+<option value="%d" selected="selected">Second Book</option>
  146
+<option value="%d">Third Book</option>
  147
+</select>  Hold down "Control", or "Command" on a Mac, to select more than one.</li>"""
  148
+            % (book1.pk, book2.pk, book3.pk))
149 149
 
150 150
 class CFFForm(forms.ModelForm):
151 151
     class Meta:
12  tests/regressiontests/null_fk/tests.py
@@ -16,15 +16,15 @@ def test_null_fk(self):
16 16
         # set of fields will properly LEFT JOIN multiple levels of NULLs (and the things
17 17
         # that come after the NULLs, or else data that should exist won't). Regression
18 18
         # test for #7369.
19  
-        c = Comment.objects.select_related().get(id=1)
  19
+        c = Comment.objects.select_related().get(id=c1.id)
20 20
         self.assertEquals(c.post, p)
21  
-        self.assertEquals(Comment.objects.select_related().get(id=2).post, None)
  21
+        self.assertEquals(Comment.objects.select_related().get(id=c2.id).post, None)
22 22
 
23 23
         self.assertQuerysetEqual(
24 24
             Comment.objects.select_related('post__forum__system_info').all(),
25 25
             [
26  
-                (1, u'My first comment', '<Post: First Post>'),
27  
-                (2, u'My second comment', 'None')
  26
+                (c1.id, u'My first comment', '<Post: First Post>'),
  27
+                (c2.id, u'My second comment', 'None')
28 28
             ],
29 29
             transform = lambda c: (c.id, c.comment_text, repr(c.post))
30 30
         )
@@ -35,8 +35,8 @@ def test_null_fk(self):
35 35
         self.assertQuerysetEqual(
36 36
             Comment.objects.select_related('post__forum__system_info__system_details'),
37 37
             [
38  
-                (1, u'My first comment', '<Post: First Post>'),
39  
-                (2, u'My second comment', 'None')
  38
+                (c1.id, u'My first comment', '<Post: First Post>'),
  39
+                (c2.id, u'My second comment', 'None')
40 40
             ],
41 41
             transform = lambda c: (c.id, c.comment_text, repr(c.post))
42 42
         )
4  tests/regressiontests/select_related_regress/tests.py
@@ -28,11 +28,11 @@ def test_regression_7110(self):

0 notes on commit ec7dd58

Please sign in to comment.
Something went wrong with that request. Please try again.