Kaydet (Commit) a13de6cd authored tarafından Jannis Leidel's avatar Jannis Leidel

Fixed #6644 -- Fixed django.contrib.formtools tests to be better isolated when…

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
üst 566b3295
...@@ -4,12 +4,13 @@ import warnings ...@@ -4,12 +4,13 @@ import warnings
from django import http from django import http
from django.conf import settings 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 import TestCase
from django.test.utils import get_warnings_state, restore_warnings_state from django.test.utils import get_warnings_state, restore_warnings_state
from django.utils import unittest 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 * from django.contrib.formtools.tests.forms import *
warnings.filterwarnings('ignore', category=PendingDeprecationWarning, warnings.filterwarnings('ignore', category=PendingDeprecationWarning,
...@@ -30,10 +31,22 @@ class TestFormPreview(preview.FormPreview): ...@@ -30,10 +31,22 @@ class TestFormPreview(preview.FormPreview):
return http.HttpResponse(success_string) 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' urls = 'django.contrib.formtools.tests.urls'
def setUp(self): def setUp(self):
super(PreviewTests, self).setUp()
self.save_warnings_state() self.save_warnings_state()
warnings.filterwarnings('ignore', category=DeprecationWarning, warnings.filterwarnings('ignore', category=DeprecationWarning,
module='django.contrib.formtools.utils') module='django.contrib.formtools.utils')
...@@ -45,6 +58,7 @@ class PreviewTests(TestCase): ...@@ -45,6 +58,7 @@ class PreviewTests(TestCase):
self.test_data = {'field1':u'foo', 'field1_':u'asdf'} self.test_data = {'field1':u'foo', 'field1_':u'asdf'}
def tearDown(self): def tearDown(self):
super(PreviewTests, self).tearDown()
self.restore_warnings_state() self.restore_warnings_state()
def test_unused_name(self): def test_unused_name(self):
...@@ -224,7 +238,7 @@ class FormHmacTests(unittest.TestCase): ...@@ -224,7 +238,7 @@ class FormHmacTests(unittest.TestCase):
# FormWizard tests # FormWizard tests
# #
class TestWizardClass(wizard.FormWizard): class TestWizardClass(FormWizard):
def get_template(self, step): def get_template(self, step):
return 'forms/wizard.html' return 'forms/wizard.html'
...@@ -243,7 +257,7 @@ class DummyRequest(http.HttpRequest): ...@@ -243,7 +257,7 @@ class DummyRequest(http.HttpRequest):
self._dont_enforce_csrf_checks = True self._dont_enforce_csrf_checks = True
class WizardTests(TestCase): class WizardTests(FormToolsTestCase):
urls = 'django.contrib.formtools.tests.urls' urls = 'django.contrib.formtools.tests.urls'
input_re = re.compile('name="([^"]+)" value="([^"]+)"') input_re = re.compile('name="([^"]+)" value="([^"]+)"')
wizard_step_data = ( wizard_step_data = (
...@@ -261,19 +275,13 @@ class WizardTests(TestCase): ...@@ -261,19 +275,13 @@ class WizardTests(TestCase):
) )
def setUp(self): def setUp(self):
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS super(WizardTests, self).setUp()
settings.TEMPLATE_DIRS = (
os.path.join(
os.path.dirname(__file__),
'templates'
),
)
# Use a known SECRET_KEY to make security_hash tests deterministic # Use a known SECRET_KEY to make security_hash tests deterministic
self.old_SECRET_KEY = settings.SECRET_KEY self.old_SECRET_KEY = settings.SECRET_KEY
settings.SECRET_KEY = "123" settings.SECRET_KEY = "123"
def tearDown(self): def tearDown(self):
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS super(WizardTests, self).tearDown()
settings.SECRET_KEY = self.old_SECRET_KEY settings.SECRET_KEY = self.old_SECRET_KEY
def test_step_starts_at_zero(self): def test_step_starts_at_zero(self):
......
...@@ -9,10 +9,10 @@ class Page1(forms.Form): ...@@ -9,10 +9,10 @@ class Page1(forms.Form):
class Page2(forms.Form): class Page2(forms.Form):
address1 = forms.CharField(max_length=100) address1 = forms.CharField(max_length=100)
address2 = forms.CharField(max_length=100) address2 = forms.CharField(max_length=100)
class Page3(forms.Form): class Page3(forms.Form):
random_crap = forms.CharField(max_length=100) random_crap = forms.CharField(max_length=100)
class ContactWizard(FormWizard): class ContactWizard(FormWizard):
def done(self, request, form_list): def done(self, request, form_list):
return HttpResponse("") return HttpResponse("")
......
{% block content %}
{% endblock %}
\ No newline at end of file
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,
)
...@@ -4,7 +4,8 @@ from django.core.exceptions import SuspiciousOperation ...@@ -4,7 +4,8 @@ from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse from django.http import HttpResponse
from django.contrib.formtools.wizard.storage.cookie import CookieStorage 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): class TestCookieStorage(TestStorage, TestCase):
def get_storage(self): def get_storage(self):
......
...@@ -20,6 +20,7 @@ class DummyRequest(http.HttpRequest): ...@@ -20,6 +20,7 @@ class DummyRequest(http.HttpRequest):
self.session = {} self.session = {}
self._dont_enforce_csrf_checks = True self._dont_enforce_csrf_checks = True
def get_request(*args, **kwargs): def get_request(*args, **kwargs):
request = DummyRequest(*args, **kwargs) request = DummyRequest(*args, **kwargs)
engine = import_module(settings.SESSION_ENGINE) engine = import_module(settings.SESSION_ENGINE)
...@@ -202,4 +203,3 @@ class CookieFormTests(TestCase): ...@@ -202,4 +203,3 @@ class CookieFormTests(TestCase):
request = get_request() request = get_request()
testform = CookieWizardView.as_view([('start', Step1)]) testform = CookieWizardView.as_view([('start', Step1)])
self.assertTrue(isinstance(testform(request), TemplateResponse)) self.assertTrue(isinstance(testform(request), TemplateResponse))
...@@ -4,16 +4,12 @@ from django.test import TestCase ...@@ -4,16 +4,12 @@ from django.test import TestCase
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.formtools import wizard
from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView, from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView,
NamedUrlCookieWizardView) NamedUrlCookieWizardView)
from django.contrib.formtools.wizard.tests.formtests import (get_request, from django.contrib.formtools.tests.wizard.forms import get_request, Step1, Step2
Step1,
Step2)
class NamedWizardTests(object): class NamedWizardTests(object):
urls = 'django.contrib.formtools.wizard.tests.namedwizardtests.urls' urls = 'django.contrib.formtools.tests.wizard.namedwizardtests.urls'
def setUp(self): def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1') self.testuser, created = User.objects.get_or_create(username='testuser1')
...@@ -310,7 +306,7 @@ class NamedCookieWizardTests(NamedWizardTests, TestCase): ...@@ -310,7 +306,7 @@ class NamedCookieWizardTests(NamedWizardTests, TestCase):
class NamedFormTests(object): class NamedFormTests(object):
urls = 'django.contrib.formtools.wizard.tests.namedwizardtests.urls' urls = 'django.contrib.formtools.tests.wizard.namedwizardtests.urls'
def test_revalidation(self): def test_revalidation(self):
request = get_request() request = get_request()
......
from django.conf.urls.defaults import * from django.conf.urls.defaults import patterns, url
from django.contrib.formtools.wizard.tests.namedwizardtests.forms import ( from django.contrib.formtools.tests.wizard.namedwizardtests.forms import (
SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4) SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
def get_named_session_wizard(): def get_named_session_wizard():
......
from django.test import TestCase 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 from django.contrib.formtools.wizard.storage.session import SessionStorage
class TestSessionStorage(TestStorage, TestCase): class TestSessionStorage(TestStorage, TestCase):
def get_storage(self): def get_storage(self):
return SessionStorage return SessionStorage
...@@ -6,12 +6,14 @@ from django.utils.importlib import import_module ...@@ -6,12 +6,14 @@ from django.utils.importlib import import_module
from django.contrib.auth.models import User from django.contrib.auth.models import User
def get_request(): def get_request():
request = HttpRequest() request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE) engine = import_module(settings.SESSION_ENGINE)
request.session = engine.SessionStore(None) request.session = engine.SessionStore(None)
return request return request
class TestStorage(object): class TestStorage(object):
def setUp(self): def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1') self.testuser, created = User.objects.get_or_create(username='testuser1')
...@@ -73,4 +75,3 @@ class TestStorage(object): ...@@ -73,4 +75,3 @@ class TestStorage(object):
storage.extra_data = extra_context storage.extra_data = extra_context
storage2 = self.get_storage()('wizard2', request, None) storage2 = self.get_storage()('wizard2', request, None)
self.assertEqual(storage2.extra_data, {}) self.assertEqual(storage2.extra_data, {})
...@@ -34,7 +34,7 @@ class ContactWizard(WizardView): ...@@ -34,7 +34,7 @@ class ContactWizard(WizardView):
def done(self, form_list, **kwargs): def done(self, form_list, **kwargs):
c = Context({ c = Context({
'form_list': [x.cleaned_data for x in form_list], '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(): for form in self.form_list.keys():
......
...@@ -5,10 +5,9 @@ from django.test import TestCase ...@@ -5,10 +5,9 @@ from django.test import TestCase
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.formtools import wizard
class WizardTests(object): class WizardTests(object):
urls = 'django.contrib.formtools.wizard.tests.wizardtests.urls' urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
def setUp(self): def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1') self.testuser, created = User.objects.get_or_create(username='testuser1')
...@@ -269,7 +268,7 @@ class WizardTestKwargs(TestCase): ...@@ -269,7 +268,7 @@ class WizardTestKwargs(TestCase):
'cookie_contact_wizard-current_step': 'form4', '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): def setUp(self):
self.testuser, created = User.objects.get_or_create(username='testuser1') self.testuser, created = User.objects.get_or_create(username='testuser1')
......
from django.conf.urls.defaults import * 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) SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4)
urlpatterns = patterns('', urlpatterns = patterns('',
......
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 *
from django.contrib.formtools.wizard.tests.namedwizardtests.tests import *
\ No newline at end of file
from django.contrib.formtools.wizard.tests.wizardtests.tests import *
\ No newline at end of file
...@@ -51,7 +51,7 @@ you just have to do these things: ...@@ -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 generic template to handle every one of the forms, or you can define a
specific template for each form. 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. :setting:`INSTALLED_APPS` list in your settings file.
5. Point your URLconf at your :class:`WizardView` :meth:`~WizardView.as_view` method. 5. Point your URLconf at your :class:`WizardView` :meth:`~WizardView.as_view` method.
......
...@@ -102,7 +102,7 @@ An abstraction of the following workflow: ...@@ -102,7 +102,7 @@ An abstraction of the following workflow:
See the :doc:`form preview documentation </ref/contrib/formtools/form-preview>`. See the :doc:`form preview documentation </ref/contrib/formtools/form-preview>`.
django.contrib.formtools.wizard django.contrib.formtools.wizard
-------------------------------- -------------------------------
Splits forms across multiple Web pages. Splits forms across multiple Web pages.
......
...@@ -35,7 +35,6 @@ ALWAYS_INSTALLED_APPS = [ ...@@ -35,7 +35,6 @@ ALWAYS_INSTALLED_APPS = [
'django.contrib.admindocs', 'django.contrib.admindocs',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'django.contrib.humanize', 'django.contrib.humanize',
'django.contrib.formtools.wizard',
'regressiontests.staticfiles_tests', 'regressiontests.staticfiles_tests',
'regressiontests.staticfiles_tests.apps.test', 'regressiontests.staticfiles_tests.apps.test',
'regressiontests.staticfiles_tests.apps.no_label', 'regressiontests.staticfiles_tests.apps.no_label',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment