Ignore:
Timestamp:
Sep 18, 2009 5:29:41 PM (15 years ago)
Author:
liebster
Message:

Added metatags order feature, which is managed by metatags_order property of of configlet

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testQSEOptimizer.py

    r1269 r1313  
    2828                    'meta_content' : ''} 
    2929                  ] 
     30view_metatags = ['DC.creator', 'DC.format', 'DC.date.modified', 'DC.date.created', 'DC.type', 
     31                   'DC.distribution', 'description', 'keywords', 'robots', 'distribution'] 
    3032 
    3133global_custom_metatags = {'default_custom_metatags':'metatag1|global_metatag1value\nmetatag4|global_metatag4value'} 
     
    215217    def testDescription(self): 
    216218        m = re.match('.*<meta name="description" content="it is description" />', self.html, re.S|re.M) 
     219        if not m: 
     220            m = re.match('.*<meta content="it is description" name="description" />', self.html, re.S|re.M) 
    217221        self.assert_(m, 'Description not set in') 
    218222 
    219223    def testKeywords(self): 
    220224        m = re.match('.*<meta name="keywords" content="my1|key2" />', self.html, re.S|re.M) 
     225        if not m: 
     226             m = re.match('.*<meta content="my1|key2" name="keywords" />', self.html, re.S|re.M) 
    221227        self.assert_(m, 'Keywords not set in') 
    222228 
    223229    def testRobots(self): 
    224230        m = re.match('.*<meta name="robots" content="ALL" />', self.html, re.S|re.M) 
     231        if not m: 
     232            m = re.match('.*<meta content="ALL" name="robots" />', self.html, re.S|re.M) 
    225233        self.assert_(m, 'Robots not set in') 
    226234 
    227235    def testDistribution(self): 
    228236        m = re.match('.*<meta name="distribution" content="Global" />', self.html, re.S|re.M) 
     237        if not m: 
     238            m = re.match('.*<meta content="Global" name="distribution" />', self.html, re.S|re.M) 
    229239        self.assert_(m, 'Distribution not set in') 
    230240 
     
    234244 
    235245    def testTagsOrder(self): 
    236         m = re.search('name="description".+name="keywords"', self.html, re.S|re.M) 
     246        mtop = self.sp.getProperty('metatags_order') 
     247        metatags_order = [t.split(' ')[0] for t in mtop if len(t.split(' '))==2 and t.split(' ')[0] in view_metatags] 
     248        m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
    237249        self.assert_(m, "Meta tags order not supported.") 
     250 
     251        mtop = list(mtop) 
     252        mtop.reverse() 
     253        metatags_order = [t.split(' ')[0] for t in mtop if len(t.split(' '))==2 and t.split(' ')[0] in view_metatags] 
     254        m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
     255        self.assertFalse(m, "Meta tags order not supported.") 
     256 
     257        self.sp.manage_changeProperties(**{'metatags_order':tuple(mtop)}) 
     258        html = self.publish(self.abs_path, self.basic_auth).getBody() 
     259        m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 
     260        self.assertFalse(m, "Meta tags order not supported.") 
     261 
     262        m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), html, re.S|re.M) 
     263        self.assert_(m, "Meta tags order not supported.") 
     264 
    238265 
    239266    def testCustomMetaTags(self): 
    240267        for tag in custom_metatags: 
    241268            m = re.search('<meta name="%(meta_name)s" content="%(meta_content)s" />' % tag, self.html, re.S|re.M) 
     269            if not m: 
     270                m = re.search('<meta content="%(meta_content)s" name="%(meta_name)s" />' % tag, self.html, re.S|re.M) 
    242271            if tag['meta_content']: 
    243272                self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) 
     
    245274                self.assert_(not m, "Meta tag %s has no content, but is present in the page." % tag['meta_name']) 
    246275        m = re.search('<meta name="metatag4" content="global_metatag4value" />' , self.html, re.S|re.M) 
     276        if not m: 
     277            m = re.search('<meta content="global_metatag4value" name="metatag4" />' , self.html, re.S|re.M) 
    247278        self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') 
    248279 
     
    253284        html = self.publish(self.abs_path, self.basic_auth).getBody() 
    254285        m = re.search('<meta name="metatag4" content="global_metatag4value" />' , html, re.S|re.M) 
     286        if not m: 
     287            m = re.search('<meta content="global_metatag4value" name="metatag4" />' , html, re.S|re.M) 
    255288        self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 
    256289        m = re.search('<meta name="metatag1" content="global_metatag1value" />' , html, re.S|re.M) 
     290        if not m: 
     291            m = re.search('<meta content="global_metatag1value" name="metatag1" />' , html, re.S|re.M) 
    257292        self.assert_(m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 
    258293 
     
    311346        self.my_doc.manage_addProperty('qSEO_keywords', ('foo',), 'lines') 
    312347        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    313         m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) 
     348        m = re.match('.*<meta\ content="foo"\ name="keywords"\ />', self.html, re.S|re.M) 
     349        if not m: 
     350            m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) 
    314351        self.assert_(m, "No 'foo' keyword find") 
    315352 
     
    317354        self.my_doc.manage_addProperty('qSEO_keywords', ('foo', 'bar'), 'lines') 
    318355        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    319         m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) 
     356        m = re.match('.*<meta\ content="foo, bar"\ name="keywords"\ />', self.html, re.S|re.M) 
     357        if not m: 
     358            m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) 
    320359        self.assert_(m, "No 'foo, bar' keyword find") 
    321360 
     
    329368        self.sp.additional_keywords = ('foo',) 
    330369        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    331         m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) 
     370        m = re.match('.*<meta\ content="foo"\ name="keywords"\ />', self.html, re.S|re.M) 
     371        if not m: 
     372            m = re.match('.*<meta\ name="keywords"\ content="foo"\ />', self.html, re.S|re.M) 
    332373        self.assert_(m, "No 'foo' keyword find") 
    333374 
     
    336377        self.sp.additional_keywords = ('foo', 'bar') 
    337378        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    338         m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) 
     379        m = re.match('.*<meta\ content="foo, bar"\ name="keywords"\ />', self.html, re.S|re.M) 
     380        if not m: 
     381            m = re.match('.*<meta\ name="keywords"\ content="foo, bar"\ />', self.html, re.S|re.M) 
    339382        self.assert_(m, "No 'foo, bar' keyword find") 
    340383 
     
    344387        self.my_doc.manage_addProperty('qSEO_keywords', ('baz',), 'lines') 
    345388        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    346         m = re.match('.*<meta\ name="keywords"\ content="baz,\ foo,\ bar"\ />', self.html, re.S|re.M) 
     389        m = re.match('.*<meta\ content="baz,\ foo,\ bar"\ name="keywords"\ />', self.html, re.S|re.M) 
     390        if not m: 
     391            m = re.match('.*<meta\ name="keywords"\ content="baz,\ foo,\ bar"\ />', self.html, re.S|re.M) 
    347392        self.assert_(m, "No 'foo, bar, baz' keyword find") 
    348393 
     
    382427        self.my_doc.qseo_properties_edit() 
    383428        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    384  
    385         m = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) or re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M) 
     429        m1 = re.match('.*<meta\ name="DC.format"\ content=".*?"\ />', self.html, re.S|re.M) 
     430        if not m1: 
     431            m1 = re.match('.*<meta content=".*?" name="DC.format" />', self.html, re.S|re.M) 
     432        m2 = re.match('.*<meta name="DC.distribution" content=".*?" />', self.html, re.S|re.M) 
     433        if not m2: 
     434            m2 = re.match('.*<meta content=".*?" name="DC.distribution" />', self.html, re.S|re.M) 
     435        m = m1 or m2 
    386436        self.assert_(not m, 'DC meta tags avaliable when exposeDCMetaTags=False') 
    387437 
     
    390440        self.my_doc.qseo_properties_edit() 
    391441        self.html = str(self.publish(self.portal.id+'/my_doc', self.basic_auth)) 
    392         m = re.match('.*<meta\ name="DC.format"\ content=".*?"\ />', self.html, re.S|re.M) and re.match('.*<meta\ name="DC.type"\ content=".*?"\ />', self.html, re.S|re.M) 
     442        m1 = re.match('.*<meta\ content=".*?"\ name="DC.format"\ />', self.html, re.S|re.M) 
     443        if not m1: 
     444            m1 = re.match('.*<meta\ name="DC.format"\ content=".*?"\ />', self.html, re.S|re.M) 
     445        m2 = re.match('.*<meta\ content=".*?"\ name="DC.type"\ />', self.html, re.S|re.M) 
     446        if not m2: 
     447            m2 = re.match('.*<meta\ name="DC.type"\ content=".*?"\ />', self.html, re.S|re.M) 
     448        m = m1 and m2 
    393449        self.assert_(m, 'DC meta tags not avaliable when createManager=True') 
    394450 
Note: See TracChangeset for help on using the changeset viewer.