Ignore:
Timestamp:
7 Dec 2011, 00:12:39 (13 years ago)
Author:
uli
Message:

Add tests for IdCaptcha?.

File:
1 edited

Legend:

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

    r7294 r7295  
    2525    ICaptchaResponse, ICaptchaRequest, ICaptcha, ICaptchaChooser)
    2626from waeup.sirp.browser.captcha import (
    27     CaptchaResponse, CaptchaRequest, NullCaptcha, CaptchaChooser)
     27    CaptchaResponse, CaptchaRequest, NullCaptcha, IdCaptcha, CaptchaChooser)
    2828
    2929class CaptchaResponseTests(FunctionalTestCase):
     
    101101        return
    102102
    103 class TestCaptchaTests(FunctionalTestCase):
    104 
    105     layer = FunctionalLayer
     103class IdCaptchaTests(FunctionalTestCase, CaptchaTestBase):
     104
     105    layer = FunctionalLayer
     106
     107    factory = IdCaptcha
     108    name = 'Testing captcha'
     109
     110    def test_verify(self):
     111        # id captchas accept any solution that matches challenge and
     112        # is not empty or None
     113        captcha = self.factory()
     114        result1 = captcha.verify(CaptchaRequest('my-sol', 'my-challenge'))
     115        result2 = captcha.verify(CaptchaRequest(None, None))
     116        result3 = captcha.verify(CaptchaRequest('', ''))
     117        result4 = captcha.verify(CaptchaRequest('my-sol', 'my-sol'))
     118        self.assertEqual(result1.is_valid, False)
     119        self.assertEqual(result2.is_valid, False)
     120        self.assertEqual(result3.is_valid, False)
     121        self.assertEqual(result4.is_valid, True)
     122        return
     123
     124    def test_display(self):
     125        # id captchas provide a simple HTML input
     126        captcha = self.factory()
     127        result = captcha.display()
     128        self.assertMatches(
     129            '<input type="hidden" name="challenge"'
     130            '      value="..." /><br />Type: ...<br />'
     131            '<input type="text" name="solution" /><br />',
     132            result)
     133        return
     134
    106135
    107136class CaptchaChooserTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.