source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testConfiglet.py @ 3510

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

Merged sitemap_date branch into trunk

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1#
2# Tests for quintagroup.plonegooglesitemaps
3#
4
5from quintagroup.plonegooglesitemaps.tests.base import FunctionalTestCase
6from StringIO import StringIO
7from urllib import urlencode
8import unittest
9
10from Products.CMFPlone.utils import _createObjectByType
11
12
13class TestConfigletSettings(FunctionalTestCase):
14
15    def afterSetUp(self):
16        super(TestConfigletSettings, self).afterSetUp()
17        self.settingsURL = '/' + self.portal.absolute_url(1) + \
18                           '/prefs_gsm_settings'
19
20    def submitForm(self, fdata, fextra={}):
21        form = {'form.submitted': 1}
22        form.update(fdata)
23        return self.publish(self.settingsURL, request_method='POST',
24                            stdin=StringIO(urlencode(form)),
25                            basic=self.auth, extra=fextra)
26
27    def testInitButtons(self):
28        settings = self.publish(self.settingsURL, self.auth).getBody()
29        self.assert_("Add Content Sitemap" in settings)
30        self.assert_("Add News Sitemap" in settings)
31        self.assert_("Add Mobile Sitemap" in settings)
32
33    def testAddContentSitemap(self):
34        resp = self.submitForm({'form.button.AddContent':
35                                "Add Content Sitemap"})
36        self.assertEqual(resp.getStatus() / 100, 3)
37        sm_edit = "sitemap.xml/edit"
38        self.assertEqual(resp.getHeader("Location").endswith(sm_edit), True)
39        # Add SM
40        self.portal["sitemap.xml"]
41        #self.portal["sitemap.xml"].setPortalTypes(("Documents",))
42        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
43        self.assertEqual('href="http://nohost/plone/sitemap.xml/edit"' in
44                         newform, True)
45        self.assertEqual("form.button.AddContent" in newform, False)
46
47    def testAddNewsSitemap(self):
48        resp = self.submitForm({'form.button.AddNews': "Add News Sitemap"})
49        self.assertEqual(resp.getStatus() / 100, 3)
50        sm_edit = "news-sitemap.xml/edit"
51        self.assertEqual(resp.getHeader("Location").endswith(sm_edit), True)
52        # Add SM
53        self.portal["news-sitemap.xml"]
54        #self.portal["news-sitemap.xml"].setPortalTypes(("News Item",))
55        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
56        self.assertEqual('href="http://nohost/plone/news-sitemap.xml/edit"'
57                         in newform, True)
58        self.assertEqual("form.button.AddNews" in newform, False)
59
60    def testAddMobileSitemap(self):
61        resp = self.submitForm({'form.button.AddMobile': "Add Mobile Sitemap"})
62        self.assertEqual(resp.getStatus() / 100, 3)
63        msm_edit = "mobile-sitemap.xml/edit"
64        self.assertEqual(resp.getHeader("Location").endswith(msm_edit), True)
65        # Add SM
66        self.portal["mobile-sitemap.xml"]
67        #self.portal["mobile-sitemap.xml"].setPortalTypes(("Documents",))
68        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
69        self.assertEqual('href="http://nohost/plone/mobile-sitemap.xml/edit"'
70                         in newform, True)
71        self.assertEqual("form.button.AddMobile" in newform, False)
72
73
74class TestConfigletOverview(FunctionalTestCase):
75
76    def afterSetUp(self):
77        super(TestConfigletOverview, self).afterSetUp()
78        self.overviewURL = '/' + self.portal.absolute_url(1) + \
79                           '/prefs_gsm_overview'
80        self.smURL = "%s/sitemap.xml" % self.portal.absolute_url()
81
82    def testInitial(self):
83        overview = self.publish(self.overviewURL, self.auth).getBody()
84        self.assert_(not self.smURL in overview)
85
86    def testPresentedSM(self):
87        _createObjectByType("Sitemap", self.portal, id="sitemap.xml",
88                            sitemapType="content")
89        overview = self.publish(self.overviewURL, self.auth).getBody()
90        self.assert_(self.smURL in overview)
91
92
93def test_suite():
94    suite = unittest.TestSuite()
95    suite.addTest(unittest.makeSuite(TestConfigletSettings))
96    suite.addTest(unittest.makeSuite(TestConfigletOverview))
97    return suite
98
99if __name__ == '__main__':
100    unittest.main(defaultTest='test_suite')
101#    framework()
Note: See TracBrowser for help on using the repository browser.