Ignore:
Timestamp:
Mar 11, 2010 3:05:30 PM (14 years ago)
Author:
mylan
Message:

#161: Clarify afterSetUp and dependents for testResponse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testResponse.py

    r1888 r1889  
    33from base import * 
    44 
    5 CUSTOM_METATAGS = [{'meta_name'    : 'metatag1', 
    6                     'meta_content' : 'metatag1value'}, 
    7                    {'meta_name'    : 'metatag2', 
    8                     'meta_content' : 'metatag2value'}, 
    9                    {'meta_name'    : 'metatag3', 
    10                     'meta_content' : ''} 
    11                   ] 
     5CUSTOM_METATAGS = [ 
     6   {'meta_name': 'metatag1', 'meta_content': 'metatag1value'}, 
     7   {'meta_name': 'metatag2', 'meta_content': 'metatag2value'}, 
     8   {'meta_name': 'metatag3', 'meta_content': ''} 
     9] 
    1210 
    13 VIEW_METATAGS = ['DC.creator', 'DC.format', 'DC.date.modified', 
    14     'DC.date.created', 'DC.type', 'DC.distribution', 'description', 
    15     'keywords', 'robots', 'distribution'] 
     11VIEW_METATAGS = [ 
     12    'DC.creator', 'DC.format', 'DC.date.modified', 
     13    'DC.date.created', 'DC.type', 'DC.distribution', 
     14    'description', 'keywords', 'robots', 'distribution' 
     15] 
    1616 
    17 GLOBAL_CUSTOM_METATAGS = { 
    18     'default_custom_metatags':'metatag1|global_metatag1value\nmetatag4|global_metatag4value'} 
     17FORM_DATA = { 
     18    'seo_robots': 'ALL', 
     19    'form.submitted:int': 1, 
     20    'seo_title': 'hello world', 
     21    'seo_title_override:int': 1, 
     22    'seo_robots_override:int': 1, 
     23    'seo_distribution': 'Global', 
     24    'seo_keywords_override:int': 1, 
     25    'seo_keywords:list': 'keyword1', 
     26    'seo_description_override:int': 1, 
     27    'seo_html_comment': 'no comments', 
     28    'seo_html_comment_override:int': 1, 
     29    'seo_distribution_override:int': 1, 
     30    'seo_custommetatags_override:int': 1, 
     31    'seo_description': 'it is description, test keyword1', 
     32} 
    1933 
    2034class TestResponse(FunctionalTestCase): 
     
    2337        self.sp = self.portal.portal_properties.seo_properties 
    2438        self.pu = self.portal.plone_utils 
    25         self.basic_auth = 'portal_manager:secret' 
     39        self.wf = self.portal.portal_workflow 
    2640 
    27         uf = self.app.acl_users 
    28         uf.userFolderAddUser('portal_manager', 'secret', ['Manager'], []) 
    29         user = uf.getUserById('portal_manager') 
    30         if not hasattr(user, 'aq_base'): 
    31             user = user.__of__(uf) 
    32         newSecurityManager(None, user) 
     41        self.basic_auth = ':'.join((portal_owner,default_password)) 
     42        self.loginAsPortalOwner() 
    3343 
    34         '''Preparation for functional testing''' 
     44        # Preparation for functional testing' 
     45        # create document for test 
    3546        my_doc = self.portal.invokeFactory('Document', id='my_doc') 
    3647        my_doc = self.portal['my_doc'] 
    37         self.sp.manage_changeProperties(**GLOBAL_CUSTOM_METATAGS) 
    38         self.sp.manage_changeProperties(settings_use_keywords_sg=3, settings_use_keywords_lg=2) 
    39         abs_path = "/%s" % my_doc.absolute_url(1) 
    40         self.form_data = {'seo_description': 'it is description, test keyword1', 'seo_keywords_override:int': 1, 'seo_custommetatags_override:int': 1, 
    41                         'seo_robots_override:int': 1, 'seo_robots': 'ALL', 'seo_description_override:int': 1, 
    42                         'seo_keywords:list': 'keyword1', 'seo_html_comment': 'no comments', 
    43                         'seo_title_override:int': 1, 'seo_title': 'hello world', 'seo_html_comment_override:int': 1, 
    44                         'seo_distribution_override:int': 1, 'seo_distribution': 'Global', 'form.submitted:int': 1} 
     48        self.abs_path = "/%s" % my_doc.absolute_url(1) 
     49        # prepare seo context form data 
     50        self.sp.manage_changeProperties( 
     51            default_custom_metatags = 'metatag1|global_metatag1value\n' \ 
     52                                      'metatag4|global_metatag4value') 
    4553        st = '' 
    4654        for d in CUSTOM_METATAGS: 
    47             st += '&seo_custommetatags.meta_name:records=%s&seo_custommetatags.meta_content:records=%s' % (d['meta_name'],d['meta_content']) 
    48         self.publish(path=abs_path+'/@@seo-context-properties', basic=self.basic_auth, request_method='POST', stdin=StringIO(urllib.urlencode(self.form_data)+st)) 
    49         #self.publish(abs_path+'/@@seo-context-properties?%s' % urllib.urlencode(self.form_data), self.basic_auth) 
     55            st += '&seo_custommetatags.meta_name:records=%s' % d['meta_name'] 
     56            st += '&seo_custommetatags.meta_content:records=%s' % d['meta_content'] 
     57        # update seo properties for the test document and publish it 
     58        self.publish(path=self.abs_path+'/@@seo-context-properties', 
     59                     basic=self.basic_auth, request_method='POST', 
     60                     stdin=StringIO(urllib.urlencode(FORM_DATA)+st)) 
     61        self.wf.doActionFor(my_doc, 'publish') 
     62        # get html view of test document 
     63        self.html = self.publish(self.abs_path, self.basic_auth).getBody() 
    5064 
    51         wf_tool = self.portal.portal_workflow 
    52         wf_tool.doActionFor(my_doc, 'publish') 
    53  
    54         self.abs_path = abs_path 
    55         self.my_doc = my_doc 
    56         self.html = self.publish(abs_path, self.basic_auth).getBody() 
    57  
    58         # now setup page with title equal to plone site's title 
    59         my_doc2 = self.portal.invokeFactory('Document', id='my_doc2') 
    60         my_doc2 = self.portal['my_doc2'] 
    61         my_doc2.update(title=self.portal.Title()) 
    62         wf_tool.doActionFor(my_doc2, 'publish') 
    63         abs_path2 = "/%s" % my_doc2.absolute_url(1) 
    64         self.html2 = self.publish(abs_path2, self.basic_auth).getBody() 
    6565 
    6666    def testTitle(self): 
     
    7272        then there should be no concatenation of both titles. Only one should be displayed. 
    7373        """ 
    74         m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), self.html2, re.S|re.M) 
     74        # setup page with title equal to plone site's title 
     75        my_doc2 = self.portal.invokeFactory('Document', id='my_doc2', title=self.portal.Title()) 
     76        my_doc2 = self.portal['my_doc2'] 
     77        self.wf.doActionFor(my_doc2, 'publish') 
     78        html2 = self.publish('/'+my_doc2.absolute_url(1), self.basic_auth).getBody() 
     79 
     80        m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), html2, re.S|re.M) 
    7581        self.assert_(m, 'Title is not set correctly, perhaps it is duplicated with plone site title') 
    7682 
     
    121127    def testDeleteCustomMetaTags(self): 
    122128        self.sp.manage_changeProperties(**{'default_custom_metatags':'metatag1|global_metatag1value'}) 
    123         my_doc = self.my_doc 
    124         self.form_data = {'seo_custommetatags': CUSTOM_METATAGS,  'seo_custommetatags_override:int': 0, 'form.submitted:int': 1} 
    125         self.publish(path=self.abs_path+'/@@seo-context-properties', basic=self.basic_auth, request_method='POST', stdin=StringIO(urllib.urlencode(self.form_data))) 
     129        form_data = {'seo_custommetatags': CUSTOM_METATAGS, 
     130                     'seo_custommetatags_override:int': 0, 
     131                     'form.submitted:int': 1} 
     132        self.publish(path=self.abs_path+'/@@seo-context-properties', 
     133                     basic=self.basic_auth, request_method='POST', 
     134                     stdin=StringIO(urllib.urlencode(form_data))) 
    126135        self.html = self.publish(self.abs_path, self.basic_auth).getBody() 
    127136        m = re.match('.*(<meta\s+(?:(?:name="metatag4"\s*)|(?:content="global_metatag4value"\s*)){2}/>)', self.html, re.S|re.M) 
Note: See TracChangeset for help on using the changeset viewer.