source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSecurity.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.5 KB
Line 
1#
2# Tests related to general Sitemap type.
3#
4from base import *
5from zope.interface import alsoProvides
6from Products.Archetypes import atapi
7from Products.CMFPlone.utils import _createObjectByType
8
9
10class MixinSecurity(FunctionalTestCase):
11
12    def getview(self, vpath):
13        return self.publish("/" + self.portal.absolute_url(1) + \
14                            "/" + vpath, self.auth)
15
16
17class TestSecurityConfigletManager(MixinSecurity):
18
19    def afterSetUp(self):
20        super(TestSecurityConfigletManager, self).afterSetUp()
21        self.auth = "admin:admin"
22        self.portal.portal_membership.addMember('admin', 'admin',
23                                                ('Manager',), [])
24
25    def testConfigOverview(self):
26        resp = self.getview("prefs_gsm_overview")
27        self.assertEqual(resp.status / 100, 2)
28
29    def testConfigSettings(self):
30        resp = self.getview("prefs_gsm_settings")
31        self.assertEqual(resp.status / 100, 2)
32
33    def testConfigVerification(self):
34        resp = self.getview("prefs_gsm_verification")
35        self.assertEqual(resp.status / 100, 2)
36
37
38class TestSecurityConfigletNotManager(MixinSecurity):
39
40    def afterSetUp(self):
41        super(TestSecurityConfigletNotManager, self).afterSetUp()
42        self.auth = "mem:mem"
43        self.portal.portal_membership.addMember('mem', 'mem', ('Member',), [])
44
45    def testConfigOverview(self):
46        resp = self.getview("prefs_gsm_overview")
47        self.assertNotEqual(resp.status / 100, 2)
48
49    def testConfigSettings(self):
50        resp = self.getview("prefs_gsm_settings")
51        self.assertNotEqual(resp.status / 100, 2)
52
53    def testConfigVerification(self):
54        resp = self.getview("prefs_gsm_verification")
55        self.assertNotEqual(resp.status / 100, 2)
56
57
58SM_TYPES = {
59  "content": {"id": "sitemap.xml", "types": ("Document",)},
60  "news": {"id": "news-sitemap.xml", "types": ("News Item",)},
61  "mobile": {"id": "mobile-sitemap.xml", "types": ("Document",)},
62}
63from DateTime import DateTime
64
65
66class TestSecuritySiteMaps(MixinSecurity):
67
68    def afterSetUp(self):
69        super(TestSecuritySiteMaps, self).afterSetUp()
70        self.auth = ":"
71        self.patchMobile()
72        self.createSMaps()
73        self.createContent()
74
75    def createSMaps(self):
76        self.smaps = {}
77        for smtype, smdata in SM_TYPES.items():
78            _createObjectByType("Sitemap", self.portal, id=smdata["id"],
79                                sitemapType=smtype,
80                                portalTypes=smdata["types"])
81            sm = getattr(self.portal, smdata["id"])
82            sm.at_post_create_script()
83            self.smaps[smtype] = sm
84
85    def createContent(self):
86        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
87        self.workflow.doActionFor(self.my_doc, 'publish')
88        self.my_news = _createObjectByType('News Item', self.portal,
89                                           id='my_news')
90        self.my_news.edit(title="My News Item (test)",
91                          effectiveDate=DateTime().strftime("%Y-%m-%d"))
92        self.workflow.doActionFor(self.my_news, 'publish')
93        # mobile content must provides additional interfaces
94        # to fall into mobile sitemap
95        alsoProvides(self.my_doc, IMobileMarker)
96        self.my_doc.reindexObject()
97        self.my_news.reindexObject()
98
99    def reparse(self, data):
100        parsed = parse(data)
101        return parsed["start"], parsed["data"]
102
103    def testContentSM(self):
104        resp = self.getview("sitemap.xml")
105        self.assertEqual(resp.status / 100, 2)
106        start, data = self.reparse(resp.getBody())
107        self.assert_("loc" in start)
108        self.assert_(self.my_doc.absolute_url() in data)
109
110    def testNewsSM(self):
111        resp = self.getview("news-sitemap.xml")
112        self.assertEqual(resp.status / 100, 2)
113        start, data = self.reparse(resp.getBody())
114        self.assert_("n:name" in start)
115        self.assert_("My News Item" in data)
116
117    def testMobileSM(self):
118        resp = self.getview("mobile-sitemap.xml")
119        self.assertEqual(resp.status / 100, 2)
120        start, data = self.reparse(resp.getBody())
121        self.assert_("loc" in start)
122        self.assert_(self.my_doc.absolute_url() in data)
123
124
125def test_suite():
126    from unittest import TestSuite, makeSuite
127    suite = TestSuite()
128    suite.addTest(makeSuite(TestSecurityConfigletManager))
129    suite.addTest(makeSuite(TestSecurityConfigletNotManager))
130    suite.addTest(makeSuite(TestSecuritySiteMaps))
131    return suite
132
133if __name__ == '__main__':
134    unittest.main(defaultTest='test_suite')
135#    framework()
Note: See TracBrowser for help on using the repository browser.