Thanks to matiasb for the report of #20060 and the draft patch for #20048.
This commit is contained in:
@@ -5,10 +5,12 @@ from django.core import signing
|
||||
from django.core.exceptions import SuspiciousOperation
|
||||
from django.http import HttpResponse
|
||||
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.contrib.formtools.wizard.storage.cookie import CookieStorage
|
||||
from django.contrib.formtools.tests.wizard.storage import get_request, TestStorage
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class TestCookieStorage(TestStorage, TestCase):
|
||||
def get_storage(self):
|
||||
return CookieStorage
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django import forms, http
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.importlib import import_module
|
||||
@@ -29,26 +30,40 @@ def get_request(*args, **kwargs):
|
||||
request.session = engine.SessionStore(None)
|
||||
return request
|
||||
|
||||
|
||||
class Step1(forms.Form):
|
||||
name = forms.CharField()
|
||||
|
||||
|
||||
class Step2(forms.Form):
|
||||
name = forms.CharField()
|
||||
|
||||
|
||||
class Step3(forms.Form):
|
||||
data = forms.CharField()
|
||||
|
||||
|
||||
class CustomKwargsStep1(Step1):
|
||||
|
||||
def __init__(self, test=None, *args, **kwargs):
|
||||
self.test = test
|
||||
return super(CustomKwargsStep1, self).__init__(*args, **kwargs)
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2)
|
||||
class TestModel(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
|
||||
class Meta:
|
||||
app_label = 'formtools'
|
||||
|
||||
|
||||
class TestModelForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = TestModel
|
||||
|
||||
|
||||
TestModelFormSet = forms.models.modelformset_factory(TestModel, form=TestModelForm, extra=2)
|
||||
|
||||
|
||||
class TestWizard(WizardView):
|
||||
storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
|
||||
@@ -149,8 +164,8 @@ class FormTests(TestCase):
|
||||
|
||||
def test_form_instance(self):
|
||||
request = get_request()
|
||||
the_instance = User()
|
||||
testform = TestWizard.as_view([('start', UserForm), ('step2', Step2)],
|
||||
the_instance = TestModel()
|
||||
testform = TestWizard.as_view([('start', TestModelForm), ('step2', Step2)],
|
||||
instance_dict={'start': the_instance})
|
||||
response, instance = testform(request)
|
||||
|
||||
@@ -163,12 +178,12 @@ class FormTests(TestCase):
|
||||
|
||||
def test_formset_instance(self):
|
||||
request = get_request()
|
||||
the_instance1, created = User.objects.get_or_create(
|
||||
username='testuser1')
|
||||
the_instance2, created = User.objects.get_or_create(
|
||||
username='testuser2')
|
||||
testform = TestWizard.as_view([('start', UserFormSet), ('step2', Step2)],
|
||||
instance_dict={'start': User.objects.filter(username='testuser1')})
|
||||
the_instance1, created = TestModel.objects.get_or_create(
|
||||
name='test object 1')
|
||||
the_instance2, created = TestModel.objects.get_or_create(
|
||||
name='test object 2')
|
||||
testform = TestWizard.as_view([('start', TestModelFormSet), ('step2', Step2)],
|
||||
instance_dict={'start': TestModel.objects.filter(name='test object 1')})
|
||||
response, instance = testform(request)
|
||||
|
||||
self.assertEqual(list(instance.get_form_instance('start')), [the_instance1])
|
||||
|
||||
@@ -5,6 +5,7 @@ from django.http import QueryDict
|
||||
from django.test import TestCase
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
|
||||
from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView,
|
||||
NamedUrlCookieWizardView)
|
||||
@@ -276,6 +277,7 @@ class NamedWizardTests(object):
|
||||
self.assertEqual(response.context['wizard']['steps'].current, 'form1')
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class NamedSessionWizardTests(NamedWizardTests, TestCase):
|
||||
wizard_urlname = 'nwiz_session'
|
||||
wizard_step_1_data = {
|
||||
@@ -307,6 +309,7 @@ class NamedSessionWizardTests(NamedWizardTests, TestCase):
|
||||
)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class NamedCookieWizardTests(NamedWizardTests, TestCase):
|
||||
wizard_urlname = 'nwiz_cookie'
|
||||
wizard_step_1_data = {
|
||||
@@ -367,11 +370,13 @@ class TestNamedUrlCookieWizardView(NamedUrlCookieWizardView):
|
||||
return response, self
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class NamedSessionFormTests(NamedFormTests, TestCase):
|
||||
formwizard_class = TestNamedUrlSessionWizardView
|
||||
wizard_urlname = 'nwiz_session'
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class NamedCookieFormTests(NamedFormTests, TestCase):
|
||||
formwizard_class = TestNamedUrlCookieWizardView
|
||||
wizard_urlname = 'nwiz_cookie'
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.contrib.formtools.tests.wizard.storage import TestStorage
|
||||
from django.contrib.formtools.wizard.storage.session import SessionStorage
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class TestSessionStorage(TestStorage, TestCase):
|
||||
def get_storage(self):
|
||||
return SessionStorage
|
||||
|
||||
@@ -7,11 +7,19 @@ from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.contrib.formtools.wizard.views import CookieWizardView
|
||||
from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet
|
||||
from django.utils._os import upath
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
|
||||
|
||||
UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2)
|
||||
|
||||
|
||||
class WizardTests(object):
|
||||
urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
|
||||
|
||||
@@ -75,7 +83,7 @@ class WizardTests(object):
|
||||
|
||||
# ticket #19025: `form` should be included in context
|
||||
form = response.context_data['wizard']['form']
|
||||
self.assertEqual(response.context_data['form'], form)
|
||||
self.assertEqual(response.context_data['form'], form)
|
||||
|
||||
def test_form_finish(self):
|
||||
response = self.client.get(self.wizard_url)
|
||||
@@ -196,6 +204,7 @@ class WizardTests(object):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class SessionWizardTests(WizardTests, TestCase):
|
||||
wizard_url = '/wiz_session/'
|
||||
wizard_step_1_data = {
|
||||
@@ -226,6 +235,8 @@ class SessionWizardTests(WizardTests, TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class CookieWizardTests(WizardTests, TestCase):
|
||||
wizard_url = '/wiz_cookie/'
|
||||
wizard_step_1_data = {
|
||||
@@ -256,6 +267,8 @@ class CookieWizardTests(WizardTests, TestCase):
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class WizardTestKwargs(TestCase):
|
||||
wizard_url = '/wiz_other_template/'
|
||||
wizard_step_1_data = {
|
||||
@@ -347,6 +360,7 @@ class WizardTestGenericViewInterface(TestCase):
|
||||
self.assertEqual(response.context_data['another_key'], 'another_value')
|
||||
|
||||
|
||||
@skipIfCustomUser
|
||||
class WizardFormKwargsOverrideTests(TestCase):
|
||||
def setUp(self):
|
||||
super(WizardFormKwargsOverrideTests, self).setUp()
|
||||
|
||||
Reference in New Issue
Block a user