Fixed #6644 -- Fixed django.contrib.formtools tests to be better isolated when running outside of the Django test suite. Also moved around the new wizard's templates a bit to better fit the common app layout.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16616 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-08-13 13:51:34 +00:00
parent 566b3295fa
commit a13de6cd76
25 changed files with 60 additions and 44 deletions

View File

@ -4,12 +4,13 @@ import warnings
from django import http
from django.conf import settings
from django.contrib.formtools import preview, wizard, utils
from django.contrib.formtools import preview, utils
from django.contrib.formtools.wizard import FormWizard
from django.test import TestCase
from django.test.utils import get_warnings_state, restore_warnings_state
from django.utils import unittest
from django.contrib.formtools.wizard.tests import *
from django.contrib.formtools.tests.wizard import *
from django.contrib.formtools.tests.forms import *
warnings.filterwarnings('ignore', category=PendingDeprecationWarning,
@ -30,10 +31,22 @@ class TestFormPreview(preview.FormPreview):
return http.HttpResponse(success_string)
class PreviewTests(TestCase):
class FormToolsTestCase(TestCase):
def setUp(self):
# in the test runner use templates/tests/ to provide base.html
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
settings.TEMPLATE_DIRS = list(settings.TEMPLATE_DIRS) + [
os.path.join(os.path.dirname(__file__), 'templates')]
def tearDown(self):
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
class PreviewTests(FormToolsTestCase):
urls = 'django.contrib.formtools.tests.urls'
def setUp(self):
super(PreviewTests, self).setUp()
self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.contrib.formtools.utils')
@ -45,6 +58,7 @@ class PreviewTests(TestCase):
self.test_data = {'field1':u'foo', 'field1_':u'asdf'}
def tearDown(self):
super(PreviewTests, self).tearDown()
self.restore_warnings_state()
def test_unused_name(self):
@ -224,7 +238,7 @@ class FormHmacTests(unittest.TestCase):
# FormWizard tests
#
class TestWizardClass(wizard.FormWizard):
class TestWizardClass(FormWizard):
def get_template(self, step):
return 'forms/wizard.html'
@ -243,7 +257,7 @@ class DummyRequest(http.HttpRequest):
self._dont_enforce_csrf_checks = True
class WizardTests(TestCase):
class WizardTests(FormToolsTestCase):
urls = 'django.contrib.formtools.tests.urls'
input_re = re.compile('name="([^"]+)" value="([^"]+)"')
wizard_step_data = (
@ -261,19 +275,13 @@ class WizardTests(TestCase):
)
def setUp(self):
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
settings.TEMPLATE_DIRS = (
os.path.join(
os.path.dirname(__file__),
'templates'
),
)
super(WizardTests, self).setUp()
# Use a known SECRET_KEY to make security_hash tests deterministic
self.old_SECRET_KEY = settings.SECRET_KEY
settings.SECRET_KEY = "123"
def tearDown(self):
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
super(WizardTests, self).tearDown()
settings.SECRET_KEY = self.old_SECRET_KEY
def test_step_starts_at_zero(self):

View File

@ -9,10 +9,10 @@ class Page1(forms.Form):
class Page2(forms.Form):
address1 = forms.CharField(max_length=100)
address2 = forms.CharField(max_length=100)
class Page3(forms.Form):
random_crap = forms.CharField(max_length=100)
class ContactWizard(FormWizard):
def done(self, request, form_list):
return HttpResponse("")

View File

@ -0,0 +1,2 @@
{% block content %}
{% endblock %}

View File

@ -0,0 +1,17 @@
from django.contrib.formtools.tests.wizard.cookiestorage import TestCookieStorage
from django.contrib.formtools.tests.wizard.forms import FormTests, SessionFormTests, CookieFormTests
from django.contrib.formtools.tests.wizard.loadstorage import TestLoadStorage
from django.contrib.formtools.tests.wizard.namedwizardtests.tests import (
NamedSessionWizardTests,
NamedCookieWizardTests,
TestNamedUrlSessionFormWizard,
TestNamedUrlCookieFormWizard,
NamedSessionFormTests,
NamedCookieFormTests,
)
from django.contrib.formtools.tests.wizard.sessionstorage import TestSessionStorage
from django.contrib.formtools.tests.wizard.wizardtests.tests import (
SessionWizardTests,
CookieWizardTests,
WizardTestKwargs,
)

View File

@ -4,7 +4,8 @@ from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse
from django.contrib.formtools.wizard.storage.cookie import CookieStorage
from django.contrib.formtools.wizard.tests.storagetests import get_request, TestStorage
from django.contrib.formtools.tests.wizard.storage import get_request, TestStorage
class TestCookieStorage(TestStorage, TestCase):
def get_storage(self):

View File

@ -20,6 +20,7 @@ class DummyRequest(http.HttpRequest):
self.session = {}
self._dont_enforce_csrf_checks = True
def get_request(*args, **kwargs):
request = DummyRequest(*args, **kwargs)
engine = import_module(settings.SESSION_ENGINE)
@ -202,4 +203,3 @@ class CookieFormTests(TestCase):
request = get_request()
testform = CookieWizardView.as_view([('start', Step1)])
self.assertTrue(isinstance(testform(request), TemplateResponse))

View File

@ -4,16 +4,12 @@ from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.formtools import wizard
from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView,
NamedUrlCookieWizardView)
from django.contrib.formtools.wizard.tests.formtests import (get_request,
Step1,
Step2)
from django.contrib.formtools.tests.wizard.forms import get_request, Step1, Step2
class NamedWizardTests(object):
urls = 'django.contrib.formtools.wizard.tests.namedwizardtests.urls'
urls = 'django.contrib.formtools.tests.wizard.namedwizardtests.urls'
def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1')
@ -310,7 +306,7 @@ class NamedCookieWizardTests(NamedWizardTests, TestCase):
class NamedFormTests(object):
urls = 'django.contrib.formtools.wizard.tests.namedwizardtests.urls'
urls = 'django.contrib.formtools.tests.wizard.namedwizardtests.urls'
def test_revalidation(self):
request = get_request()

