source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testPinging.py @ 3163

Last change on this file since 3163 was 3163, checked in by zidane, 13 years ago

fixes pyflakes and pylint

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[3163]1from quintagroup.plonegooglesitemaps.tests.base import FunctionalTestCase
2import sys
3from StringIO import StringIO
4import unittest
5
[2527]6from Products.CMFPlone.utils import _createObjectByType
7
8
9class TestPinging(FunctionalTestCase):
10
11    def afterSetUp(self):
12        super(TestPinging, self).afterSetUp()
[3152]13        self.workflow.setChainForPortalTypes(
14                pt_names=('News Item', 'Document'),
15                chain="simple_publication_workflow")
16        gsm_properties = 'googlesitemap_properties'
17        self.gsm_props = self.portal.portal_properties[gsm_properties]
[2527]18        # Add sitemaps
[3152]19        self.contentSM = _createObjectByType('Sitemap', self.portal,
20                                             id='google-sitemaps')
21        spw_publish = 'simple_publication_workflow#publish'
22        self.contentSM.setPingTransitions((spw_publish,))
23        self.newsSM = _createObjectByType('Sitemap', self.portal,
24                                          id='news-sitemaps')
25        self.newsSM.setPortalTypes(('News Item', 'Document'))
26        self.newsSM.setPingTransitions((spw_publish,))
27        self.sitemapUrl = '/' + self.portal.absolute_url(1) + \
28                          '/google-sitemaps'
[2527]29        # Add testing document to portal
[2534]30        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
[3152]31        self.my_news = _createObjectByType('News Item', self.portal,
32                                           id='my_news')
[2527]33
34    def testAutomatePinging(self):
35        # 1. Check for pinging both sitemaps
36        back_out, myout = sys.stdout, StringIO()
37        sys.stdout = myout
38        try:
39            self.workflow.doActionFor(self.my_doc, 'publish')
40            myout.seek(0)
41            data = myout.read()
42        finally:
43            sys.stdout = back_out
44
[3152]45        self.assert_('Pinged %s sitemap to Google' \
46                     % self.contentSM.absolute_url() in data,
[2527]47                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
[3152]48        self.assert_('Pinged %s sitemap to Google' \
49                     % self.newsSM.absolute_url() in data,
[2527]50                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
51
52        # 2. Check for pinging only news-sitemap sitemaps
53        back_out, myout = sys.stdout, StringIO()
54        sys.stdout = myout
55        try:
56            self.workflow.doActionFor(self.my_news, 'publish')
57            myout.seek(0)
58            data = myout.read()
59        finally:
60            sys.stdout = back_out
61
[3152]62        self.assert_('Pinged %s sitemap to Google' \
63                     % self.newsSM.absolute_url() in data,
[2527]64                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
[3152]65        self.assert_(not 'Pinged %s sitemap to Google' \
66                     % self.contentSM.absolute_url() in data,
[2527]67                     "Pinged %s on news: '%s'" % (self.contentSM.id, data))
68
69    def testPingingWithSetupForm(self):
70        # Ping news and content sitemaps
[3152]71        formUrl = '/' + self.portal.absolute_url(1) + '/prefs_gsm_settings'
72        qs = 'smselected:list=%s&smselected:list=%s&form.button.Ping=1' \
73             '&form.submitted=1' % (self.contentSM.id, self.newsSM.id)
[2527]74
75        back_out, myout = sys.stdout, StringIO()
76        sys.stdout = myout
77        try:
[3163]78            self.publish("%s?%s" % (formUrl, qs), basic=self.auth)
[2527]79            myout.seek(0)
80            data = myout.read()
81        finally:
82            sys.stdout = back_out
83
[3152]84        self.assert_('Pinged %s sitemap to Google' \
85                     % self.contentSM.absolute_url() in data,
[2527]86                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
[3152]87        self.assert_('Pinged %s sitemap to Google' \
88                     % self.newsSM.absolute_url() in data,
[2527]89                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
90
91
92def test_suite():
[3163]93    suite = unittest.TestSuite()
94    suite.addTest(unittest.makeSuite(TestPinging))
[2527]95    return suite
96
97if __name__ == '__main__':
98    unittest.main(defaultTest='test_suite')
99#    framework()
Note: See TracBrowser for help on using the repository browser.