Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed a bunch more tests that were failing in Oracle due to false ass…

…umptions about the primary keys of objects.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15789 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f17fc56602f8de37ef8c5565ddf04991e8c91442 1 parent 23103bd
Ian Kelly authored March 09, 2011
3  django/contrib/flatpages/tests/forms.py
... ...
@@ -1,3 +1,4 @@
  1
+from django.conf import settings
1 2
 from django.contrib.flatpages.admin import FlatpageForm
2 3
 from django.test import TestCase
3 4
 
@@ -6,7 +7,7 @@ def setUp(self):
6 7
         self.form_data = {
7 8
             'title': "A test page",
8 9
             'content': "This is a test",
9  
-            'sites': [1],
  10
+            'sites': [settings.SITE_ID],
10 11
         }
11 12
 
12 13
     def test_flatpage_admin_form_url_validation(self):
2  django/contrib/flatpages/tests/views.py
@@ -68,7 +68,7 @@ def test_view_flatpage_special_chars(self):
68 68
             enable_comments=False,
69 69
             registration_required=False,
70 70
         )
71  
-        fp.sites.add(1)
  71
+        fp.sites.add(settings.SITE_ID)
72 72
 
73 73
         response = self.client.get('/flatpage_root/some.very_special~chars-here/')
74 74
         self.assertEqual(response.status_code, 200)
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)
11  tests/modeltests/fixtures/tests.py
@@ -2,6 +2,7 @@
2 2
 import sys
3 3
 
4 4
 from django.conf import settings
  5
+from django.contrib.sites.models import Site
5 6
 from django.core import management
6 7
 from django.db import DEFAULT_DB_ALIAS
7 8
 from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
@@ -45,6 +46,7 @@ def test_initial_data(self):
45 46
     def test_loading_and_dumping(self):
46 47
         new_io = StringIO.StringIO()
47 48
 
  49
+        Site.objects.all().delete()
48 50
         # Load fixture 1. Single JSON file, with two objects.
49 51
         management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
50 52
         self.assertQuerysetEqual(Article.objects.all(), [
@@ -159,6 +161,7 @@ def test_loading_and_dumping(self):
159 161
 
160 162
     def test_dumpdata_with_excludes(self):
161 163
         # Load fixture1 which has a site, two articles, and a category
  164
+        Site.objects.all().delete()
162 165
         management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False)
163 166
 
164 167
         # Excluding fixtures app should only leave sites
@@ -200,15 +203,15 @@ def test_dumpdata_with_excludes(self):
200 203
                           exclude_list=['fixtures.FooModel'])
201 204
 
202 205
     def test_dumpdata_with_filtering_manager(self):
203  
-        Spy(name='Paul').save()
204  
-        Spy(name='Alex', cover_blown=True).save()
  206
+        spy1 = Spy.objects.create(name='Paul')
  207
+        spy2 = Spy.objects.create(name='Alex', cover_blown=True)
205 208
         self.assertQuerysetEqual(Spy.objects.all(),
206 209
                                  ['<Spy: Paul>'])
207 210
         # Use the default manager
208  
-        self._dumpdata_assert(['fixtures.Spy'],'[{"pk": 1, "model": "fixtures.spy", "fields": {"cover_blown": false}}]')
  211
+        self._dumpdata_assert(['fixtures.Spy'],'[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk)
209 212
         # Dump using Django's base manager. Should return all objects,
210 213
         # even those normally filtered by the manager
211  
-        self._dumpdata_assert(['fixtures.Spy'], '[{"pk": 2, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": 1, "model": "fixtures.spy", "fields": {"cover_blown": false}}]', use_base_manager=True)
  214
+        self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk), use_base_manager=True)
212 215
 
213 216
     def test_compress_format_loading(self):
