Changeset 3160 in products for quintagroup.plonecaptchas/branches/plone4/quintagroup/plonecaptchas/tests/testForms.py
- Timestamp:
- Apr 20, 2011 10:44:02 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonecaptchas/branches/plone4/quintagroup/plonecaptchas/tests/testForms.py
r3154 r3160 17 17 from plone.app.controlpanel.security import ISecuritySchema 18 18 19 # BBB for plone v<3.1, where plone.protect not used yet 19 # BBB for plone v<3.1, where plone.protect not used yet 20 20 PROTECT_SUPPORT = True 21 21 try: … … 30 30 testPatch() 31 31 32 32 33 class TestFormMixin(FunctionalTestCase): 33 34 … … 41 42 addTestLayer(self) 42 43 # Prepare form data 43 self.basic_auth = ':'.join((portal_owner, default_password))44 self.basic_auth = ':'.join((portal_owner, default_password)) 44 45 self.form_url = '' 45 46 self.form_method = "POST" … … 55 56 raise NotImplementedError( 56 57 "getFormData not implemented") 57 58 58 59 def publishForm(self): 59 60 stdin_data = None … … 82 83 open("/tmp/test.%s.html" % name, "w").write(response) 83 84 logs = self.portal.error_log.getLogEntries() 84 if len(logs) >0:85 if len(logs) > 0: 85 86 i = 0 86 87 while logs: 87 88 l = logs.pop() 88 i +=189 open("/tmp/test.%s.error.%d.html" % (l ,i),"w").write(l["tb_html"])90 import pdb;pdb.set_trace()89 i += 1 90 open("/tmp/test.%s.error.%d.html" % (l["id"], i), 91 "w").write(l["tb_html"]) 91 92 92 93 def testImage(self): … … 94 95 self.form_method = "GET" 95 96 response = self.publishForm().getBody() 96 patt = re.compile(IMAGE_PATT 97 patt = re.compile(IMAGE_PATT % self.portal.absolute_url()) 97 98 match_obj = patt.search(response) 98 99 self.elog("image", response) 99 100 img_url = match_obj.group(1) 100 101 101 content_type = self.publish('/plone' + img_url).getHeader('content-type') 102 content_type = self.publish( 103 '/plone' + img_url).getHeader('content-type') 102 104 self.assertTrue(content_type.startswith('image'), 103 105 "Wrong captcha image content type") 104 106 105 107 def testSubmitRightCaptcha(self): 106 key = getWord(int(parseKey(decrypt(self.captcha_key, self.hashkey))['key'])-1) 108 key = getWord(int(parseKey(decrypt(self.captcha_key, 109 self.hashkey))['key']) - 1) 107 110 self.form_data[self.formkey_key] = key 108 111 109 112 response = self.publishForm().getBody() 110 113 self.elog("right", response) … … 118 121 119 122 def testSubmitRightCaptchaTwice(self): 120 key = getWord(int(parseKey(decrypt(self.captcha_key, self.hashkey))['key'])-1) 123 key = getWord(int(parseKey(decrypt(self.captcha_key, 124 self.hashkey))['key']) - 1) 121 125 self.form_data[self.formkey_key] = key 122 126 … … 135 139 self.portal['index_html'].allowDiscussion(True) 136 140 self.form_url = '/index_html/discussion_reply_form' 137 138 def getFormData(self): 139 return {'form.submitted' 141 142 def getFormData(self): 143 return {'form.submitted': '1', 140 144 'subject': 'testing', 141 145 'Creator': portal_owner, 142 146 'body_text': 'Text in Comment', 143 147 'discussion_reply:method': 'Save', 144 'form.button.form_submit' 148 'form.button.form_submit': 'Save'} 145 149 146 150 … … 160 164 161 165 def getFormData(self): 162 return {"form.fullname" 163 "form.username" 164 "form.email" 165 "form.password" 166 "form.password_ctl" 167 'form.actions.register' 166 return {"form.fullname": "Tester", 167 "form.username": "tester", 168 "form.email": "tester@test.com", 169 "form.password": "123456", 170 "form.password_ctl": "123456", 171 'form.actions.register': 'Register'} 168 172 169 173 … … 175 179 self.portal['index_html'].allowDiscussion(True) 176 180 self.form_url = '/index_html/sendto_form' 177 178 def getFormData(self): 179 return {'form.submitted' 180 "send_to_address" 181 "send_from_address" 181 182 def getFormData(self): 183 return {'form.submitted': '1', 184 "send_to_address": "recipient@test.com", 185 "send_from_address": "sender@test.com", 182 186 'comment': 'Text in Comment', 183 'form.button.Send' : 'Save'} 187 'form.button.Send': 'Save'} 188 184 189 185 190 def send_patch(self, *args, **kwargs): 186 191 """This patch prevent breakage on sending.""" 187 192 193 188 194 class TestContactInfo(TestFormMixin): 189 195 … … 191 197 TestFormMixin.afterSetUp(self) 192 198 # preparation to form correct working 193 self.portal._updateProperty('email_from_address', 'manager@test.com')199 self.portal._updateProperty('email_from_address', 'manager@test.com') 194 200 self.logout() 195 201 self.form_url = '/contact-info' … … 201 207 202 208 def getFormData(self): 203 return {'form.submitted' 204 "sender_fullname" 205 "sender_from_address" 209 return {'form.submitted': '1', 210 "sender_fullname": "tester", 211 "sender_from_address": "sender@test.com", 206 212 'subject': 'Subject', 207 213 'message': 'Message', 208 'form.button.Send' 214 'form.button.Send': 'Save'} 209 215 210 216
Note: See TracChangeset
for help on using the changeset viewer.