Ignore:
Timestamp:
7 Dec 2011, 07:17:32 (13 years ago)
Author:
uli
Message:

Add ReCaptcha? tests. One of them is intentionally disabled because it
contacts remote servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py

    r7301 r7302  
    2525    ICaptchaResponse, ICaptchaRequest, ICaptcha, ICaptchaChooser)
    2626from waeup.sirp.browser.captcha import (
    27     CaptchaResponse, CaptchaRequest, NullCaptcha, StaticCaptcha, CaptchaChooser)
     27    CaptchaResponse, CaptchaRequest, NullCaptcha, StaticCaptcha, ReCaptcha,
     28    CaptchaChooser)
    2829
    2930class CaptchaResponseTests(FunctionalTestCase):
     
    140141        return
    141142
     143class ReCaptchaTests(FunctionalTestCase, CaptchaTestBase):
     144
     145    layer = FunctionalLayer
     146
     147    factory = ReCaptcha
     148    name = 'ReCaptcha'
     149
     150    def DISABLEDtest_verify(self):
     151        # recaptcha verification cannot be tested easily. As the
     152        # solution and other environment parameters is only known to
     153        # the remote server, we cannot guess on server side what the
     154        # solution is.  Further more this test contacts a remote
     155        # server so that we might want to disable this test by
     156        # default.
     157        captcha = self.factory()
     158        request1 = TestRequest(
     159            form={'recaptcha_challenge_field': 'my-challenge',
     160                  'recaptcha_response_field': 'my-solution'})
     161        result1 = captcha.verify(request1)
     162        self.assertEqual(result1.is_valid, False)
     163        self.assertEqual(result1.error_code, 'invalid-request-cookie')
     164        return
     165
     166    def test_display(self):
     167        # recaptchas provide the pieces to trigger the remote API
     168        captcha = self.factory()
     169        result = captcha.display()
     170        self.assertMatches(
     171            '<script type="text/javascript" src="..."></script>'
     172            '<noscript>'
     173            '<iframe src="..." height="300" width="500" '
     174            '        frameborder="0"></iframe><br />'
     175            '<textarea name="recaptcha_challenge_field" rows="3" '
     176            '          cols="40"></textarea>'
     177            '<input type="hidden" name="recaptcha_response_field" '
     178            '       value="manual_challenge" /></noscript>',
     179            result)
     180        return
    142181
    143182class CaptchaChooserTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.