source: products/quintagroup.plonegooglesitemaps/branches/sitemap_date/quintagroup/plonegooglesitemaps/tests/testSecurity.py @ 3565

Last change on this file since 3565 was 3503, checked in by potar, 12 years ago

fixed pep8

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