| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
import re, sys |
|---|
| 5 |
from urllib import urlencode |
|---|
| 6 |
from StringIO import StringIO |
|---|
| 7 |
|
|---|
| 8 |
from Products.Five import zcml |
|---|
| 9 |
from Products.Five import fiveconfigure |
|---|
| 10 |
from Products.PloneTestCase import PloneTestCase |
|---|
| 11 |
|
|---|
| 12 |
from Products.CMFPlone.utils import _createObjectByType |
|---|
| 13 |
|
|---|
| 14 |
import Products.qPloneGoogleSitemaps |
|---|
| 15 |
from Products.qPloneGoogleSitemaps.config import ping_googlesitemap |
|---|
| 16 |
|
|---|
| 17 |
from XMLParser import parse, hasURL |
|---|
| 18 |
Products.qPloneGoogleSitemaps.config.testing = 1 |
|---|
| 19 |
|
|---|
| 20 |
PRODUCT = 'qPloneGoogleSitemaps' |
|---|
| 21 |
PRODUCTS = (PRODUCT,) |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
fiveconfigure.debug_mode = True |
|---|
| 25 |
zcml.load_config('configure.zcml', Products.qPloneGoogleSitemaps) |
|---|
| 26 |
fiveconfigure.debug_mode = False |
|---|
| 27 |
|
|---|
| 28 |
PloneTestCase.installProduct(PRODUCT) |
|---|
| 29 |
PloneTestCase.setupPloneSite(extension_profiles=("Products.%s:default" % PRODUCT,)) |
|---|
| 30 |
|
|---|
| 31 |
class TestqPloneGoogleSitemapsInstallation(PloneTestCase.PloneTestCase): |
|---|
| 32 |
|
|---|
| 33 |
def afterSetUp(self): |
|---|
| 34 |
self.loginAsPortalOwner() |
|---|
| 35 |
|
|---|
| 36 |
def testType(self): |
|---|
| 37 |
pt = self.portal.portal_types |
|---|
| 38 |
self.assert_('Sitemap' in pt.objectIds(), |
|---|
| 39 |
'No "Sitemap" type after installation') |
|---|
| 40 |
|
|---|
| 41 |
views = pt.getTypeInfo('Sitemap').view_methods |
|---|
| 42 |
self.assert_('sitemap.xml' in views, |
|---|
| 43 |
'No "sitemap.xml" view for Sitemap type') |
|---|
| 44 |
self.assert_('mobile-sitemap.xml' in views, |
|---|
| 45 |
'No "mobile-sitemap.xml" view for Sitemap type') |
|---|
| 46 |
self.assert_('news-sitemap.xml' in views, |
|---|
| 47 |
'No "news-sitemap.xml" view for Sitemap type') |
|---|
| 48 |
|
|---|
| 49 |
def testGSMProperties(self): |
|---|
| 50 |
pp = self.portal.portal_properties |
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
self.assert_("Sitemap" in pp['site_properties'].getProperty('types_not_searched'), |
|---|
| 54 |
'No "Sitemap" added to types not searched on installation') |
|---|
| 55 |
|
|---|
| 56 |
self.assert_("Sitemap" in pp['navtree_properties'].getProperty('metaTypesNotToList'), |
|---|
| 57 |
'No "Sitemap" added to types not to list on installation') |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
self.assert_('googlesitemap_properties' in pp.objectIds(), |
|---|
| 61 |
'No "googlesitemap_properties" after installation') |
|---|
| 62 |
qsmprops = pp['googlesitemap_properties'] |
|---|
| 63 |
self.assert_(qsmprops.hasProperty('verification_filenames'), |
|---|
| 64 |
'No "verification_filenames" property added on installation') |
|---|
| 65 |
|
|---|
| 66 |
def testSkins(self): |
|---|
| 67 |
ps = self.portal.portal_skins |
|---|
| 68 |
self.assert_('qPloneGoogleSitemaps' in ps.objectIds(), |
|---|
| 69 |
'No "qPloneGoogleSitemaps" skin layer in portal_skins') |
|---|
| 70 |
self.assert_('qPloneGoogleSitemaps' in ps.getSkinPath(ps.getDefaultSkin()), |
|---|
| 71 |
'No "qPloneGoogleSitemaps" skin layer in default skin') |
|---|
| 72 |
|
|---|
| 73 |
def testConfiglet(self): |
|---|
| 74 |
cp = self.portal.portal_controlpanel |
|---|
| 75 |
self.assert_([1 for ai in cp.listActionInfos() if ai['id']=='qPloneGoogleSitemaps'], |
|---|
| 76 |
'No "qPloneGoogleSitemaps" configlet added to plone control panel') |
|---|
| 77 |
|
|---|
| 78 |
def testCatalog(self): |
|---|
| 79 |
catalog = self.portal.portal_catalog |
|---|
| 80 |
self.assert_('hasMobileContent' in catalog.indexes(), |
|---|
| 81 |
'No "hasMobileContent" index in portal_catalog') |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
class TestSitemapType(PloneTestCase.FunctionalTestCase): |
|---|
| 85 |
|
|---|
| 86 |
def afterSetUp(self): |
|---|
| 87 |
self.loginAsPortalOwner() |
|---|
| 88 |
self.auth = 'admin:admin' |
|---|
| 89 |
self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') |
|---|
| 90 |
self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
|---|
| 91 |
|
|---|
| 92 |
def testFields(self): |
|---|
| 93 |
field_ids = map(lambda x:x.getName(), self.contentSM.Schema().fields()) |
|---|
| 94 |
|
|---|
| 95 |
self.assert_('id' in field_ids) |
|---|
| 96 |
self.assert_('portalTypes' in field_ids) |
|---|
| 97 |
self.assert_('states' in field_ids) |
|---|
| 98 |
self.assert_('blackout_list' in field_ids) |
|---|
| 99 |
self.assert_('urls' in field_ids) |
|---|
| 100 |
self.assert_('pingTransitions' in field_ids) |
|---|
| 101 |
|
|---|
| 102 |
self.assert_('sitemapType' in field_ids) |
|---|
| 103 |
|
|---|
| 104 |
def testSitemapTypes(self): |
|---|
| 105 |
sitemap_types = self.contentSM.getField('sitemapType').Vocabulary().keys() |
|---|
| 106 |
self.assert_('content' in sitemap_types) |
|---|
| 107 |
self.assert_('mobile' in sitemap_types) |
|---|
| 108 |
self.assert_('news' in sitemap_types) |
|---|
| 109 |
|
|---|
| 110 |
def testAutoSetLayout(self): |
|---|
| 111 |
response = self.publish('/%s/createObject?type_name=Sitemap' % \ |
|---|
| 112 |
self.portal.absolute_url(1), basic=self.auth) |
|---|
| 113 |
location = response.getHeader('location') |
|---|
| 114 |
newurl = location[location.find('/'+self.portal.absolute_url(1)):] |
|---|
| 115 |
|
|---|
| 116 |
msm_id = 'mobile_sitemap' |
|---|
| 117 |
form = {'id': msm_id, |
|---|
| 118 |
'sitemapType':'mobile', |
|---|
| 119 |
'portalTypes':['Document',], |
|---|
| 120 |
'states':['published'], |
|---|
| 121 |
'form_submit':'Save', |
|---|
| 122 |
'form.submitted':1, |
|---|
| 123 |
} |
|---|
| 124 |
post_data = StringIO(urlencode(form)) |
|---|
| 125 |
response = self.publish(newurl, request_method='POST', stdin=post_data, basic=self.auth) |
|---|
| 126 |
msitemap = getattr(self.portal, msm_id) |
|---|
| 127 |
|
|---|
| 128 |
self.assertEqual(msitemap.defaultView(), 'mobile-sitemap.xml') |
|---|
| 129 |
|
|---|
| 130 |
def txestPingSetting(self): |
|---|
| 131 |
pwf = self.portal.portal_workflow['plone_workflow'] |
|---|
| 132 |
self.assertEqual(self.contentSM.getPingTransitions(), ()) |
|---|
| 133 |
|
|---|
| 134 |
self.contentSM.setPingTransitions(('plone_workflow#publish',)) |
|---|
| 135 |
self.assertEqual(self.contentSM.getPingTransitions(), ('plone_workflow#publish',)) |
|---|
| 136 |
self.assert_(ping_googlesitemap in pwf.scripts.keys(),"Not add wf script") |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
class TestqPloneGoogleSitemaps(PloneTestCase.FunctionalTestCase): |
|---|
| 140 |
|
|---|
| 141 |
def afterSetUp(self): |
|---|
| 142 |
self.loginAsPortalOwner() |
|---|
| 143 |
|
|---|
| 144 |
self.workflow = self.portal.portal_workflow |
|---|
| 145 |
self.auth = 'admin:admin' |
|---|
| 146 |
_createObjectByType('Sitemap', self.portal, id='google-sitemaps') |
|---|
| 147 |
self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' |
|---|
| 148 |
self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
|---|
| 149 |
self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
my_doc = self.portal.invokeFactory('Document', id='my_doc') |
|---|
| 153 |
self.my_doc = self.portal['my_doc'] |
|---|
| 154 |
self.my_doc.edit(text_format='plain', text='hello world') |
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
def testSitemap(self): |
|---|
| 159 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 160 |
parsed_sitemap = parse(sitemap) |
|---|
| 161 |
start = parsed_sitemap['start'] |
|---|
| 162 |
data = parsed_sitemap['data'] |
|---|
| 163 |
self.assertEqual(len(start.keys()), 1) |
|---|
| 164 |
self.assert_('urlset' in start.keys()) |
|---|
| 165 |
|
|---|
| 166 |
self.workflow.doActionFor(self.my_doc, 'publish') |
|---|
| 167 |
|
|---|
| 168 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 169 |
parsed_sitemap = parse(sitemap) |
|---|
| 170 |
start = parsed_sitemap['start'] |
|---|
| 171 |
data = parsed_sitemap['data'] |
|---|
| 172 |
self.assertEqual(len(start.keys()), 4) |
|---|
| 173 |
self.assert_('urlset' in start.keys()) |
|---|
| 174 |
self.assert_('url' in start.keys()) |
|---|
| 175 |
self.assert_('loc' in start.keys()) |
|---|
| 176 |
self.assert_('lastmod' in start.keys()) |
|---|
| 177 |
|
|---|
| 178 |
self.assert_(data[0] == self.my_doc.absolute_url(0), 'Incorect url') |
|---|
| 179 |
|
|---|
| 180 |
def testVerificationFileCreation(self): |
|---|
| 181 |
self.portal.gsm_create_verify_file('verif_file') |
|---|
| 182 |
|
|---|
| 183 |
vf_created = hasattr(self.portal, 'verif_file') |
|---|
| 184 |
self.assert_(vf_created, 'Verification file not created') |
|---|
| 185 |
|
|---|
| 186 |
def testVerificationForm(self): |
|---|
| 187 |
verifyConfigUrl = '/'+self.portal.absolute_url(1) + '/prefs_gsm_verification' |
|---|
| 188 |
verif_config = self.publish(verifyConfigUrl, self.auth).getBody() |
|---|
| 189 |
rexp_input_acitve = re.compile('<input\s+name="verify_filename"\s+([^>]*)>', re.I|re.S) |
|---|
| 190 |
rexp_button_acitve = re.compile('<input\s+name="form.button.CreateFile"\s+([^>]*)>', re.I|re.S) |
|---|
| 191 |
rexp_delete_button = re.compile('<input\s+name="form.button.DeleteFile"\s+[^>]*>', re.I|re.S) |
|---|
| 192 |
|
|---|
| 193 |
input_acitve = rexp_input_acitve.search(verif_config) |
|---|
| 194 |
button_acitve = rexp_button_acitve.search(verif_config) |
|---|
| 195 |
delete_button = rexp_delete_button.match(verif_config) |
|---|
| 196 |
|
|---|
| 197 |
self.assert_(input_acitve and not 'disabled' in input_acitve.groups(1)) |
|---|
| 198 |
self.assert_(button_acitve and not 'disabled' in button_acitve.groups(1)) |
|---|
| 199 |
self.assert_(not delete_button) |
|---|
| 200 |
|
|---|
| 201 |
self.portal.gsm_create_verify_file('verif_file') |
|---|
| 202 |
|
|---|
| 203 |
input_acitve = rexp_input_acitve.search(verif_config) |
|---|
| 204 |
button_acitve = rexp_button_acitve.search(verif_config) |
|---|
| 205 |
delete_button = rexp_delete_button.match(verif_config) |
|---|
| 206 |
|
|---|
| 207 |
verif_config = self.publish(verifyConfigUrl, self.auth).getBody() |
|---|
| 208 |
self.assert_(input_acitve and not 'disabled' in input_acitve.groups(1)) |
|---|
| 209 |
self.assert_(not delete_button) |
|---|
| 210 |
|
|---|
| 211 |
def testMultiplyVerificationFiles(self): |
|---|
| 212 |
verifyConfigUrl = '/'+self.portal.absolute_url(1) + '/prefs_gsm_verification' |
|---|
| 213 |
|
|---|
| 214 |
form = {'verify_filename':'verif_file_1', |
|---|
| 215 |
'form.button.CreateFile': 'Create verification file', |
|---|
| 216 |
'form.submitted':1} |
|---|
| 217 |
post_data = StringIO(urlencode(form)) |
|---|
| 218 |
response = self.publish(verifyConfigUrl, request_method='POST', |
|---|
| 219 |
stdin=post_data, basic=self.auth) |
|---|
| 220 |
self.assertEqual(response.getStatus(), 200) |
|---|
| 221 |
self.assert_('verif_file_1' in self.gsm_props.getProperty('verification_filenames',[]), |
|---|
| 222 |
self.gsm_props.getProperty('verification_filenames',[])) |
|---|
| 223 |
|
|---|
| 224 |
form = {'verify_filename':'verif_file_2', |
|---|
| 225 |
'form.button.CreateFile': 'Create verification file', |
|---|
| 226 |
'form.submitted':1} |
|---|
| 227 |
post_data = StringIO(urlencode(form)) |
|---|
| 228 |
response = self.publish(verifyConfigUrl, request_method='POST', |
|---|
| 229 |
stdin=post_data, basic=self.auth) |
|---|
| 230 |
self.assertEqual(response.getStatus(), 200) |
|---|
| 231 |
self.assert_([1 for vf in ['verif_file','verif_file_2'] \ |
|---|
| 232 |
if vf in self.gsm_props.getProperty('verification_filenames',[])], |
|---|
| 233 |
self.gsm_props.getProperty('verification_filenames',[])) |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
class TestSettings(PloneTestCase.FunctionalTestCase): |
|---|
| 237 |
|
|---|
| 238 |
def afterSetUp(self): |
|---|
| 239 |
self.loginAsPortalOwner() |
|---|
| 240 |
|
|---|
| 241 |
self.workflow = self.portal.portal_workflow |
|---|
| 242 |
self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] |
|---|
| 243 |
self.auth = 'admin:admin' |
|---|
| 244 |
self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') |
|---|
| 245 |
|
|---|
| 246 |
self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' |
|---|
| 247 |
|
|---|
| 248 |
self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
my_doc = self.portal.invokeFactory('Document', id='my_doc') |
|---|
| 252 |
self.my_doc = self.portal['my_doc'] |
|---|
| 253 |
self.my_doc.edit(text_format='plain', text='hello world') |
|---|
| 254 |
self.my_doc_url = self.my_doc.absolute_url() |
|---|
| 255 |
|
|---|
| 256 |
def testMetaTypeToDig(self): |
|---|
| 257 |
self.workflow.doActionFor(self.my_doc, 'publish') |
|---|
| 258 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 259 |
self.assert_(hasURL(sitemap, self.my_doc_url)) |
|---|
| 260 |
|
|---|
| 261 |
self.contentSM.setPortalTypes([]) |
|---|
| 262 |
|
|---|
| 263 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 264 |
self.assert_(not hasURL(sitemap, self.my_doc_url)) |
|---|
| 265 |
|
|---|
| 266 |
self.contentSM.setPortalTypes(['Document']) |
|---|
| 267 |
|
|---|
| 268 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 269 |
self.assert_(hasURL(sitemap, self.my_doc_url)) |
|---|
| 270 |
|
|---|
| 271 |
def testStates(self): |
|---|
| 272 |
self.workflow.doActionFor(self.my_doc, 'publish') |
|---|
| 273 |
self.contentSM.setStates(['visible']) |
|---|
| 274 |
|
|---|
| 275 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 276 |
self.assert_(not hasURL(sitemap, self.my_doc_url)) |
|---|
| 277 |
|
|---|
| 278 |
self.contentSM.setStates(['published']) |
|---|
| 279 |
|
|---|
| 280 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 281 |
self.assert_(hasURL(sitemap, self.my_doc_url)) |
|---|
| 282 |
|
|---|
| 283 |
def test_blackout_entries(self): |
|---|
| 284 |
self.workflow.doActionFor(self.my_doc, 'publish') |
|---|
| 285 |
self.contentSM.setBlackout_list((self.my_doc.getId(),)) |
|---|
| 286 |
|
|---|
| 287 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 288 |
self.assert_(not hasURL(sitemap, self.my_doc_url)) |
|---|
| 289 |
|
|---|
| 290 |
self.contentSM.setBlackout_list([]) |
|---|
| 291 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 292 |
self.assert_(hasURL(sitemap, self.my_doc_url)) |
|---|
| 293 |
|
|---|
| 294 |
def test_regexp(self): |
|---|
| 295 |
self.workflow.doActionFor(self.my_doc, 'publish') |
|---|
| 296 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 297 |
self.assert_(not hasURL(sitemap, self.portal.absolute_url())) |
|---|
| 298 |
|
|---|
| 299 |
regexp = "s/\/%s//"%self.my_doc.getId() |
|---|
| 300 |
self.contentSM.setReg_exp([regexp]) |
|---|
| 301 |
|
|---|
| 302 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 303 |
self.assert_(hasURL(sitemap, self.portal.absolute_url())) |
|---|
| 304 |
|
|---|
| 305 |
def test_add_urls(self): |
|---|
| 306 |
self.contentSM.setUrls(['http://w1', 'w2', '/w3']) |
|---|
| 307 |
w1_url = 'http://w1' |
|---|
| 308 |
w2_url = self.portal.absolute_url() + '/w2' |
|---|
| 309 |
w3_url = self.portal.getPhysicalRoot().absolute_url() + '/w3' |
|---|
| 310 |
sitemap = self.publish(self.sitemapUrl, self.auth).getBody() |
|---|
| 311 |
|
|---|
| 312 |
self.assert_(hasURL(sitemap, w1_url)) |
|---|
| 313 |
self.assert_(hasURL(sitemap, w2_url)) |
|---|
| 314 |
self.assert_(hasURL(sitemap, w3_url)) |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
class TestPinging(PloneTestCase.FunctionalTestCase): |
|---|
| 318 |
|
|---|
| 319 |
def afterSetUp(self): |
|---|
| 320 |
self.loginAsPortalOwner() |
|---|
| 321 |
|
|---|
| 322 |
self.workflow = self.portal.portal_workflow |
|---|
| 323 |
self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] |
|---|
| 324 |
self.auth = 'admin:admin' |
|---|
| 325 |
self.portal.portal_membership.addMember('admin', 'admin', ('Manager',), []) |
|---|
| 326 |
|
|---|
| 327 |
self.contentSM = _createObjectByType('Sitemap', self.po |
|---|