add further doctests (failing).
svn path=/plone.formwidget.captcha/trunk/; revision=28724
This commit is contained in:
parent
56c7d377ec
commit
e7d28bd6ef
|
@ -63,4 +63,35 @@ First, set up a simple test form and context.
|
|||
>>> provideAdapter(adapts=(ICaptchaForm, IBrowserRequest),
|
||||
... provides=Interface,
|
||||
... factory=form_view,
|
||||
... name=u"captcha-form")
|
||||
... name=u"captcha-form")
|
||||
|
||||
>>> from OFS.SimpleItem import SimpleItem
|
||||
>>> class Bar(SimpleItem):
|
||||
... __allow_access_to_unprotected_subobjects__ = 1
|
||||
... implements(ICaptchaForm)
|
||||
...
|
||||
... def __init__(self, id):
|
||||
... self.id = id
|
||||
... self.subject = u""
|
||||
... self.captcha = u""
|
||||
|
||||
Let us now look up the form and attempt to render the widget.
|
||||
|
||||
>>> from zope.component import getMultiAdapter
|
||||
>>> from OFS.Application import Application
|
||||
>>> app = Application()
|
||||
>>> app.REQUEST = make_request('/') # eeeevil
|
||||
>>> context = Bar('bar').__of__(app)
|
||||
|
||||
Simulates traversal:
|
||||
|
||||
>>> request = make_request('bar/@@captcha-form')
|
||||
>>> form_view = getMultiAdapter((context, request), name=u"captcha-form").__of__(context)
|
||||
>>> form_view.__name__ = 'captcha-form'
|
||||
|
||||
Simulates partial rendering:
|
||||
|
||||
>>> form = form_view.form_instance
|
||||
>>> form.__name__ = 'captcha-form'
|
||||
>>> form.update()
|
||||
>>> print form.widgets['captcha'].render() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<configure
|
||||
xmlns="http://namespaces.zope.org/zope"
|
||||
xmlns:z3c="http://namespaces.zope.org/z3c"
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
i18n_domain="plone.formwidget.captcha">
|
||||
|
||||
<include file="meta.zcml" package="Products.GenericSetup"/>
|
||||
|
||||
<include package="plone.z3cform" file="testing.zcml" />
|
||||
<include package="plone.formwidget.captcha" file="configure.zcml" />
|
||||
|
||||
</configure>
|
|
@ -1,54 +1,16 @@
|
|||
import os
|
||||
import unittest
|
||||
|
||||
from zope.testing import doctestunit
|
||||
from zope.component import testing
|
||||
from Testing import ZopeTestCase as ztc
|
||||
|
||||
from Products.Five import zcml
|
||||
from Products.Five import fiveconfigure
|
||||
from Products.PloneTestCase import PloneTestCase as ptc
|
||||
from Products.PloneTestCase.layer import PloneSite
|
||||
ptc.setupPloneSite()
|
||||
|
||||
import plone.formwidget.captcha
|
||||
|
||||
class TestCase(ptc.PloneTestCase):
|
||||
class layer(PloneSite):
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
fiveconfigure.debug_mode = True
|
||||
zcml.load_config('configure.zcml',
|
||||
plone.formwidget.captcha)
|
||||
fiveconfigure.debug_mode = False
|
||||
|
||||
@classmethod
|
||||
def tearDown(cls):
|
||||
pass
|
||||
from zope.testing import doctest
|
||||
from zope.app.testing.functional import ZCMLLayer
|
||||
|
||||
testing_zcml_path = os.path.join(os.path.dirname(__file__), 'testing.zcml')
|
||||
testing_zcml_layer = ZCMLLayer(testing_zcml_path, 'plone.formwidget.captcha', 'testing_zcml_layer')
|
||||
|
||||
def test_suite():
|
||||
readme_txt = doctest.DocFileSuite('README.txt')
|
||||
readme_txt.layer = testing_zcml_layer
|
||||
|
||||
return unittest.TestSuite([
|
||||
|
||||
# Unit tests
|
||||
doctestunit.DocFileSuite(
|
||||
'README.txt', package='plone.formwidget.captcha',
|
||||
setUp=testing.setUp, tearDown=testing.tearDown),
|
||||
|
||||
#doctestunit.DocTestSuite(
|
||||
# module='plone.formwidget.captcha.mymodule',
|
||||
# setUp=testing.setUp, tearDown=testing.tearDown),
|
||||
|
||||
|
||||
# Integration tests that use PloneTestCase
|
||||
#ztc.ZopeDocFileSuite(
|
||||
# 'README.txt', package='plone.formwidget.captcha',
|
||||
# test_class=TestCase),
|
||||
|
||||
#ztc.FunctionalDocFileSuite(
|
||||
# 'browser.txt', package='plone.formwidget.captcha',
|
||||
# test_class=TestCase),
|
||||
|
||||
readme_txt,
|
||||
])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(defaultTest='test_suite')
|
||||
|
|
Reference in New Issue