[2527] | 1 | # |
---|
| 2 | # Tests related to general Sitemap type. |
---|
| 3 | # |
---|
| 4 | from base import * |
---|
| 5 | from Products.CMFPlone.utils import _createObjectByType |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | class TestSitemapType(FunctionalTestCase): |
---|
| 9 | |
---|
| 10 | def afterSetUp(self): |
---|
| 11 | super(TestSitemapType, self).afterSetUp() |
---|
| 12 | self.auth = 'admin:admin' |
---|
| 13 | self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') |
---|
| 14 | self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
---|
| 15 | |
---|
| 16 | def testFields(self): |
---|
| 17 | field_ids = map(lambda x:x.getName(), self.contentSM.Schema().fields()) |
---|
| 18 | # test old Sitemap settings fields |
---|
| 19 | self.assert_('id' in field_ids) |
---|
| 20 | self.assert_('portalTypes' in field_ids) |
---|
| 21 | self.assert_('states' in field_ids) |
---|
| 22 | self.assert_('blackout_list' in field_ids) |
---|
| 23 | self.assert_('urls' in field_ids) |
---|
| 24 | self.assert_('pingTransitions' in field_ids) |
---|
| 25 | # test new sitemap type field |
---|
| 26 | self.assert_('sitemapType' in field_ids) |
---|
| 27 | |
---|
| 28 | def testSitemapTypes(self): |
---|
| 29 | sitemap_types = self.contentSM.getField('sitemapType').Vocabulary().keys() |
---|
| 30 | self.assert_('content' in sitemap_types) |
---|
| 31 | self.assert_('mobile' in sitemap_types) |
---|
| 32 | self.assert_('news' in sitemap_types) |
---|
| 33 | |
---|
| 34 | def testAutoSetLayout(self): |
---|
| 35 | response = self.publish('/%s/createObject?type_name=Sitemap' % \ |
---|
| 36 | self.portal.absolute_url(1), basic=self.auth) |
---|
| 37 | location = response.getHeader('location') |
---|
| 38 | newurl = location[location.find('/'+self.portal.absolute_url(1)):] |
---|
| 39 | |
---|
| 40 | msm_id = 'mobile_sitemap' |
---|
| 41 | form = {'id': msm_id, |
---|
| 42 | 'sitemapType':'mobile', |
---|
| 43 | 'portalTypes':['Document',], |
---|
| 44 | 'states':['published'], |
---|
| 45 | 'form_submit':'Save', |
---|
| 46 | 'form.submitted':1, |
---|
| 47 | } |
---|
| 48 | post_data = StringIO(urlencode(form)) |
---|
| 49 | response = self.publish(newurl, request_method='POST', stdin=post_data, basic=self.auth) |
---|
| 50 | msitemap = getattr(self.portal, msm_id) |
---|
| 51 | |
---|
| 52 | self.assertEqual(msitemap.defaultView(), 'mobile-sitemap.xml') |
---|
| 53 | |
---|
| 54 | def txestPingSetting(self): |
---|
| 55 | pwf = self.portal.portal_workflow['plone_workflow'] |
---|
| 56 | self.assertEqual(self.contentSM.getPingTransitions(), ()) |
---|
| 57 | |
---|
| 58 | self.contentSM.setPingTransitions(('plone_workflow#publish',)) |
---|
| 59 | self.assertEqual(self.contentSM.getPingTransitions(), ('plone_workflow#publish',)) |
---|
| 60 | self.assert_(ping_googlesitemap in pwf.scripts.keys(),"Not add wf script") |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | class TestSettings(FunctionalTestCase): |
---|
| 64 | |
---|
| 65 | def afterSetUp(self): |
---|
| 66 | super(TestSettings, self).afterSetUp() |
---|
| 67 | |
---|
| 68 | self.workflow = self.portal.portal_workflow |
---|
| 69 | self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] |
---|
| 70 | self.auth = 'admin:admin' |
---|
| 71 | self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') |
---|
| 72 | |
---|
| 73 | self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' |
---|
| 74 | |
---|
| 75 | self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
---|
| 76 | |
---|
| 77 | # Add testing document to portal |
---|
| 78 | my_doc = self.portal.invokeFactory('Document', id='my_doc') |
---|
| 79 | self.my_doc = self.portal['my_doc'] |
---|
| 80 | self.my_doc.edit(text_format='plain', text='hello world') |
---|
| 81 | self.my_doc_url = self.my_doc.absolute_url() |
---|
| 82 | |
---|
| 83 | def testMetaTypeToDig(self): |
---|
| 84 | self.workflow.doActionFor(self.my_doc, 'publish') |
---|
| 85 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 86 | self.assert_(hasURL(sitemap, self.my_doc_url)) |
---|
| 87 | |
---|
| 88 | self.contentSM.setPortalTypes([]) |
---|
| 89 | |
---|
| 90 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 91 | self.assert_(not hasURL(sitemap, self.my_doc_url)) |
---|
| 92 | |
---|
| 93 | self.contentSM.setPortalTypes(['Document']) |
---|
| 94 | |
---|
| 95 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 96 | self.assert_(hasURL(sitemap, self.my_doc_url)) |
---|
| 97 | |
---|
| 98 | def testStates(self): |
---|
| 99 | self.workflow.doActionFor(self.my_doc, 'publish') |
---|
| 100 | self.contentSM.setStates(['visible']) |
---|
| 101 | |
---|
| 102 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 103 | self.assert_(not hasURL(sitemap, self.my_doc_url)) |
---|
| 104 | |
---|
| 105 | self.contentSM.setStates(['published']) |
---|
| 106 | |
---|
| 107 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 108 | self.assert_(hasURL(sitemap, self.my_doc_url)) |
---|
| 109 | |
---|
| 110 | def test_blackout_entries(self): |
---|
| 111 | self.workflow.doActionFor(self.my_doc, 'publish') |
---|
| 112 | self.contentSM.setBlackout_list((self.my_doc.getId(),)) |
---|
| 113 | |
---|
| 114 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 115 | self.assert_(not hasURL(sitemap, self.my_doc_url)) |
---|
| 116 | |
---|
| 117 | self.contentSM.setBlackout_list([]) |
---|
| 118 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 119 | self.assert_(hasURL(sitemap, self.my_doc_url)) |
---|
| 120 | |
---|
| 121 | def test_regexp(self): |
---|
| 122 | self.workflow.doActionFor(self.my_doc, 'publish') |
---|
| 123 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 124 | self.assert_(not hasURL(sitemap, self.portal.absolute_url())) |
---|
| 125 | |
---|
| 126 | regexp = "s/\/%s//"%self.my_doc.getId() |
---|
| 127 | self.contentSM.setReg_exp([regexp]) |
---|
| 128 | |
---|
| 129 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 130 | self.assert_(hasURL(sitemap, self.portal.absolute_url())) |
---|
| 131 | |
---|
| 132 | def test_add_urls(self): |
---|
| 133 | self.contentSM.setUrls(['http://w1', 'w2', '/w3']) |
---|
| 134 | w1_url = 'http://w1' |
---|
| 135 | w2_url = self.portal.absolute_url() + '/w2' |
---|
| 136 | w3_url = self.portal.getPhysicalRoot().absolute_url() + '/w3' |
---|
| 137 | sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
---|
| 138 | |
---|
| 139 | self.assert_(hasURL(sitemap, w1_url)) |
---|
| 140 | self.assert_(hasURL(sitemap, w2_url)) |
---|
| 141 | self.assert_(hasURL(sitemap, w3_url)) |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | def test_suite(): |
---|
| 145 | from unittest import TestSuite, makeSuite |
---|
| 146 | suite = TestSuite() |
---|
| 147 | suite.addTest(makeSuite(TestSitemapType)) |
---|
| 148 | suite.addTest(makeSuite(TestSettings)) |
---|
| 149 | return suite |
---|
| 150 | |
---|
| 151 | if __name__ == '__main__': |
---|
| 152 | unittest.main(defaultTest='test_suite') |
---|
| 153 | # framework() |
---|