View File

@ -1,5 +1,5 @@
from django.conf.urls.defaults import *
from django.contrib.formtools.wizard.tests.namedwizardtests.forms import (
from django.conf.urls.defaults import patterns, url
from django.contrib.formtools.tests.wizard.namedwizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
def get_named_session_wizard():

View File

@ -1,8 +1,9 @@
from django.test import TestCase
from django.contrib.formtools.wizard.tests.storagetests import TestStorage
from django.contrib.formtools.tests.wizard.storage import TestStorage
from django.contrib.formtools.wizard.storage.session import SessionStorage
class TestSessionStorage(TestStorage, TestCase):
def get_storage(self):
return SessionStorage

View File

@ -6,12 +6,14 @@ from django.utils.importlib import import_module
from django.contrib.auth.models import User
def get_request():
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
request.session = engine.SessionStore(None)
return request
class TestStorage(object):
def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1')
@ -73,4 +75,3 @@ class TestStorage(object):
storage.extra_data = extra_context
storage2 = self.get_storage()('wizard2', request, None)
self.assertEqual(storage2.extra_data, {})

View File

@ -34,7 +34,7 @@ class ContactWizard(WizardView):
def done(self, form_list, **kwargs):
c = Context({
'form_list': [x.cleaned_data for x in form_list],
'all_cleaned_data': self.get_all_cleaned_data()
'all_cleaned_data': self.get_all_cleaned_data(),
})
for form in self.form_list.keys():

View File

@ -5,10 +5,9 @@ from django.test import TestCase
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.formtools import wizard
class WizardTests(object):
urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls'
urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1')
@ -269,7 +268,7 @@ class WizardTestKwargs(TestCase):
'cookie_contact_wizard-current_step': 'form4',
}
)
urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls'
urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1')

View File

@ -1,5 +1,5 @@
from django.conf.urls.defaults import *
from django.contrib.formtools.wizard.tests.wizardtests.forms import (
from django.contrib.formtools.tests.wizard.wizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
urlpatterns = patterns('',

View File

@ -1,6 +0,0 @@
from django.contrib.formtools.wizard.tests.formtests import *
from django.contrib.formtools.wizard.tests.sessionstoragetests import *
from django.contrib.formtools.wizard.tests.cookiestoragetests import *
from django.contrib.formtools.wizard.tests.loadstoragetests import *
from django.contrib.formtools.wizard.tests.wizardtests import *
from django.contrib.formtools.wizard.tests.namedwizardtests import *

View File

@ -1 +0,0 @@
from django.contrib.formtools.wizard.tests.namedwizardtests.tests import *

View File

@ -1 +0,0 @@
from django.contrib.formtools.wizard.tests.wizardtests.tests import *

View File

@ -51,7 +51,7 @@ you just have to do these things:
generic template to handle every one of the forms, or you can define a
specific template for each form.
4. Add ``django.contrib.formtools.wizard`` to your
4. Add ``django.contrib.formtools`` to your
:setting:`INSTALLED_APPS` list in your settings file.
5. Point your URLconf at your :class:`WizardView` :meth:`~WizardView.as_view` method.

View File

@ -102,7 +102,7 @@ An abstraction of the following workflow:
See the :doc:`form preview documentation </ref/contrib/formtools/form-preview>`.
django.contrib.formtools.wizard
--------------------------------
-------------------------------
Splits forms across multiple Web pages.

View File

@ -35,7 +35,6 @@ ALWAYS_INSTALLED_APPS = [
'django.contrib.admindocs',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.formtools.wizard',
'regressiontests.staticfiles_tests',
'regressiontests.staticfiles_tests.apps.test',
'regressiontests.staticfiles_tests.apps.no_label',