Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #1 -- form instance is incorrectly propagated to other forms
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Regression test for https://github.com/t0ster/django-composite-form/issues/1 | ||
|
||
from django.test import TestCase | ||
from django.contrib.auth.models import User | ||
|
||
|
||
from example.forms import ProfileForm, BaseProfileForm, UserCreationForm | ||
from example.models import Profile | ||
|
||
|
||
class FormsTests(TestCase): | ||
def setUp(self): | ||
profile_form = ProfileForm({ | ||
"address": "13 Test St", | ||
"username": "test_user", | ||
"password1": "123456", | ||
"password2": "123456", | ||
}) | ||
profile_form.save() | ||
self.user = User.objects.all()[0] | ||
self.profile = Profile.objects.all()[0] | ||
|
||
def test_1(self): | ||
profile_form = ProfileForm(instances=[self.user, self.profile]) | ||
self.assertEqual(profile_form.get_form(UserCreationForm).instance, self.user) | ||
self.assertEqual(profile_form.get_form(BaseProfileForm).instance, self.profile) | ||
|
||
def test_2(self): | ||
profile_form = ProfileForm(instances=[self.user, None]) | ||
self.assertEqual(profile_form.get_form(UserCreationForm).instance, self.user) | ||
self.assertIsInstance(profile_form.get_form(BaseProfileForm).instance, Profile) | ||
|
||
def test_3(self): | ||
profile_form = ProfileForm(instances=[None, self.profile]) | ||
self.assertEqual(profile_form.get_form(BaseProfileForm).instance, self.profile) | ||
self.assertIsInstance(profile_form.get_form(UserCreationForm).instance, User) |