Changeset 427

Show
Ignore:
Timestamp:
07/28/06 05:59:10
Author:
crchemist
Message:

Added more tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneCaptchas/trunk/Extensions/Install.py

    r426 r427  
    100100    updateProperty(props_sheet, id="avaliable_libs", value=avaliable_libs, property_type='lines', out=out) 
    101101    updateProperty(props_sheet, id="current_lib", value='avaliable_libs', property_type='selection', out=out) 
     102    updateProperty(props_sheet, id="current_lib", value="Static", out=out) 
    102103 
    103104def addConfiglet(self, configlet_id, configlet_name): 
  • qPloneCaptchas/trunk/skins/captchas_discussion/2.5/discussion_reply_form.cpt

    r426 r427  
    160160 
    161161            </div> 
    162             <div metal:use-macro="here/captcha_widget/macros/captcha"></div 
     162            <div metal:use-macro="here/captcha_widget/macros/captcha"></div> 
    163163            <div class="formControls"> 
    164164 
  • qPloneCaptchas/trunk/skins/plone_captchas/captcha_validator.vpy

    r426 r427  
    99evalkey = request.get('evalkey', '') 
    1010test_key = request.get('key', '') 
     11 
    1112if DateTime().timeTime() - float(evalkey)>3600: 
    1213   return  state.set(status="failure", portal_status_message="Please re enter key") 
  • qPloneCaptchas/trunk/tests/testQPloneComments.py

    r426 r427  
    33# 
    44 
    5 import os, sys 
     5import os, sys, re 
    66if __name__ == '__main__': 
    77    execfile(os.path.join(sys.path[0], 'framework.py')) 
     
    1313PloneTestCase.setupPloneSite() 
    1414 
     15def time(obj): 
     16    return 1153996082.8 
    1517 
    16 class TestQPloneCaptchas(PloneTestCase.FunctionalTestCase): 
     18from DateTime import DateTime 
     19DateTime.timeTime = time 
     20class TestQPloneStaticCaptchas(PloneTestCase.FunctionalTestCase): 
    1721 
    1822    def afterSetUp(self): 
    1923        self.addProduct('qPloneComments') 
    2024        self.addProduct('qPloneCaptchas') 
    21          
    22          
    23     def testEditForm(self): 
    24          
     25        self.loginAsPortalOwner() 
     26        self.portal.portal_properties['qPloneCaptchas'].current_lib = 'Static' 
     27        self.portal.invokeFactory('Document', 'index_html') 
     28        self.portal['index_html'].allow_discussion = True 
     29        self.absolute_url = self.portal['index_html'].absolute_url_path() 
    2530 
     31    def test_editform_with_right_captcha(self): 
     32        parameters = 'form.submitted=1&Creator=test_user&key=room' 
     33        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     34        extra = { 
     35            'evalkey':'1153994494.48', 
     36            'hashkey': 'AE89E6D9461FD8A28EAF5C35FA15047F', 
     37            'subject': 'testing', 
     38            'body_text': 'Text in Comment', 
     39            'discussion_reply:method': 'Save'} 
    2640 
     41        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     42        patt = re.compile(".*?Your\+comment\+awaits\+moderation") 
     43        match_obj = patt.match(response) 
     44        self.assert_(match_obj) 
     45 
     46    def test_editform_with_wrong_captcha(self): 
     47        parameters = 'form.submitted=1&Creator=test_user&key=cat' 
     48        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     49        extra = { 
     50            'evalkey':'1153994494.48', 
     51            'hashkey': 'AE89E6D9461FD8A28EAF5C35FA15047F', 
     52            'subject': 'testing', 
     53            'body_text': 'Text in Comment', 
     54            'discussion_reply:method': 'Save'} 
     55 
     56        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     57        patt = re.compile("Please re enter validation code") 
     58        match_obj = patt.search(response) 
     59 
     60        self.assert_(match_obj) 
     61 
     62    def test_editform_with_empty_key(self): 
     63        parameters = 'form.submitted=1&Creator=test_user' 
     64        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     65        extra = { 
     66            'evalkey':'1153994494.48', 
     67            'hashkey': 'AE89E6D9461FD8A28EAF5C35FA15047F', 
     68            'subject': 'testing', 
     69            'body_text': 'Text in Comment', 
     70            'discussion_reply:method': 'Save'} 
     71 
     72        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     73        patt = re.compile("Please re enter validation code") 
     74        match_obj = patt.search(response) 
     75 
     76        self.assert_(match_obj) 
     77 
     78class TestQPlonePILCaptchas(PloneTestCase.FunctionalTestCase): 
     79 
     80    def afterSetUp(self): 
     81        self.addProduct('qPloneComments') 
     82        self.addProduct('qPloneCaptchas') 
     83        self.loginAsPortalOwner() 
     84        self.portal.portal_properties['qPloneCaptchas'].current_lib = 'PIL' 
     85        self.portal.invokeFactory('Document', 'index_html') 
     86        self.portal['index_html'].allow_discussion = True 
     87        self.absolute_url = self.portal['index_html'].absolute_url_path() 
     88 
     89    def test_editform_with_right_captcha(self): 
     90        parameters = 'form.submitted=1&Creator=test_user&key=man' 
     91        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     92        extra = { 
     93            'evalkey':'1153996082.6', 
     94            'hashkey': '8545A37C98C09756B24626430812B807', 
     95            'subject': 'testing', 
     96            'body_text': 'Text in Comment', 
     97            'discussion_reply:method': 'Save'} 
     98 
     99        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     100        patt = re.compile(".*?Your\+comment\+awaits\+moderation") 
     101        match_obj = patt.match(response) 
     102        self.assert_(match_obj) 
     103 
     104    def test_editform_with_wrong_captcha(self): 
     105        parameters = 'form.submitted=1&Creator=test_user&key=cat' 
     106        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     107        extra = { 
     108            'evalkey':'1153996082.6', 
     109            'hashkey': '8545A37C98C09756B24626430812B807', 
     110            'subject': 'testing', 
     111            'body_text': 'Text in Comment', 
     112            'discussion_reply:method': 'Save'} 
     113 
     114        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     115        patt = re.compile("Please re enter validation code") 
     116        match_obj = patt.search(response) 
     117 
     118        self.assert_(match_obj) 
     119 
     120    def test_editform_with_empty_key(self): 
     121        parameters = 'form.submitted=1&Creator=test_user' 
     122        path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
     123        extra = { 
     124            'evalkey':'1153996082.6', 
     125            'hashkey': '8545A37C98C09756B24626430812B807', 
     126            'subject': 'testing', 
     127            'body_text': 'Text in Comment', 
     128            'discussion_reply:method': 'Save'} 
     129 
     130        response = self.publish(path, extra=extra, request_method='GET').getBody() 
     131        patt = re.compile("Please re enter validation code") 
     132        match_obj = patt.search(response) 
     133 
     134        self.assert_(match_obj) 
    27135def test_suite(): 
    28136    from unittest import TestSuite, makeSuite 
    29137    suite = TestSuite() 
    30     suite.addTest(makeSuite(TestQPloneCaptchas)) 
     138    suite.addTest(makeSuite(TestQPloneStaticCaptchas)) 
     139    suite.addTest(makeSuite(TestQPlonePILCaptchas)) 
    31140    return suite 
    32141 
    33142if __name__ == '__main__': 
    34143    framework() 
    35