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

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

fixes pep8

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