Changeset 7291
- Timestamp:
- 6 Dec 2011, 16:45:18 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/browser/tests/test_captcha.py
r7286 r7291 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import grok 18 19 from zope.component import getAdapter, getUtility 19 from zope.component.hooks import setSite 20 from zope.component.hooks import setSite, clearSite 20 21 from zope.interface import verify 21 22 from zope.publisher.browser import TestRequest … … 96 97 97 98 class CaptchaChooserTests(FunctionalTestCase): 99 # These tests do not require a site setup 98 100 99 101 layer = FunctionalLayer … … 130 132 self.assertTrue(result is default) 131 133 return 134 135 class FakeSite(grok.Site, grok.Container): 136 pass 137 138 class 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.