Ticket #13987: 13987_fix_2_with_tests_updated.diff

File 13987_fix_2_with_tests_updated.diff, 3.0 KB (added by Aram Dulyan, 13 years ago)

Updated patch to bring test into line with the changes in the test suite.

  • django/db/models/options.py

     
    119119                # Promote the first parent link in lieu of adding yet another
    120120                # field.
    121121                field = self.parents.value_for_index(0)
     122                already_created = [fld for fld in self.local_fields if fld.name == field.name]
     123                if already_created:
     124                    field = already_created[0]
    122125                field.primary_key = True
    123126                self.setup_pk(field)
    124127            else:
  • tests/regressiontests/model_inheritance_regress/tests.py

     
    1111    ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent,
    1212    SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM,
    1313    Person, BirthdayParty, BachelorParty, MessyBachelorParty,
    14     InternalCertificationAudit)
     14    InternalCertificationAudit, BusStation, TrainStation)
    1515
    1616
    1717class ModelInheritanceTest(TestCase):
     
    386386            ],
    387387            attrgetter("pk")
    388388        )
     389   
     390    def test_13987(self):
     391        """
     392        Primary key set correctly with concrete->abstract->concrete inheritance.
     393        """
     394        # Regression test for #13987: Primary key is incorrectly determined
     395        # when more than one model has a concrete->abstract->concrete
     396        # inheritance hierarchy.
     397        self.assertEquals(
     398            len([field for field in BusStation._meta.local_fields
     399                       if field.primary_key]),
     400            1
     401        )
     402        self.assertEquals(
     403            len([field for field in TrainStation._meta.local_fields
     404                       if field.primary_key]),
     405            1
     406        )
     407        self.assertIs(BusStation._meta.pk.model, BusStation)
     408        self.assertIs(TrainStation._meta.pk.model, TrainStation)
  • tests/regressiontests/model_inheritance_regress/models.py

     
    146146
    147147class MessyBachelorParty(BachelorParty):
    148148    pass
     149
     150# Check concrete -> abstract -> concrete inheritance
     151class SearchableLocation(models.Model):
     152    keywords = models.CharField(max_length=256)
     153
     154class Station(SearchableLocation):
     155    name = models.CharField(max_length=128)
     156   
     157    class Meta:
     158        abstract = True
     159
     160class BusStation(Station):
     161    bus_routes = models.CommaSeparatedIntegerField(max_length=128)
     162    inbound = models.BooleanField()
     163
     164class TrainStation(Station):
     165    zone = models.IntegerField()
Back to Top