From e7d28bd6ef80b971955fde5b76493e594fd6691c Mon Sep 17 00:00:00 2001 From: Timo Stollenwerk Date: Wed, 12 Aug 2009 07:04:47 +0000 Subject: [PATCH] add further doctests (failing). svn path=/plone.formwidget.captcha/trunk/; revision=28724 --- plone/formwidget/captcha/README.txt | 33 +++++++++++++++- plone/formwidget/captcha/testing.zcml | 12 ++++++ plone/formwidget/captcha/tests.py | 56 +++++---------------------- 3 files changed, 53 insertions(+), 48 deletions(-) create mode 100644 plone/formwidget/captcha/testing.zcml diff --git a/plone/formwidget/captcha/README.txt b/plone/formwidget/captcha/README.txt index a8718f0..687ad35 100644 --- a/plone/formwidget/captcha/README.txt +++ b/plone/formwidget/captcha/README.txt @@ -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") \ No newline at end of file + ... 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 diff --git a/plone/formwidget/captcha/testing.zcml b/plone/formwidget/captcha/testing.zcml new file mode 100644 index 0000000..9dd8e30 --- /dev/null +++ b/plone/formwidget/captcha/testing.zcml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/plone/formwidget/captcha/tests.py b/plone/formwidget/captcha/tests.py index a2ae73b..60cbbec 100644 --- a/plone/formwidget/captcha/tests.py +++ b/plone/formwidget/captcha/tests.py @@ -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')