[2382] | 1 | # |
---|
| 2 | # Tests for quintagroup.plonegooglesitemaps |
---|
| 3 | # |
---|
| 4 | |
---|
[3152] | 5 | import re |
---|
| 6 | import sys |
---|
[2382] | 7 | from urllib import urlencode |
---|
| 8 | from StringIO import StringIO |
---|
| 9 | import unittest |
---|
| 10 | |
---|
| 11 | from zope.testing import doctestunit |
---|
[2538] | 12 | from zope.interface import Interface |
---|
[2382] | 13 | from zope.component import testing |
---|
[2841] | 14 | from zope.interface import alsoProvides |
---|
[2382] | 15 | from Testing import ZopeTestCase as ztc |
---|
| 16 | |
---|
| 17 | from Products.Five import zcml |
---|
| 18 | from Products.Five import fiveconfigure |
---|
| 19 | |
---|
| 20 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
[2555] | 21 | from Products.PloneTestCase.layer import onsetup |
---|
[2382] | 22 | from Products.PloneTestCase.layer import PloneSite |
---|
[2394] | 23 | from Products.PloneTestCase.setup import portal_owner |
---|
| 24 | from Products.PloneTestCase.setup import default_password |
---|
[2382] | 25 | |
---|
| 26 | from XMLParser import parse, hasURL |
---|
| 27 | |
---|
| 28 | import quintagroup.plonegooglesitemaps |
---|
[2386] | 29 | from quintagroup.plonegooglesitemaps.config import PROJECTNAME |
---|
[2382] | 30 | from quintagroup.plonegooglesitemaps.config import ping_googlesitemap |
---|
[3152] | 31 | from quintagroup.plonegooglesitemaps.config import SUPPORT_BLAYER |
---|
[2538] | 32 | from quintagroup.plonegooglesitemaps.browser import mobilesitemapview |
---|
[2841] | 33 | from quintagroup.plonegooglesitemaps.interfaces import IGoogleSitemapsLayer |
---|
[2382] | 34 | |
---|
[3002] | 35 | from collective.testcaselayer.ptc import BasePTCLayer, ptc_layer |
---|
| 36 | |
---|
[2382] | 37 | quintagroup.plonegooglesitemaps.config.testing = 1 |
---|
| 38 | quintagroup.plonegooglesitemaps.config.UPDATE_CATALOG = True |
---|
| 39 | |
---|
[2555] | 40 | PRODUCT = 'quintagroup.plonegooglesitemaps' |
---|
[2382] | 41 | |
---|
[2555] | 42 | |
---|
[3002] | 43 | class NotInstalled(BasePTCLayer): |
---|
| 44 | """Initialize the package, without installation into portal |
---|
[2555] | 45 | """ |
---|
[3002] | 46 | def afterSetUp(self): |
---|
| 47 | fiveconfigure.debug_mode = True |
---|
| 48 | import quintagroup.plonegooglesitemaps |
---|
| 49 | zcml.load_config('configure.zcml', quintagroup.plonegooglesitemaps) |
---|
| 50 | zcml.load_config('overrides.zcml', quintagroup.plonegooglesitemaps) |
---|
| 51 | fiveconfigure.debug_mode = False |
---|
[2555] | 52 | |
---|
[3002] | 53 | if not ptc.PLONE31: |
---|
| 54 | ztc.installProduct("plone.browserlayer") |
---|
[2555] | 55 | |
---|
[3002] | 56 | ztc.installPackage(PRODUCT) |
---|
[2555] | 57 | |
---|
| 58 | |
---|
[3002] | 59 | class Installed(BasePTCLayer): |
---|
| 60 | """ Install product into the portal |
---|
| 61 | """ |
---|
| 62 | def afterSetUp(self): |
---|
| 63 | if not ptc.PLONE31: |
---|
| 64 | self.addProduct("plone.browserlayer") |
---|
| 65 | self.addProduct(PRODUCT) |
---|
| 66 | |
---|
[3152] | 67 | |
---|
[3002] | 68 | class UnInstalled(BasePTCLayer): |
---|
| 69 | """ UnInstall product from the portal |
---|
| 70 | """ |
---|
| 71 | def afterSetUp(self): |
---|
| 72 | qi = getattr(self.portal, 'portal_quickinstaller', None) |
---|
[3152] | 73 | qi.uninstallProducts(products=[PRODUCT, ]) |
---|
[3002] | 74 | |
---|
| 75 | |
---|
[3152] | 76 | NotInstalledLayer = NotInstalled([ptc_layer, ]) |
---|
| 77 | InstalledLayer = Installed([NotInstalledLayer, ]) |
---|
| 78 | UnInstalledLayer = UnInstalled([InstalledLayer, ]) |
---|
[3002] | 79 | |
---|
| 80 | |
---|
[2538] | 81 | class IMobileMarker(Interface): |
---|
| 82 | """Test Marker interface for mobile objects""" |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | class MixinTestCase(object): |
---|
[2382] | 86 | """ Define layer and common afterSetup method with package installation. |
---|
| 87 | Package installation on plone site setup impossible because of |
---|
| 88 | five's registerPackage directive not recognized on module initializing. |
---|
| 89 | """ |
---|
| 90 | def afterSetUp(self): |
---|
| 91 | self.loginAsPortalOwner() |
---|
[2538] | 92 | self.workflow = self.portal.portal_workflow |
---|
| 93 | self.orig_mobile_ifaces = None |
---|
[2841] | 94 | alsoProvides(self.portal.REQUEST, IGoogleSitemapsLayer) |
---|
[2382] | 95 | |
---|
[2538] | 96 | def patchMobile(self): |
---|
| 97 | # patch mobile sitemap view |
---|
| 98 | self.orig_mobile_ifaces = mobilesitemapview.MOBILE_INTERFACES |
---|
[3152] | 99 | mobilesitemapview.MOBILE_INTERFACES = [IMobileMarker.__identifier__, ] |
---|
[2382] | 100 | |
---|
[2538] | 101 | def beforeTearDown(self): |
---|
[3002] | 102 | if getattr(self, 'orig_mobile_ifaces', None) is not None: |
---|
[2538] | 103 | mobilesitemapview.MOBILE_INTERFACES = self.orig_mobile_ifaces |
---|
| 104 | |
---|
| 105 | |
---|
[3002] | 106 | class TestCaseNotInstalled(ptc.PloneTestCase): |
---|
| 107 | layer = NotInstalledLayer |
---|
[2382] | 108 | |
---|
[3152] | 109 | |
---|
[3002] | 110 | class TestCase(ptc.PloneTestCase, MixinTestCase): |
---|
| 111 | layer = InstalledLayer |
---|
[2538] | 112 | |
---|
[3002] | 113 | def afterSetUp(self): |
---|
| 114 | ptc.PloneTestCase.afterSetUp(self) |
---|
| 115 | MixinTestCase.afterSetUp(self) |
---|
[2382] | 116 | |
---|
[3002] | 117 | def beforeTearDown(self): |
---|
| 118 | ptc.PloneTestCase.beforeTearDown(self) |
---|
| 119 | MixinTestCase.beforeTearDown(self) |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | class TestCaseUnInstalled(ptc.PloneTestCase): |
---|
| 123 | layer = UnInstalledLayer |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | class FunctionalTestCaseNotInstalled(ptc.FunctionalTestCase): |
---|
| 127 | layer = NotInstalledLayer |
---|
| 128 | |
---|
[3152] | 129 | |
---|
[3002] | 130 | class FunctionalTestCase(ptc.FunctionalTestCase, MixinTestCase): |
---|
| 131 | layer = InstalledLayer |
---|
| 132 | |
---|
[2538] | 133 | def afterSetUp(self): |
---|
[3002] | 134 | ptc.FunctionalTestCase.afterSetUp(self) |
---|
| 135 | MixinTestCase.afterSetUp(self) |
---|
[2538] | 136 | self.auth = "%s:%s" % (portal_owner, default_password) |
---|
| 137 | |
---|
[3002] | 138 | def beforeTearDown(self): |
---|
| 139 | ptc.FunctionalTestCase.beforeTearDown(self) |
---|
| 140 | MixinTestCase.beforeTearDown(self) |
---|
| 141 | |
---|
[3152] | 142 | |
---|
[3002] | 143 | class FunctionalTestCaseUnInstalled(ptc.FunctionalTestCase): |
---|
| 144 | layer = UnInstalledLayer |
---|