Changeset 1997 in products


Ignore:
Timestamp:
Mar 24, 2010 4:53:38 PM (14 years ago)
Author:
mylan
Message:

#175: Reorganize tests structure

Location:
quintagroup.plonecaptchas/branches/split2packs/quintagroup/plonecaptchas/tests
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • quintagroup.plonecaptchas/branches/split2packs/quintagroup/plonecaptchas/tests/testInstallation.py

    r1994 r1997  
    1 import unittest 
    2 import os 
    3 import sys 
    4 import re 
     1from base import * 
    52 
    6 from Products.Five import zcml 
    7 from Products.Five import fiveconfigure 
    8  
    9 from Testing import ZopeTestCase as ztc 
    10 from Products.PloneTestCase import PloneTestCase as ptc 
    11 from Products.PloneTestCase.layer import onsetup 
    12  
    13 from AccessControl.SecurityManagement import newSecurityManager 
    14 from Products.CMFCore.utils import getToolByName 
    15  
    16 from quintagroup.plonecaptchas.utils import getWord, decrypt, parseKey 
    17 from quintagroup.plonecaptchas.config import * 
    18  
    19 @onsetup 
    20 def setup_product(): 
    21     fiveconfigure.debug_mode = True 
    22     import quintagroup.plonecaptchas 
    23     zcml.load_config('configure.zcml', quintagroup.plonecaptchas) 
    24     fiveconfigure.debug_mode = False 
    25     ztc.installPackage('quintagroup.plonecaptchas') 
    26  
    27 setup_product() 
    28 ptc.setupPloneSite() 
    29  
    30 class TestCaptchaWidget(ptc.FunctionalTestCase): 
    31  
    32     def afterSetUp(self): 
    33         self.loginAsPortalOwner() 
    34         self.addProduct(PRODUCT_NAME) 
    35         self.portal.invokeFactory('Document', 'index_html') 
    36         self.portal['index_html'].allowDiscussion(True) 
    37         self.absolute_url = self.portal['index_html'].absolute_url_path() 
    38  
    39         self.basic_auth = 'portal_manager:secret' 
    40         uf = self.app.acl_users 
    41         uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) 
    42         user = uf.getUserById('portal_manager') 
    43         if not hasattr(user, 'aq_base'): 
    44             user = user.__of__(uf) 
    45         newSecurityManager(None, user) 
    46         self.captcha_key = self.portal.captcha_key 
    47  
    48     def testImage(self): 
    49         path = '%s/discussion_reply_form' % self.absolute_url 
    50         response = self.publish(path, self.basic_auth, request_method='GET').getBody() 
    51         patt = re.compile('\s+src="%s(/getCaptchaImage/[0-9a-fA-F]+)"' % self.portal.absolute_url()) 
    52         match_obj = patt.search(response) 
    53         img_url = match_obj.group(1) 
    54         content_type = self.publish('/plone' + img_url, self.basic_auth).getHeader('content-type') 
    55         self.assert_(content_type.startswith('image')) 
    56  
    57     def testSubmitRightCaptcha(self): 
    58         hashkey = self.portal.getCaptcha() 
    59         key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])) 
    60         parameters = 'form.submitted=1&Creator=test_user&key=%s' % key 
    61         path = '%s/discussion_reply_form?%s' % (self.absolute_url, parameters) 
    62         extra = {'hashkey': hashkey, 
    63                  'subject': 'testing', 
    64                  'body_text': 'Text in Comment', 
    65                  'discussion_reply:method': 'Save'} 
    66         response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 
    67         patt = re.compile("Please re\-enter validation code") 
    68         match_obj = patt.match(response) 
    69         self.assert_(not match_obj) 
    70  
    71     def testSubmitWrongCaptcha(self): 
    72         hashkey = self.portal.getCaptcha() 
    73         parameters = 'form.submitted=1&Creator=test_user&key=fdfgh' 
    74         path = '%s/discussion_reply_form?%s' % (self.absolute_url, parameters) 
    75         extra = {'hashkey': hashkey, 
    76                  'subject': 'testing', 
    77                  'body_text': 'Text in Comment', 
    78                  'discussion_reply:method': 'Save'} 
    79         response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 
    80         patt = re.compile("Please re\-enter validation code") 
    81         match_obj = patt.search(response) 
    82         self.assert_(match_obj) 
    83  
    84     def testSubmitRightCaptchaTwice(self): 
    85         hashkey = self.portal.getCaptcha() 
    86         key = getWord(int(parseKey(decrypt(self.captcha_key, hashkey))['key'])) 
    87         parameters = 'form.submitted=1&Creator=test_user&key=%s'%key 
    88         path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
    89         extra = {'hashkey': hashkey, 
    90                  'subject': 'testing', 
    91                  'body_text': 'Text in Comment', 
    92                  'discussion_reply:method': 'Save'} 
    93         self.publish(path, self.basic_auth, extra=extra, request_method='GET') 
    94         response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 
    95         patt = re.compile(".*?Comment\+added") 
    96         match_obj = patt.match(response) 
    97         self.assert_(not match_obj) 
    98  
    99 class TestInstallation(ptc.FunctionalTestCase): 
     3class TestInstallation(TestCase): 
    1004 
    1015    def afterSetUp(self): 
     
    16569        self.assert_(not self.portal.hasProperty(CAPTCHA_KEY)) 
    16670 
     71 
    16772def test_suite(): 
    16873    suite = unittest.TestSuite() 
    169     suite.addTest(unittest.makeSuite(TestCaptchaWidget)) 
    17074    suite.addTest(unittest.makeSuite(TestInstallation)) 
    17175    return suite 
Note: See TracChangeset for help on using the changeset viewer.