214 217
         # Load fixture 4 (compressed), using format specification
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 /><span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></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
         """
28  tests/regressiontests/admin_changelist/tests.py
@@ -36,7 +36,7 @@ def test_result_list_empty_changelist_value(self):
36 36
         template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
37 37
         context = Context({'cl': cl})
38 38
         table_output = template.render(context)
39  
-        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>'
  39
+        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)
40 40
         self.assertFalse(table_output.find(row_html) == -1,
41 41
             'Failed to find expected row element: %s' % table_output)
42 42
 
@@ -57,7 +57,7 @@ def test_result_list_html(self):
57 57
         template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
58 58
         context = Context({'cl': cl})
59 59
         table_output = template.render(context)
60  
-        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>'
  60
+        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)
61 61
         self.assertFalse(table_output.find(row_html) == -1,
62 62
             'Failed to find expected row element: %s' % table_output)
63 63
 
@@ -88,7 +88,7 @@ def test_result_list_editable_html(self):
88 88
         context = Context({'cl': cl})
89 89
         table_output = template.render(context)
90 90
         # make sure that hidden fields are in the correct place
91  
-        hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>'
  91
+        hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /></div>' % new_child.id
92 92
         self.assertFalse(table_output.find(hiddenfields_div) == -1,
93 93
             'Failed to find hidden fields in: %s' % table_output)
94 94
         # make sure that list editable fields are rendered in divs correctly
@@ -148,12 +148,12 @@ def test_distinct_for_m2m_in_list_filter(self):
148 148
         band.genres.add(blues)
149 149
 
150 150
         m = BandAdmin(Band, admin.site)
151  
-        cl = ChangeList(MockFilteredRequestA(), Band, m.list_display,
  151
+        cl = ChangeList(MockFilteredRequestA(blues.pk), Band, m.list_display,
152 152
                 m.list_display_links, m.list_filter, m.date_hierarchy,
153 153
                 m.search_fields, m.list_select_related, m.list_per_page,
154 154
                 m.list_editable, m)
155 155
 
156  
-        cl.get_results(MockFilteredRequestA())
  156
+        cl.get_results(MockFilteredRequestA(blues.pk))
157 157
 
158 158
         # There's only one Group instance
159 159
         self.assertEqual(cl.result_count, 1)
@@ -169,12 +169,12 @@ def test_distinct_for_through_m2m_in_list_filter(self):
169 169
         Membership.objects.create(group=band, music=lead, role='bass player')
170 170
 
171 171
         m = GroupAdmin(Group, admin.site)
172  
-        cl = ChangeList(MockFilteredRequestB(), Group, m.list_display,
  172
+        cl = ChangeList(MockFilteredRequestB(lead.pk), Group, m.list_display,
173 173
                 m.list_display_links, m.list_filter, m.date_hierarchy,
174 174
                 m.search_fields, m.list_select_related, m.list_per_page,
175 175
                 m.list_editable, m)
176 176
 
177  
-        cl.get_results(MockFilteredRequestB())
  177
+        cl.get_results(MockFilteredRequestB(lead.pk))
178 178
 
179 179
         # There's only one Group instance
180 180
         self.assertEqual(cl.result_count, 1)
@@ -191,12 +191,12 @@ def test_distinct_for_inherited_m2m_in_list_filter(self):
191 191
         Membership.objects.create(group=four, music=lead, role='guitar player')
192 192
 
193 193
         m = QuartetAdmin(Quartet, admin.site)
194  
-        cl = ChangeList(MockFilteredRequestB(), Quartet, m.list_display,
  194
+        cl = ChangeList(MockFilteredRequestB(lead.pk), Quartet, m.list_display,
195 195
                 m.list_display_links, m.list_filter, m.date_hierarchy,
196 196
                 m.search_fields, m.list_select_related, m.list_per_page,
197 197
                 m.list_editable, m)
198 198
 
199  
-        cl.get_results(MockFilteredRequestB())
  199
+        cl.get_results(MockFilteredRequestB(lead.pk))
200 200
 
201 201
         # There's only one Quartet instance
202 202
         self.assertEqual(cl.result_count, 1)
@@ -213,12 +213,12 @@ def test_distinct_for_m2m_to_inherited_in_list_filter(self):
213 213
         Invitation.objects.create(band=three, player=lead, instrument='bass')
214 214
 
215 215
         m = ChordsBandAdmin(ChordsBand, admin.site)
216  
-        cl = ChangeList(MockFilteredRequestB(), ChordsBand, m.list_display,
  216
+        cl = ChangeList(MockFilteredRequestB(lead.pk), ChordsBand, m.list_display,
217 217
                 m.list_display_links, m.list_filter, m.date_hierarchy,
218 218
                 m.search_fields, m.list_select_related, m.list_per_page,
219 219
                 m.list_editable, m)
220 220
 
221  
-        cl.get_results(MockFilteredRequestB())
  221
+        cl.get_results(MockFilteredRequestB(lead.pk))
222 222
 
223 223
         # There's only one ChordsBand instance
224 224
         self.assertEqual(cl.result_count, 1)
@@ -289,7 +289,9 @@ class ChordsBandAdmin(admin.ModelAdmin):
289 289
     list_filter = ['members']
290 290
 
291 291
 class MockFilteredRequestA(object):
292  
-    GET = { 'genres': 1 }
  292
+    def __init__(self, pk):
  293
+        self.GET = { 'genres' : pk }
293 294
 
294 295
 class MockFilteredRequestB(object):
295  
-    GET = { 'members': 1 }
  296
+    def __init__(self, pk):
  297
+        self.GET = { 'members': pk }
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
@@ -116,8 +116,8 @@ def test_distinct_choice_limit(self):
116 116
         bar_b = Bar.objects.create(b='bla', a=b)
117 117
         form = BazForm()
118 118
         fk_field = str(form['foo'])
119  
-        self.assertEqual(len(re.findall(r'value="2"', fk_field)), 0)
120  
-        self.assertEqual(len(re.findall(r'value="1"', fk_field)), 1)
  119
+        self.assertEqual(len(re.findall(r'value="%d"' % b.pk, fk_field)), 0)
  120
+        self.assertEqual(len(re.findall(r'value="%d"' % a.pk, fk_field)), 1)
121 121
 
122 122
 class DateTimeFieldTests(unittest.TestCase):
123 123
     def test_datetimefield_to_python_usecs(self):
20  tests/regressiontests/model_forms_regress/tests.py
@@ -18,11 +18,10 @@ def test_model_multiple_choice_number_of_queries(self):
18 18
         Test that ModelMultipleChoiceField does O(1) queries instead of
19 19
         O(n) (#10156).
20 20
         """
