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
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()
[3510]13        workflow = "simple_publication_workflow"
14        self.workflow.setChainForPortalTypes(pt_names=('News Item',
15                                                       'Document'),
16                                             chain=workflow)
[3152]17        gsm_properties = 'googlesitemap_properties'
18        self.gsm_props = self.portal.portal_properties[gsm_properties]
[2527]19        # Add sitemaps
[3152]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'
[2527]30        # Add testing document to portal
[2534]31        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
[3152]32        self.my_news = _createObjectByType('News Item', self.portal,
33                                           id='my_news')
[2527]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
[3510]46        self.assert_('Pinged %s sitemap to Google'
[3152]47                     % self.contentSM.absolute_url() in data,
[2527]48                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
[3510]49        self.assert_('Pinged %s sitemap to Google'
[3152]50                     % self.newsSM.absolute_url() in data,
[2527]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
[3510]63        self.assert_('Pinged %s sitemap to Google'
[3152]64                     % self.newsSM.absolute_url() in data,
[2527]65                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
[3510]66        self.assert_(not 'Pinged %s sitemap to Google'
[3152]67                     % self.contentSM.absolute_url() in data,
[2527]68                     "Pinged %s on news: '%s'" % (self.contentSM.id, data))
69
70    def testPingingWithSetupForm(self):
71        # Ping news and content sitemaps
[3152]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)
[2527]75
76        back_out, myout = sys.stdout, StringIO()
77        sys.stdout = myout
78        try:
[3163]79            self.publish("%s?%s" % (formUrl, qs), basic=self.auth)
[2527]80            myout.seek(0)
81            data = myout.read()
82        finally:
83            sys.stdout = back_out
84
[3510]85        self.assert_('Pinged %s sitemap to Google'
[3152]86                     % self.contentSM.absolute_url() in data,
[2527]87                     "Not pinged %s: '%s'" % (self.contentSM.id, data))
[3510]88        self.assert_('Pinged %s sitemap to Google'
[3152]89                     % self.newsSM.absolute_url() in data,
[2527]90                     "Not pinged %s: '%s'" % (self.newsSM.id, data))
91
92
93def test_suite():
[3163]94    suite = unittest.TestSuite()
95    suite.addTest(unittest.makeSuite(TestPinging))
[2527]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.