summaryrefslogtreecommitdiff
path: root/tests/model_formsets
diff options
context:
space:
mode:
authorJason Hoos <jhoos@maestrohealth.com>2015-06-05 15:04:24 -0500
committerTim Graham <timograham@gmail.com>2015-06-26 09:09:09 -0400
commita50b66da30320887c23c73927f6b2ab41e0301bf (patch)
treecae84894d198c429c382bf3a8f79fb855f00b9f1 /tests/model_formsets
parent0cc39e50e136780fcdb5931502980655fff2d488 (diff)
Fixed #24958 -- Fixed inline forms using UUID-PK parents with auto-PK children.
Diffstat (limited to 'tests/model_formsets')
-rw-r--r--tests/model_formsets/models.py30
-rw-r--r--tests/model_formsets/test_uuid.py48
2 files changed, 77 insertions, 1 deletions
diff --git a/tests/model_formsets/models.py b/tests/model_formsets/models.py
index 0b4963208f..18b2525738 100644
--- a/tests/model_formsets/models.py
+++ b/tests/model_formsets/models.py
@@ -254,3 +254,33 @@ class UUIDPKChild(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255)
parent = models.ForeignKey(UUIDPKParent)
+
+
+class ChildWithEditablePK(models.Model):
+ name = models.CharField(max_length=255, primary_key=True)
+ parent = models.ForeignKey(UUIDPKParent)
+
+
+class AutoPKChildOfUUIDPKParent(models.Model):
+ name = models.CharField(max_length=255)
+ parent = models.ForeignKey(UUIDPKParent)
+
+
+class AutoPKParent(models.Model):
+ name = models.CharField(max_length=255)
+
+
+class UUIDPKChildOfAutoPKParent(models.Model):
+ uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
+ name = models.CharField(max_length=255)
+ parent = models.ForeignKey(AutoPKParent)
+
+
+class ParentWithUUIDAlternateKey(models.Model):
+ uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
+ name = models.CharField(max_length=50)
+
+
+class ChildRelatedViaAK(models.Model):
+ name = models.CharField(max_length=255)
+ parent = models.ForeignKey(to=ParentWithUUIDAlternateKey, to_field='uuid')
diff --git a/tests/model_formsets/test_uuid.py b/tests/model_formsets/test_uuid.py
index 8025f758c9..bd44595530 100644
--- a/tests/model_formsets/test_uuid.py
+++ b/tests/model_formsets/test_uuid.py
@@ -1,7 +1,11 @@
from django.forms.models import inlineformset_factory
from django.test import TestCase
-from .models import UUIDPKChild, UUIDPKParent
+from .models import (
+ AutoPKChildOfUUIDPKParent, AutoPKParent, ChildRelatedViaAK,
+ ChildWithEditablePK, ParentWithUUIDAlternateKey, UUIDPKChild,
+ UUIDPKChildOfAutoPKParent, UUIDPKParent,
+)
class InlineFormsetTests(TestCase):
@@ -10,6 +14,8 @@ class InlineFormsetTests(TestCase):
#24377 - If we're adding a new object, a parent's auto-generated pk
from the model field default should be ignored as it's regenerated on
the save request.
+
+ Tests the case where both the parent and child have a UUID primary key.
"""
FormSet = inlineformset_factory(UUIDPKParent, UUIDPKChild, fields='__all__')
formset = FormSet()
@@ -30,3 +36,43 @@ class InlineFormsetTests(TestCase):
'uuidpkchild_set-2-name': '',
})
self.assertTrue(formset.is_valid())
+
+ def test_inlineformset_factory_nulls_default_pks_uuid_parent_auto_child(self):
+ """
+ #24958 - Variant of test_inlineformset_factory_nulls_default_pks for
+ the case of a parent object with a UUID primary key and a child object
+ with an AutoField primary key.
+ """
+ FormSet = inlineformset_factory(UUIDPKParent, AutoPKChildOfUUIDPKParent, fields='__all__')
+ formset = FormSet()
+ self.assertIsNone(formset.forms[0].fields['parent'].initial)
+
+ def test_inlineformset_factory_nulls_default_pks_auto_parent_uuid_child(self):
+ """
+ #24958 - Variant of test_inlineformset_factory_nulls_default_pks for
+ the case of a parent object with an AutoField primary key and a child
+ object with a UUID primary key.
+ """
+ FormSet = inlineformset_factory(AutoPKParent, UUIDPKChildOfAutoPKParent, fields='__all__')
+ formset = FormSet()
+ self.assertIsNone(formset.forms[0].fields['parent'].initial)
+
+ def test_inlineformset_factory_nulls_default_pks_child_editable_pk(self):
+ """
+ #24958 - Variant of test_inlineformset_factory_nulls_default_pks for
+ the case of a parent object with a UUID primary key and a child
+ object with an editable natural key for a primary key.
+ """
+ FormSet = inlineformset_factory(UUIDPKParent, ChildWithEditablePK, fields='__all__')
+ formset = FormSet()
+ self.assertIsNone(formset.forms[0].fields['parent'].initial)
+
+ def test_inlineformset_factory_nulls_default_pks_alternate_key_relation(self):
+ """
+ #24958 - Variant of test_inlineformset_factory_nulls_default_pks for
+ the case of a parent object with a UUID alternate key and a child
+ object that relates to that alternate key.
+ """
+ FormSet = inlineformset_factory(ParentWithUUIDAlternateKey, ChildRelatedViaAK, fields='__all__')
+ formset = FormSet()
+ self.assertIsNone(formset.forms[0].fields['parent'].initial)