Changeset 7291


Ignore:
Timestamp:
6 Dec 2011, 16:45:18 (13 years ago)
Author:
uli
Message:

Add missing tests for getCaptcha.

File:
1 edited

Legend:

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

    r7286 r7291  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
     18import grok
    1819from zope.component import getAdapter, getUtility
    19 from zope.component.hooks import setSite
     20from zope.component.hooks import setSite, clearSite
    2021from zope.interface import verify
    2122from zope.publisher.browser import TestRequest
     
    9697
    9798class CaptchaChooserTests(FunctionalTestCase):
     99    # These tests do not require a site setup
    98100
    99101    layer = FunctionalLayer
     
    130132        self.assertTrue(result is default)
    131133        return
     134
     135class FakeSite(grok.Site, grok.Container):
     136    pass
     137
     138class CaptchaChooserTestsWithSite(FunctionalTestCase):
     139
     140    layer = FunctionalLayer
     141
     142    def setUp(self):
     143        super(CaptchaChooserTestsWithSite, self).setUp()
     144        self.getRootFolder()['app'] = FakeSite()
     145        self.site = self.getRootFolder()['app']
     146        return
     147
     148    def tearDown(self):
     149        super(CaptchaChooserTestsWithSite, self).tearDown()
     150        clearSite(self.site)
     151        return
     152
     153    def test_get_captcha_no_captcha_in_config(self):
     154        # if a site has no configuration setting for captchas, we get
     155        # the default captcha
     156        setSite(self.site)
     157        chooser = getUtility(ICaptchaChooser)
     158        result = chooser.getCaptcha()
     159        default = getUtility(ICaptcha)
     160        self.assertTrue(result is default)
     161        return
     162
     163    def test_get_captcha_empty_captcha_in_config(self):
     164        # if a site has None as configuration setting for captchas, we get
     165        # the default captcha
     166        setSite(self.site)
     167        self.site['configuration'] = dict()
     168        chooser = getUtility(ICaptchaChooser)
     169        result = chooser.getCaptcha()
     170        default = getUtility(ICaptcha)
     171        self.assertTrue(result is default)
     172        return
     173
     174    def test_get_captcha_invalid_captcha_in_config(self):
     175        # if a site has None as configuration setting for captchas, we get
     176        # the default captcha
     177        setSite(self.site)
     178        self.site['configuration'] = dict(captcha='invalid name')
     179        chooser = getUtility(ICaptchaChooser)
     180        result = chooser.getCaptcha()
     181        default = getUtility(ICaptcha)
     182        self.assertTrue(result is default)
     183        return
     184
     185    def test_get_captcha_invalid_captcha_in_config(self):
     186        # if a site has None as configuration setting for captchas, we get
     187        # the default captcha
     188        setSite(self.site)
     189        self.site['configuration'] = dict(captcha='No captcha')
     190        chooser = getUtility(ICaptchaChooser)
     191        result = chooser.getCaptcha()
     192        no_captcha = getUtility(ICaptcha, name='No captcha')
     193        default = getUtility(ICaptcha)
     194        self.assertTrue(result is not default)
     195        self.assertTrue(result is no_captcha)
     196        return
Note: See TracChangeset for help on using the changeset viewer.