source: products/quintagroup.plonegooglesitemaps/branches/test_refactoring/quintagroup/plonegooglesitemaps/tests/testPinging.py @ 2534

Last change on this file since 2534 was 2534, checked in by mylan, 14 years ago

#206: some cleanup, simplify tests

  • Property svn:eol-style set to native
File size: 3.5 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()
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
[2534]20        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
21        self.my_news = _createObjectByType('News Item', self.portal, id='my_news')
[2527]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.