Code

Ticket #13030: nk_inherit_test.diff

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

diff with test showing bug

Line 
1Index: regressiontests/fixtures_regress/fixtures/nk-inheritance.json
2===================================================================
3--- regressiontests/fixtures_regress/fixtures/nk-inheritance.json       (revision 0)
4+++ regressiontests/fixtures_regress/fixtures/nk-inheritance.json       (revision 0)
5@@ -0,0 +1,9 @@
6+[
7+    {"pk": 1, "model": "fixtures_regress.parent", "fields": {"name": "fred"}},
8+
9+    {"pk": 1, "model": "fixtures_regress.child", "fields": {"data": "apple"}},
10+    {"pk": 1, "model": "fixtures_regress.reftochild", "fields": {"text": "my text", "thechild" : 1}},
11+
12+    {"pk": 1, "model": "fixtures_regress.nkchild", "fields": {"data": "apple"}},
13+    {"pk": 1, "model": "fixtures_regress.reftonkchild", "fields": {"text": "my text", "thenkchild" : ["apple"]}}
14+]
15Index: regressiontests/fixtures_regress/models.py
16===================================================================
17--- regressiontests/fixtures_regress/models.py  (revision 12678)
18+++ regressiontests/fixtures_regress/models.py  (working copy)
19@@ -55,6 +55,23 @@
20 class Child(Parent):
21     data = models.CharField(max_length=10)
22 
23+class NKManager(models.Manager):
24+   def get_by_natural_key(self, data):
25+      return self.get(data=data)
26+class NKChild(Parent):
27+    data = models.CharField(max_length=10, unique=True)
28+    objects = NKManager()
29+    def natural_key(self):
30+       return self.data
31+
32+class RefToChild(models.Model):
33+               text = models.CharField(max_length=10)
34+               thechild = models.ForeignKey(Child)
35+
36+class RefToNKChild(models.Model):
37+               text = models.CharField(max_length=10)
38+               thenkchild = models.ForeignKey(NKChild)
39+
40 # Models to regression test #7572
41 class Channel(models.Model):
42     name = models.CharField(max_length=255)
43@@ -245,6 +262,13 @@
44 >>> management.call_command('loaddata', 'model-inheritance.json', verbosity=0)
45 
46 ###############################################
47+# Test for ticket #XXXX -- natural keys deserialize with fk to inheriting model
48+
49+# load data with natural keys
50+>>> management.call_command('loaddata', 'nk-inheritance.json', verbosity=0)
51+
52+
53+###############################################
54 # Test for ticket #7572 -- MySQL has a problem if the same connection is
55 # used to create tables, load data, and then query over that data.
56 # To compensate, we close the connection after running loaddata.