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

#161: Clarify and simplify testResponse tests

File:
1 edited

Legend:

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

    r1889 r1890  
    1515] 
    1616 
    17 FORM_DATA = { 
     17FORM = { 
    1818    'seo_robots': 'ALL', 
    1919    'form.submitted:int': 1, 
     
    3131    'seo_description': 'it is description, test keyword1', 
    3232} 
     33 
     34METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="%s"\s*)){2}/>)' 
    3335 
    3436class TestResponse(FunctionalTestCase): 
     
    5860        self.publish(path=self.abs_path+'/@@seo-context-properties', 
    5961                     basic=self.basic_auth, request_method='POST', 
    60                      stdin=StringIO(urllib.urlencode(FORM_DATA)+st)) 
     62                     stdin=StringIO(urllib.urlencode(FORM)+st)) 
    6163        self.wf.doActionFor(my_doc, 'publish') 
    6264        # get html view of test document 
     
    7375        """ 
    7476        # setup page with title equal to plone site's title 
    75         my_doc2 = self.portal.invokeFactory('Document', id='my_doc2', title=self.portal.Title()) 
     77        my_doc2 = self.portal.invokeFactory('Document', id='my_doc2', 
     78                                            title=self.portal.Title()) 
    7679        my_doc2 = self.portal['my_doc2'] 
    7780        self.wf.doActionFor(my_doc2, 'publish') 
     
    8285 
    8386    def testDescription(self): 
    84         m = re.match('.*(<meta\s+(?:(?:name="description"\s*)|(?:content="it is description, test keyword1"\s*)){2}/>)', self.html, re.S|re.M) 
     87        m = re.match(METATAG % ("description", FORM['seo_description']), self.html, re.S|re.M) 
    8588        self.assert_(m, 'Description not set in') 
    8689 
    8790    def testRobots(self): 
    88         m = re.match('.*(<meta\s+(?:(?:name="robots"\s*)|(?:content="ALL"\s*)){2}/>)', self.html, re.S|re.M) 
     91        m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, re.S|re.M) 
    8992        self.assert_(m, 'Robots not set in') 
    9093 
    9194    def testDistribution(self): 
    92         m = re.match('.*(<meta\s+(?:(?:name="distribution"\s*)|(?:content="Global"\s*)){2}/>)', self.html, re.S|re.M) 
     95        m = re.match(METATAG % ("distribution", FORM['seo_distribution']), self.html, re.S|re.M) 
    9396        self.assert_(m, 'Distribution not set in') 
    9497 
     
    98101 
    99102    def testTagsOrder(self): 
     103        def is_match(html, mtorder): 
     104            return re.search('.*'.join(['<meta.*name="%s".*/>' %t \ 
     105                                        for t in mtorder]), html, re.S|re.M) 
     106 
    100107        metatags_order = [t for t in self.sp.getProperty('metatags_order') if t in VIEW_METATAGS] 
    101         m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
    102         self.assert_(m, "Meta tags order not supported.") 
     108        self.assert_(is_match(self.html, metatags_order), "Meta tags order not supported.") 
    103109 
    104110        metatags_order.reverse() 
    105         m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
    106         self.assertFalse(m, "Meta tags order not supported.") 
     111        self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 
    107112 
    108         self.sp.manage_changeProperties(**{'metatags_order':metatags_order}) 
     113        self.sp.manage_changeProperties(metatags_order = metatags_order) 
     114        self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 
     115 
    109116        html = self.publish(self.abs_path, self.basic_auth).getBody() 
    110         m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
    111         self.assertFalse(m, "Meta tags order not supported.") 
    112  
    113         m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), html, re.S|re.M) 
    114         self.assert_(m, "Meta tags order not supported.") 
     117        self.assert_(is_match(html, metatags_order), "Meta tags order not supported.") 
    115118 
    116119 
    117120    def testCustomMetaTags(self): 
    118121        for tag in CUSTOM_METATAGS: 
    119             m = re.match('.*(<meta\s+(?:(?:name="%(meta_name)s"\s*)|(?:content="%(meta_content)s"\s*)){2}/>)' % tag, self.html, re.S|re.M) 
     122            m = re.match(METATAG % (tag['meta_name'], tag['meta_content']), 
     123                         self.html, re.S|re.M) 
    120124            if tag['meta_content']: 
    121125                self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) 
    122126            else: 
    123                 self.assert_(not m, "Meta tag %s has no content, but is present in the page." % tag['meta_name']) 
    124         m = re.match('.*(<meta\s+(?:(?:name="metatag4"\s*)|(?:content="global_metatag4value"\s*)){2}/>)', self.html, re.S|re.M) 
     127                self.assert_(not m, "Meta tag %s has no content, but is present:" \ 
     128                                 " in the page." % tag['meta_name']) 
     129 
     130        m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, re.S|re.M) 
    125131        self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') 
    126132 
    127133    def testDeleteCustomMetaTags(self): 
    128         self.sp.manage_changeProperties(**{'default_custom_metatags':'metatag1|global_metatag1value'}) 
     134        self.sp.manage_changeProperties( 
     135            default_custom_metatags = 'metatag1|global_metatag1value') 
    129136        form_data = {'seo_custommetatags': CUSTOM_METATAGS, 
    130137                     'seo_custommetatags_override:int': 0, 
     
    133140                     basic=self.basic_auth, request_method='POST', 
    134141                     stdin=StringIO(urllib.urlencode(form_data))) 
    135         self.html = self.publish(self.abs_path, self.basic_auth).getBody() 
    136         m = re.match('.*(<meta\s+(?:(?:name="metatag4"\s*)|(?:content="global_metatag4value"\s*)){2}/>)', self.html, re.S|re.M) 
     142        html = self.publish(self.abs_path, self.basic_auth).getBody() 
     143 
     144        m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, re.S|re.M) 
    137145        self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 
    138         m = re.match('.*(<meta\s+(?:(?:name="metatag1"\s*)|(?:content="global_metatag1value"\s*)){2}/>)', self.html, re.S|re.M) 
     146 
     147        m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, re.S|re.M) 
    139148        self.assert_(m, "Global custom meta tag %s not applied." % 'metatag1') 
    140149 
Note: See TracChangeset for help on using the changeset viewer.