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

Last change on this file since 2538 was 2538, checked in by mylan, 11 years ago

Merged revisions 3566-3575 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/test_refactoring

........

r3566 | mylan | 2010-06-14 12:24:52 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Split single testqPloneGoogleSitemaps module into several specific one

........

r3567 | mylan | 2010-06-14 16:14:34 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - remove useless BBB code from interfaces.

........

r3568 | mylan | 2010-06-14 20:24:25 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - added test for MobileSitemap?, MobileSitemapView?.

........

r3569 | mylan | 2010-06-14 22:39:39 +0300 (Mon, 14 Jun 2010) | 1 line


#206: reorganize sitemap tests

........

r3570 | mylan | 2010-06-14 22:40:12 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Added configlet tests

........

r3571 | mylan | 2010-06-14 23:05:19 +0300 (Mon, 14 Jun 2010) | 1 line


#206: remove BBB code for plone<3.0

........

r3572 | mylan | 2010-06-14 23:12:00 +0300 (Mon, 14 Jun 2010) | 1 line


#206: added workflow vocabularies tests for SitemapTypes?

........

r3573 | mylan | 2010-06-15 21:36:40 +0300 (Tue, 15 Jun 2010) | 1 line


#206: some cleanup, simplify tests

........

r3574 | mylan | 2010-06-16 16:35:31 +0300 (Wed, 16 Jun 2010) | 1 line


#206: move mobile sitemap code preparation into base module

........

r3575 | mylan | 2010-06-16 16:37:14 +0300 (Wed, 16 Jun 2010) | 1 line


#206: Added security tests

........

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