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

Last change on this file since 3664 was 3510, checked in by potar, 12 years ago

Merged sitemap_date branch into trunk

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