Index: /main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py
===================================================================
--- /main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py	(revision 7282)
+++ /main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py	(revision 7282)
@@ -0,0 +1,99 @@
+##
+## test_captcha.py
+## Login : <uli@pu.smp.net>
+## Started on  Tue Dec  6 12:54:29 2011 Uli Fouquet
+## $Id$
+## 
+## Copyright (C) 2011 Uli Fouquet
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+## 
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+## 
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+from zope.component import getAdapter
+from zope.interface import verify
+from zope.publisher.browser import TestRequest
+from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
+from waeup.sirp.browser.captcha import (
+    ICaptchaResponse, ICaptchaRequest, ICaptcha)
+from waeup.sirp.browser.captcha import (
+    CaptchaResponse, CaptchaRequest, NullCaptcha)
+
+class CaptchaResponseTests(FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def test_ifaces(self):
+        # make sure we implement the promised interfaces
+        obj = CaptchaResponse(True)
+        verify.verifyClass(ICaptchaResponse, CaptchaResponse)
+        verify.verifyObject(ICaptchaResponse, obj)
+        return
+
+    def test_init_vals(self):
+        # make sure the initial values are stored
+        resp = CaptchaResponse(False, 'some-msg')
+        self.assertEqual(resp.is_valid, False)
+        self.assertEqual(resp.error_code, 'some-msg')
+        return
+
+class CaptchaRequestTests(FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def test_ifaces(self):
+        # make sure we implement the promised interfces
+        obj = CaptchaRequest(None)
+        verify.verifyClass(ICaptchaRequest, CaptchaRequest)
+        verify.verifyObject(ICaptchaRequest, obj)
+        return
+
+    def test_init_vals(self):
+        # make sure initial values are stored
+        req = CaptchaRequest('my-solution', 'my-challenge')
+        self.assertEqual(req.solution, 'my-solution')
+        self.assertEqual(req.challenge, 'my-challenge')
+        return
+
+class NullCaptchaTests(FunctionalTestCase):
+
+    layer = FunctionalLayer
+
+    def test_ifaces(self):
+        # make sure we implement the promised interfaces
+        obj = NullCaptcha()
+        verify.verifyClass(ICaptcha, NullCaptcha)
+        verify.verifyObject(ICaptcha, obj)
+        return
+
+    def test_verify(self):
+        # null captchas accept any input request
+        captcha = NullCaptcha()
+        result1 = captcha.verify(CaptchaRequest('my-sol', 'my-challenge'))
+        result2 = captcha.verify(CaptchaRequest(None, None))
+        self.assertEqual(result1.is_valid, True)
+        self.assertEqual(result2.is_valid, True)
+        return
+
+    def test_display(self):
+        # null captchas do not generate additional HTML code
+        captcha = NullCaptcha()
+        result = captcha.display()
+        self.assertEqual(result, u'')
+        return
+
+    def test_adapter(self):
+        # the null captcha is also registered as an adapter to IHTTPRequest
+        request = TestRequest()
+        captcha = getAdapter(request, name='No captcha')
+        self.assertTrue(isinstance(captcha, NullCaptcha))
+        return
