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

Last change on this file since 3152 was 3152, checked in by zidane, 9 years ago

fixes pep8

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