source: products/quintagroup.plonegooglesitemaps/branches/test_refactoring/quintagroup/plonegooglesitemaps/tests/testConfiglet.py @ 2531

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

#206: Added configlet tests

  • Property svn:eol-style set to native
File size: 3.9 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.auth = "%s:%s" % (portal_owner, default_password)
19        self.settingsURL = '/'+self.portal.absolute_url(1) + '/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({'form.button.AddContent': "Add Content Sitemap"})
36        self.assertEqual(resp.getStatus() / 100, 3)
37        self.assertEqual(resp.getHeader("Location").endswith("sitemap.xml/edit"), True)
38        # Add SM
39        sm = self.portal["sitemap.xml"]
40        #sm.setPortalTypes(("Documents",))
41        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
42        self.assertEqual('href="http://nohost/plone/sitemap.xml/edit"' in newform, True)
43        self.assertEqual("form.button.AddContent" in newform, False)
44
45    def testAddNewsSitemap(self):
46        resp = self.submitForm({'form.button.AddNews': "Add News Sitemap"})
47        self.assertEqual(resp.getStatus() / 100, 3)
48        self.assertEqual(resp.getHeader("Location").endswith("news-sitemap.xml/edit"), True)
49        # Add SM
50        sm = self.portal["news-sitemap.xml"]
51        #sm.setPortalTypes(("News Item",))
52        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
53        self.assertEqual('href="http://nohost/plone/news-sitemap.xml/edit"' in newform, True)
54        self.assertEqual("form.button.AddNews" in newform, False)
55
56    def testAddMobileSitemap(self):
57        resp = self.submitForm({'form.button.AddMobile': "Add Mobile Sitemap"})
58        self.assertEqual(resp.getStatus() / 100, 3)
59        self.assertEqual(resp.getHeader("Location").endswith("mobile-sitemap.xml/edit"), True)
60        # Add SM
61        sm = self.portal["mobile-sitemap.xml"]
62        #sm.setPortalTypes(("Documents",))
63        newform = self.publish(self.settingsURL, basic=self.auth).getBody()
64        self.assertEqual('href="http://nohost/plone/mobile-sitemap.xml/edit"' in newform, True)
65        self.assertEqual("form.button.AddMobile" in newform, False)
66
67
68class TestConfigletOverview(FunctionalTestCase):
69
70    def afterSetUp(self):
71        super(TestConfigletOverview, self).afterSetUp()
72        self.auth = "%s:%s" % (portal_owner, default_password)
73        self.overviewURL = '/'+self.portal.absolute_url(1) + '/prefs_gsm_overview'
74        self.smURL = "%s/sitemap.xml" % self.portal.absolute_url()
75       
76    def testInitial(self):
77        overview = self.publish(self.overviewURL, self.auth).getBody()
78        self.assert_(not self.smURL in overview)
79
80    def testPresentedSM(self):
81        _createObjectByType("Sitemap", self.portal, id="sitemap.xml",
82                            sitemapType="content")
83        overview = self.publish(self.overviewURL, self.auth).getBody()
84        self.assert_(self.smURL in overview)
85
86
87def test_suite():
88    from unittest import TestSuite, makeSuite
89    suite = TestSuite()
90    suite.addTest(makeSuite(TestConfigletSettings))
91    suite.addTest(makeSuite(TestConfigletOverview))
92    return suite
93
94if __name__ == '__main__':
95    unittest.main(defaultTest='test_suite')
96#    framework()
Note: See TracBrowser for help on using the repository browser.