21  
-        for i in range(30):
22  
-            Person.objects.create(name="Person %s" % i)
  21
+        persons = [Person.objects.create(name="Person %s" % i) for i in range(30)]
23 22
 
24 23
         f = forms.ModelMultipleChoiceField(queryset=Person.objects.all())
25  
-        self.assertNumQueries(1, f.clean, [1, 3, 5, 7, 9])
  24
+        self.assertNumQueries(1, f.clean, [p.pk for p in persons[1:11:2]])
26 25
 
27 26
     def test_model_multiple_choice_run_validators(self):
28 27
         """
@@ -126,19 +125,20 @@ def formfield_for_dbfield(db_field, **kwargs):
126 125
             return db_field.formfield(**kwargs)
127 126
 
128 127
         # Set up some Publications to use as data
129  
-        Publication(title="First Book", date_published=date(2007,1,1)).save()
130  
-        Publication(title="Second Book", date_published=date(2008,1,1)).save()
131  
-        Publication(title="Third Book", date_published=date(2009,1,1)).save()
  128
+        book1 = Publication.objects.create(title="First Book", date_published=date(2007,1,1))
  129
+        book2 = Publication.objects.create(title="Second Book", date_published=date(2008,1,1))
  130
+        book3 = Publication.objects.create(title="Third Book", date_published=date(2009,1,1))
132 131
 
133 132
         # Create a ModelForm, instantiate it, and check that the output is as expected
134 133
         ModelForm = modelform_factory(Article, formfield_callback=formfield_for_dbfield)
135 134
         form = ModelForm()
136 135
         self.assertEqual(form.as_ul(), u"""<li><label for="id_headline">Headline:</label> <input id="id_headline" type="text" name="headline" maxlength="100" /></li>
137 136
 <li><label for="id_publications">Publications:</label> <select multiple="multiple" name="publications" id="id_publications">
138  
-<option value="1" selected="selected">First Book</option>
139  
-<option value="2" selected="selected">Second Book</option>
140  
-<option value="3">Third Book</option>
141  
-</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li>""")
  137
+<option value="%d" selected="selected">First Book</option>
  138
+<option value="%d" selected="selected">Second Book</option>
  139
+<option value="%d">Third Book</option>
  140
+</select> <span class="helptext"> Hold down "Control", or "Command" on a Mac, to select more than one.</span></li>"""
  141
+            % (book1.pk, book2.pk, book3.pk))
142 142
 
143 143
 class CFFForm(forms.ModelForm):
144 144
     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.assertEqual(c.post, p)
21  
-        self.assertEqual(Comment.objects.select_related().get(id=2).post, None)
  21
+        self.assertEqual(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 f17fc56

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