source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSecurity.py @ 3163

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

fixes pyflakes and pylint

  • Property svn:eol-style set to native
File size: 4.6 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', 'mem', ('Member',), [])
47
48    def testConfigOverview(self):
49        resp = self.getview("prefs_gsm_overview")
50        self.assertNotEqual(resp.status / 100, 2)
51
52    def testConfigSettings(self):
53        resp = self.getview("prefs_gsm_settings")
54        self.assertNotEqual(resp.status / 100, 2)
55
56    def testConfigVerification(self):
57        resp = self.getview("prefs_gsm_verification")
58        self.assertNotEqual(resp.status / 100, 2)
59
60
61SM_TYPES = {
62  "content": {"id": "sitemap.xml", "types": ("Document",)},
63  "news": {"id": "news-sitemap.xml", "types": ("News Item",)},
64  "mobile": {"id": "mobile-sitemap.xml", "types": ("Document",)},
65}
66from DateTime import DateTime
67
68
69class TestSecuritySiteMaps(MixinSecurity):
70
71    def afterSetUp(self):
72        super(TestSecuritySiteMaps, self).afterSetUp()
73        self.auth = ":"
74        self.patchMobile()
75        self.createSMaps()
76        self.createContent()
77
78    def createSMaps(self):
79        self.smaps = {}
80        for smtype, smdata in SM_TYPES.items():
81            _createObjectByType("Sitemap", self.portal, id=smdata["id"],
82                                sitemapType=smtype,
83                                portalTypes=smdata["types"])
84            sm = getattr(self.portal, smdata["id"])
85            sm.at_post_create_script()
86            self.smaps[smtype] = sm
87
88    def createContent(self):
89        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
90        self.workflow.doActionFor(self.my_doc, 'publish')
91        self.my_news = _createObjectByType('News Item', self.portal,
92                                           id='my_news')
93        self.my_news.edit(title="My News Item (test)",
94                          effectiveDate=DateTime().strftime("%Y-%m-%d"))
95        self.workflow.doActionFor(self.my_news, 'publish')
96        # mobile content must provides additional interfaces
97        # to fall into mobile sitemap
98        alsoProvides(self.my_doc, IMobileMarker)
99        self.my_doc.reindexObject()
100        self.my_news.reindexObject()
101
102    def reparse(self, data):
103        parsed = parse(data)
104        return parsed["start"], parsed["data"]
105
106    def testContentSM(self):
107        resp = self.getview("sitemap.xml")
108        self.assertEqual(resp.status / 100, 2)
109        start, data = self.reparse(resp.getBody())
110        self.assert_("loc" in start)
111        self.assert_(self.my_doc.absolute_url() in data)
112
113    def testNewsSM(self):
114        resp = self.getview("news-sitemap.xml")
115        self.assertEqual(resp.status / 100, 2)
116        start, data = self.reparse(resp.getBody())
117        self.assert_("n:name" in start)
118        self.assert_("My News Item" in data)
119
120    def testMobileSM(self):
121        resp = self.getview("mobile-sitemap.xml")
122        self.assertEqual(resp.status / 100, 2)
123        start, data = self.reparse(resp.getBody())
124        self.assert_("loc" in start)
125        self.assert_(self.my_doc.absolute_url() in data)
126
127
128def test_suite():
129    suite = unittest.TestSuite()
130    suite.addTest(unittest.makeSuite(TestSecurityConfigletManager))
131    suite.addTest(unittest.makeSuite(TestSecurityConfigletNotManager))
132    suite.addTest(unittest.makeSuite(TestSecuritySiteMaps))
133    return suite
134
135if __name__ == '__main__':
136    unittest.main(defaultTest='test_suite')
137#    framework()
Note: See TracBrowser for help on using the repository browser.