Ticket #13030: nk_inherit_test.diff

File nk_inherit_test.diff, 2.3 KB (added by yishaibeeri, 15 years ago)

diff with test showing bug

  • regressiontests/fixtures_regress/fixtures/nk-inheritance.json

     
     1[
     2    {"pk": 1, "model": "fixtures_regress.parent", "fields": {"name": "fred"}},
     3
     4    {"pk": 1, "model": "fixtures_regress.child", "fields": {"data": "apple"}},
     5    {"pk": 1, "model": "fixtures_regress.reftochild", "fields": {"text": "my text", "thechild" : 1}},
     6
     7    {"pk": 1, "model": "fixtures_regress.nkchild", "fields": {"data": "apple"}},
     8    {"pk": 1, "model": "fixtures_regress.reftonkchild", "fields": {"text": "my text", "thenkchild" : ["apple"]}}
     9]
  • regressiontests/fixtures_regress/models.py

     
    5555class Child(Parent):
    5656    data = models.CharField(max_length=10)
    5757
     58class NKManager(models.Manager):
     59   def get_by_natural_key(self, data):
     60      return self.get(data=data)
     61class NKChild(Parent):
     62    data = models.CharField(max_length=10, unique=True)
     63    objects = NKManager()
     64    def natural_key(self):
     65        return self.data
     66
     67class RefToChild(models.Model):
     68                text = models.CharField(max_length=10)
     69                thechild = models.ForeignKey(Child)
     70
     71class RefToNKChild(models.Model):
     72                text = models.CharField(max_length=10)
     73                thenkchild = models.ForeignKey(NKChild)
     74
    5875# Models to regression test #7572
    5976class Channel(models.Model):
    6077    name = models.CharField(max_length=255)
     
    245262>>> management.call_command('loaddata', 'model-inheritance.json', verbosity=0)
    246263
    247264###############################################
     265# Test for ticket #XXXX -- natural keys deserialize with fk to inheriting model
     266
     267# load data with natural keys
     268>>> management.call_command('loaddata', 'nk-inheritance.json', verbosity=0)
     269
     270
     271###############################################
    248272# Test for ticket #7572 -- MySQL has a problem if the same connection is
    249273# used to create tables, load data, and then query over that data.
    250274# To compensate, we close the connection after running loaddata.
Back to Top