Ignore:
Timestamp:
Apr 20, 2011 8:20:36 AM (13 years ago)
Author:
zidane
Message:

fixes pep8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSitemaps.py

    r3002 r3152  
    1111 
    1212from quintagroup.plonegooglesitemaps.browser.sitemapview import SitemapView 
    13 from quintagroup.plonegooglesitemaps.browser.newssitemapview import NewsSitemapView 
    14 from quintagroup.plonegooglesitemaps.browser.mobilesitemapview import MobileSitemapView 
     13from quintagroup.plonegooglesitemaps.browser.newssitemapview \ 
     14    import NewsSitemapView 
     15from quintagroup.plonegooglesitemaps.browser.mobilesitemapview \ 
     16    import MobileSitemapView 
    1517 
    1618 
     
    1921    def afterSetUp(self): 
    2022        super(TestSitemapType, self).afterSetUp() 
    21         self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 
     23        self.contentSM = _createObjectByType('Sitemap', self.portal, 
     24                                             id='google-sitemaps') 
    2225 
    2326    def testFields(self): 
    24         field_ids = map(lambda x:x.getName(), self.contentSM.Schema().fields()) 
     27        field_ids = map(lambda x: x.getName(), 
     28                        self.contentSM.Schema().fields()) 
    2529        # test old Sitemap settings fields 
    2630        self.assert_('id' in field_ids) 
     
    3438 
    3539    def testSitemapTypes(self): 
    36         sitemap_types = self.contentSM.getField('sitemapType').Vocabulary().keys() 
     40        sm_vocabulary = self.contentSM.getField('sitemapType').Vocabulary() 
     41        sitemap_types = sm_vocabulary.keys() 
    3742        self.assert_('content' in sitemap_types) 
    3843        self.assert_('mobile' in sitemap_types) 
     
    4045 
    4146    def testAutoSetLayout(self): 
    42         response = self.publish('/%s/createObject?type_name=Sitemap' % \ 
    43                                 self.portal.absolute_url(1), basic=self.auth) 
     47        response = self.publish('/%s/createObject?type_name=Sitemap' \ 
     48                                % self.portal.absolute_url(1), basic=self.auth) 
    4449        location = response.getHeader('location') 
    45         newurl = location[location.find('/'+self.portal.absolute_url(1)):] 
     50        newurl = location[location.find('/' + self.portal.absolute_url(1)):] 
    4651 
    4752        msm_id = 'mobile_sitemap' 
    4853        form = {'id': msm_id, 
    49                 'sitemapType':'mobile', 
    50                 'portalTypes':['Document',], 
    51                 'states':['published'], 
    52                 'form_submit':'Save', 
    53                 'form.submitted':1, 
     54                'sitemapType': 'mobile', 
     55                'portalTypes': ['Document', ], 
     56                'states': ['published'], 
     57                'form_submit': 'Save', 
     58                'form.submitted': 1, 
    5459                } 
    5560        post_data = StringIO(urlencode(form)) 
    56         response = self.publish(newurl, request_method='POST', stdin=post_data, basic=self.auth) 
     61        response = self.publish(newurl, request_method='POST', stdin=post_data, 
     62                                basic=self.auth) 
    5763        msitemap = getattr(self.portal, msm_id) 
    5864 
     
    6470 
    6571        self.contentSM.setPingTransitions(('plone_workflow#publish',)) 
    66         self.assertEqual(self.contentSM.getPingTransitions(), ('plone_workflow#publish',)) 
    67         self.assert_(ping_googlesitemap in pwf.scripts.keys(),"Not add wf script") 
     72        self.assertEqual(self.contentSM.getPingTransitions(), 
     73                         ('plone_workflow#publish',)) 
     74        self.assert_(ping_googlesitemap in pwf.scripts.keys(), 
     75                     "Not add wf script") 
    6876 
    6977    def testWorkflowStates(self): 
     
    7583        wftrans = self.contentSM.getWorkflowTransitions() 
    7684        self.assertEqual(isinstance(wftrans, atapi.DisplayList), True) 
    77         self.assertEqual("simple_publication_workflow#publish" in wftrans.keys(), True) 
     85        self.assertEqual("simple_publication_workflow#publish" in \ 
     86                         wftrans.keys(), True) 
    7887 
    7988    def testSettingBlackout(self): 
    80         bolist = ["path:./el1  ","   ",""," id:index.html  ","index_html"] 
    81         expect = ("path:./el1","id:index.html","index_html") 
     89        bolist = ["path:./el1  ", "   ", "", " id:index.html  ", "index_html"] 
     90        expect = ("path:./el1", "id:index.html", "index_html") 
    8291        self.contentSM.edit(blackout_list=bolist) 
    8392        value = self.contentSM.getBlackout_list() 
     
    9099    def afterSetUp(self): 
    91100        super(TestSettings, self).afterSetUp() 
    92         self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] 
    93         self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 
    94         self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' 
     101        gsm_properties = 'googlesitemap_properties' 
     102        self.gsm_props = self.portal.portal_properties[gsm_properties] 
     103        self.contentSM = _createObjectByType('Sitemap', self.portal, 
     104                                             id='google-sitemaps') 
     105        self.sitemapUrl = '/' + self.portal.absolute_url(1) + \ 
     106                          '/google-sitemaps' 
    95107        # Add testing document to portal 
    96108        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc') 
     
    141153        self.assert_(not hasURL(sitemap, self.portal.absolute_url())) 
    142154 
    143         regexp = "s/\/%s//"%self.my_doc.getId() 
     155        regexp = "s/\/%s//" % self.my_doc.getId() 
    144156        self.contentSM.setReg_exp([regexp]) 
    145157 
     
    163175    def afterSetUp(self): 
    164176        super(TestPinging, self).afterSetUp() 
    165         self.workflow.setChainForPortalTypes(pt_names=('News Item','Document'), 
    166                                              chain="simple_publication_workflow") 
    167         self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] 
     177        self.workflow.setChainForPortalTypes(pt_names=('News Item', 
     178                 'Document'), chain="simple_publication_workflow") 
     179        gsm_properties = 'googlesitemap_properties' 
     180        self.gsm_props = self.portal.portal_properties[gsm_properties] 
    168181        # Add sitemaps 
    169         self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 
    170         self.contentSM.setPingTransitions(('simple_publication_workflow#publish',)) 
    171         self.newsSM = _createObjectByType('Sitemap', self.portal, id='news-sitemaps') 
    172         self.newsSM.setPortalTypes(('News Item','Document')) 
    173         self.newsSM.setPingTransitions(('simple_publication_workflow#publish',)) 
    174         self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' 
     182        self.contentSM = _createObjectByType('Sitemap', self.portal, 
     183                                             id='google-sitemaps') 
     184        spw_publish = 'simple_publication_workflow#publish' 
     185        self.contentSM.setPingTransitions((spw_publish,)) 
     186        self.newsSM = _createObjectByType('Sitemap', self.portal, 
     187                                          id='news-sitemaps') 
     188        self.newsSM.setPortalTypes(('News Item', 'Document')) 
     189        self.newsSM.setPingTransitions((spw_publish,)) 
     190        self.sitemapUrl = '/' + self.portal.absolute_url(1) + \ 
     191                          '/google-sitemaps' 
    175192        # Add testing document to portal 
    176193        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc') 
    177         self.my_news = _createObjectByType('News Item', self.portal, id='my_news') 
     194        self.my_news = _createObjectByType('News Item', self.portal, 
     195                                           id='my_news') 
    178196 
    179197    def testAutomatePinging(self): 
     
    188206            sys.stdout = back_out 
    189207 
    190         self.assert_('Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 
     208        self.assert_('Pinged %s sitemap to Google' \ 
     209                     % self.contentSM.absolute_url() in data, 
    191210                     "Not pinged %s: '%s'" % (self.contentSM.id, data)) 
    192         self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 
     211        self.assert_('Pinged %s sitemap to Google' \ 
     212                     % self.newsSM.absolute_url() in data, 
    193213                     "Not pinged %s: '%s'" % (self.newsSM.id, data)) 
    194214 
     
    203223            sys.stdout = back_out 
    204224 
    205         self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 
     225        self.assert_('Pinged %s sitemap to Google' \ 
     226                     % self.newsSM.absolute_url() in data, 
    206227                     "Not pinged %s: '%s'" % (self.newsSM.id, data)) 
    207         self.assert_(not 'Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 
     228        self.assert_(not 'Pinged %s sitemap to Google' \ 
     229                     % self.contentSM.absolute_url() in data, 
    208230                     "Pinged %s on news: '%s'" % (self.contentSM.id, data)) 
    209231 
    210232    def testPingingWithSetupForm(self): 
    211233        # Ping news and content sitemaps 
    212         formUrl = '/'+self.portal.absolute_url(1) + '/prefs_gsm_settings' 
    213         qs = 'smselected:list=%s&smselected:list=%s&form.button.Ping=1&form.submitted=1' % \ 
    214              (self.contentSM.id, self.newsSM.id) 
     234        formUrl = '/' + self.portal.absolute_url(1) + '/prefs_gsm_settings' 
     235        qs = 'smselected:list=%s&smselected:list=%s&form.button.Ping=1' \ 
     236             '&form.submitted=1' % (self.contentSM.id, self.newsSM.id) 
    215237 
    216238        back_out, myout = sys.stdout, StringIO() 
     
    223245            sys.stdout = back_out 
    224246 
    225         self.assert_('Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 
     247        self.assert_('Pinged %s sitemap to Google' \ 
     248                     % self.contentSM.absolute_url() in data, 
    226249                     "Not pinged %s: '%s'" % (self.contentSM.id, data)) 
    227         self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 
     250        self.assert_('Pinged %s sitemap to Google' \ 
     251                     % self.newsSM.absolute_url() in data, 
    228252                     "Not pinged %s: '%s'" % (self.newsSM.id, data)) 
    229253 
     
    241265        self.sm.at_post_create_script() 
    242266        # Add content in root and in the test folder 
    243         pubdate = (DateTime()+1).strftime("%Y-%m-%d") 
    244         root_content = _createObjectByType(ptypes[0], self.portal, id='root-content') 
    245         inner_content = _createObjectByType(ptypes[0], tfolder, id='inner-content') 
     267        pubdate = (DateTime() + 1).strftime("%Y-%m-%d") 
     268        root_content = _createObjectByType(ptypes[0], self.portal, 
     269                                           id='root-content') 
     270        inner_content = _createObjectByType(ptypes[0], tfolder, 
     271                                            id='inner-content') 
    246272        for obj in (root_content, inner_content): 
    247273            self.workflow.doActionFor(obj, 'publish') 
    248274            if ifaces: 
    249275                alsoProvides(obj, ifaces) 
    250             obj.edit(effectiveDate=pubdate) # this also reindex object 
     276            obj.edit(effectiveDate=pubdate)  # this also reindex object 
    251277        self.inner_path = '/'.join(inner_content.getPhysicalPath()) 
    252          
     278 
    253279    def testGoogleSitemap(self): 
    254280        self.prepareTestContent("content", ("Document",)) 
    255281        filtered = SitemapView(self.sm, TestRequest()).getFilteredObjects() 
    256         self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     282        self.assertEqual(map(lambda x: x.getPath(), filtered), 
     283                        [self.inner_path, ]) 
    257284 
    258285    def testNewsSitemap(self): 
    259286        self.prepareTestContent("news", ("News Item",)) 
    260287        filtered = NewsSitemapView(self.sm, TestRequest()).getFilteredObjects() 
    261         self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     288        self.assertEqual(map(lambda x: x.getPath(), filtered), 
     289                         [self.inner_path, ]) 
    262290 
    263291    def testMobileSitemap(self): 
    264292        self.patchMobile() 
    265293        self.prepareTestContent("content", ("Document",), (IMobileMarker,)) 
    266         filtered = MobileSitemapView(self.sm, TestRequest()).getFilteredObjects() 
    267         self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 
     294        filtered = MobileSitemapView(self.sm, 
     295                                     TestRequest()).getFilteredObjects() 
     296        self.assertEqual(map(lambda x: x.getPath(), filtered), 
     297                         [self.inner_path, ]) 
    268298 
    269299 
Note: See TracChangeset for help on using the changeset viewer.