Changeset 3128 in products for quintagroup.captcha.core/trunk/quintagroup/captcha/core/tests/testStatic.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/testStatic.py
r2542 r3128 4 4 from DateTime import DateTime 5 5 from Products.CMFFormController.ControllerState import ControllerState 6 6 7 7 8 class TestStatic(ptc.FunctionalTestCase): … … 19 20 for skin in self.skins.getSkinSelections(): 20 21 path = self.skins.getSkinPath(skin) 21 path = map( string.strip, string.split( path,','))22 path = map(string.strip, string.split(path, ',')) 22 23 self.assertTrue(LAYER_STATIC_CAPTCHAS in path) 23 24 … … 26 27 static = self.skins.restrictedTraverse('captchas') 27 28 static_ids = static.objectIds() 28 for i in range(1, CAPTCHAS_COUNT +1):29 for i in range(1, CAPTCHAS_COUNT + 1): 29 30 self.assertTrue("%s.jpg" % i in static_ids, 30 "No %s.jpg in static, %s" % (i, static_ids))31 "No %s.jpg in static, %s" % (i, static_ids)) 31 32 32 33 def test_GetCaptcha_Date(self): … … 45 46 self.assertTrue(index >= 1 and index <= CAPTCHAS_COUNT) 46 47 # encrypted key must be equals to title of the image 47 key = getWord( index-1)48 key = getWord(index - 1) 48 49 img = getattr(self.portal, '%s.jpg' % index) 49 50 self.assertTrue(encrypt1(key) == img.title) … … 51 52 def test_GetImage(self): 52 53 # getCaptchaImage function must return image coded in hashkey same to 53 # image get by 'key' after parsing decrypted key 54 # image get by 'key' after parsing decrypted key 54 55 req, resp = self.app.REQUEST, self.app.REQUEST.RESPONSE 55 56 decrypted_key = decrypt(self.captcha_key, self.hashkey) 56 57 parsed_key = parseKey(decrypted_key) 57 img = self.portal.restrictedTraverse(parsed_key['key'] +'.jpg')58 img = self.portal.restrictedTraverse(parsed_key['key'] + '.jpg') 58 59 img_html = img.index_html(req, resp) 59 60 60 obj_html = self.publish( 61 self.portal.absolute_url(1)+"/getCaptchaImage/%s" % self.hashkey).getBody() 62 self.assertTrue(obj_html == img_html, "Image get by getCaptchaImage script " \ 63 "is differ from image get by index (after parsing decrypted key)") 64 61 portal = self.portal.absolute_url(1) 62 captcha_path = portal + "/getCaptchaImage/%s" % self.hashkey 63 obj_html = self.publish(captcha_path).getBody() 64 msg = "Image get by getCaptchaImage script is differ from"\ 65 "image get by index (after parsing decrypted key)" 66 self.assertTrue(obj_html == img_html, msg) 67 65 68 66 69 class TestStaticValidator(ptc.PloneTestCase): … … 80 83 def testGoodData(self): 81 84 hashkey = self.portal.getCaptcha() 82 key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])-1 ) 85 decrypted_key = decrypt(self.captcha_key, hashkey) 86 key = getWord(int(parseKey(decrypted_key)['key']) - 1) 83 87 self.req.form['hashkey'] = hashkey 84 self.req.form['key'] = key +'1'88 self.req.form['key'] = key + '1' 85 89 86 cstate = self.pfc.validate(self.dummycs, self.req, ['captcha_validator',]) 87 self.assertTrue(cstate.getErrors()['key'] == 'Please re-enter validation code.', 90 cstate = self.pfc.validate(self.dummycs, self.req, 91 ['captcha_validator', ]) 92 error_msg = 'Please re-enter validation code.' 93 self.assertTrue(cstate.getErrors()['key'] == error_msg, 88 94 "Static captcha validator validate wrong key") 89 95 90 96 def testBadKey(self): 91 97 hashkey = self.portal.getCaptcha() 92 key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])-1 ) 98 decrypted_key = decrypt(self.captcha_key, hashkey) 99 key = getWord(int(parseKey(decrypted_key)['key']) - 1) 93 100 self.req.form['hashkey'] = hashkey 94 101 self.req.form['key'] = 'bad key' 95 96 cstate = self.pfc.validate(self.dummycs, self.req, ['captcha_validator',]) 97 self.assertTrue(cstate.getErrors()['key'] == 'Please re-enter validation code.', 102 103 cstate = self.pfc.validate(self.dummycs, self.req, 104 ['captcha_validator', ]) 105 error_msg = 'Please re-enter validation code.' 106 self.assertTrue(cstate.getErrors()['key'] == error_msg, 98 107 "Static captcha validator validate wrong key") 99 108 … … 103 112 now = DateTime().timeTime() 104 113 DateTime.timeTime = lambda s: now - float(3601) 105 114 106 115 hashkey = self.portal.getCaptcha() 107 key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])-1 ) 116 117 decrypted_key = decrypt(self.captcha_key, hashkey) 118 key = getWord(int(parseKey(decrypted_key)['key']) - 1) 108 119 self.req.form['hashkey'] = hashkey 109 120 self.req.form['key'] = key 110 121 # Return original Date 111 122 DateTime.timeTime = origDTTT 112 cstate = self.pfc.validate(self.dummycs, self.req, ['captcha_validator',]) 113 self.assertTrue(cstate.getErrors()['key'] == 'Please re-enter validation code.', 123 cstate = self.pfc.validate(self.dummycs, self.req, 124 ['captcha_validator', ]) 125 error_msg = 'Please re-enter validation code.' 126 self.assertTrue(cstate.getErrors()['key'] == error_msg, 114 127 "Static captcha validator validate wrong key") 115 128
Note: See TracChangeset
for help on using the changeset viewer.