source: products/quintagroup.plonegooglesitemaps/branches/1.7.1/quintagroup/plonegooglesitemaps/tests/testPinging.py

Last change on this file 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
Line 
1from quintagroup.plonegooglesitemaps.tests.base import FunctionalTestCase
2import sys
3from StringIO import StringIO
4import unittest
5
6from Products.CMFPlone.utils import _createObjectByType
7
8
9class TestPinging(FunctionalTestCase):
10
11    def afterSetUp(self):
12        super(TestPinging, self).afterSetUp()
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]
18        # Add sitemaps
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'
29        # Add testing document to portal
30        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
31        self.my_news = _createObjectByType('News Item', self.portal,
32                                           id='my_news')
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
45        self.assert_('Pinged %s sitemap to Google' \
46                     % self.contentSM.absolute_url() in data,
47                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
48        self.assert_('Pinged %s sitemap to Google' \
49                     % self.newsSM.absolute_url() in data,
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
62        self.assert_('Pinged %s sitemap to Google' \
63                     % self.newsSM.absolute_url() in data,
64                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
65        self.assert_(not 'Pinged %s sitemap to Google' \
66                     % self.contentSM.absolute_url() in data,
67                     "Pinged %s on news: '%s'" % (self.contentSM.id, data))
68
69    def testPingingWithSetupForm(self):
70        # Ping news and content sitemaps
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)
74
75        back_out, myout = sys.stdout, StringIO()
76        sys.stdout = myout
77        try:
78            self.publish("%s?%s" % (formUrl, qs), basic=self.auth)
79            myout.seek(0)
80            data = myout.read()
81        finally:
82            sys.stdout = back_out
83
84        self.assert_('Pinged %s sitemap to Google' \
85                     % self.contentSM.absolute_url() in data,
86                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
87        self.assert_('Pinged %s sitemap to Google' \
88                     % self.newsSM.absolute_url() in data,
89                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
90
91
92def test_suite():
93    suite = unittest.TestSuite()
94    suite.addTest(unittest.makeSuite(TestPinging))
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.