Changeset 3128 in products for quintagroup.captcha.core/trunk/quintagroup/captcha/core/tests/testWidget.py
- Timestamp:
- Apr 18, 2011 11:16:39 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.captcha.core/trunk/quintagroup/captcha/core/tests/testWidget.py
r2542 r3128 12 12 testPatch() 13 13 14 14 15 def addTestLayer(self): 15 16 # Install test_captcha skin layer … … 19 20 skinName = skins.getDefaultSkin() 20 21 paths = map(string.strip, skins.getSkinPath(skinName).split(',')) 21 paths.insert(paths.index('custom') +1, 'test_captcha')22 paths.insert(paths.index('custom') + 1, 'test_captcha') 22 23 skins.addSkinSelection(skinName, ','.join(paths)) 23 24 self._refreshSkinData() … … 34 35 self.absolute_url = self.portal['index_html'].absolute_url_path() 35 36 36 self.basic_auth = ':'.join((portal_owner, default_password))37 self.basic_auth = ':'.join((portal_owner, default_password)) 37 38 self.captcha_key = self.portal.captcha_key 38 39 39 40 def testImage(self): 40 41 path = '%s/test_form' % self.absolute_url 41 response = self.publish(path, self.basic_auth, request_method='GET').getBody() 42 response = self.publish(path, self.basic_auth, 43 request_method='GET').getBody() 42 44 patt = re.compile(IMAGE_PATT % self.portal.absolute_url()) 43 45 match_obj = patt.search(response) 44 46 45 47 img_url = match_obj.group(1) 46 content_type = self.publish('/plone' + img_url, self.basic_auth).getHeader('content-type') 48 res = self.publish('/plone' + img_url, self.basic_auth) 49 content_type = res.getHeader('content-type') 47 50 self.assert_(content_type.startswith('image')) 48 51 49 52 def testSubmitRightCaptcha(self): 50 53 hashkey = self.portal.getCaptcha() 51 # index of word number starts from 1, but index of dictionary starts from 0 52 key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])-1 ) 54 # index of word number starts from 1, 55 # but index of dictionary starts from 0 56 decrypted_key = decrypt(self.captcha_key, hashkey) 57 key = getWord(int(parseKey(decrypted_key)['key']) - 1) 53 58 parameters = 'form.submitted=1&key=%s' % key 54 59 path = '%s/test_form?%s' % (self.absolute_url, parameters) 55 60 extra = {'hashkey': hashkey, 56 61 'form.button.Save': 'Save'} 57 response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 62 response = self.publish(path, self.basic_auth, extra=extra, 63 request_method='GET').getBody() 58 64 self.assert_(not NOT_VALID.search(response)) 59 65 … … 64 70 extra = {'hashkey': hashkey, 65 71 'form.button.Save': 'Save'} 66 response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 72 response = self.publish(path, self.basic_auth, extra=extra, 73 request_method='GET').getBody() 67 74 self.assert_(NOT_VALID.search(response)) 68 75 69 76 def testSubmitRightCaptchaTwice(self): 70 77 hashkey = self.portal.getCaptcha() 71 key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])-1) 72 parameters = 'form.submitted=1&key=%s'%key 73 path = '%s/test_form?%s'%(self.absolute_url, parameters) 78 decrypted_key = decrypt(self.captcha_key, hashkey) 79 key = getWord(int(parseKey(decrypted_key)['key']) - 1) 80 parameters = 'form.submitted=1&key=%s' % key 81 path = '%s/test_form?%s' % (self.absolute_url, parameters) 74 82 extra = {'hashkey': hashkey, 75 83 'form.button.Save': 'Save'} 76 84 self.publish(path, self.basic_auth, extra=extra, request_method='GET') 77 response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 85 response = self.publish(path, self.basic_auth, extra=extra, 86 request_method='GET').getBody() 78 87 79 88 self.assert_(NOT_VALID.search(response)) … … 82 91 # captcha core related issue, described in 83 92 # in http://plone.org/products/plone-comments/issues/5 84 resp = self.publish(self.portal.absolute_url(1) +"/captcha_widget")93 resp = self.publish(self.portal.absolute_url(1) + "/captcha_widget") 85 94 self.assertEqual(resp.status / 100, 2) 95 86 96 87 97 def test_suite():
Note: See TracChangeset
for help on using the changeset viewer.