source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/base.py @ 3152

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

fixes pep8

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1#
2# Tests for quintagroup.plonegooglesitemaps
3#
4
5import re
6import sys
7from urllib import urlencode
8from StringIO import StringIO
9import unittest
10
11from zope.testing import doctestunit
12from zope.interface import Interface
13from zope.component import testing
14from zope.interface import alsoProvides
15from Testing import ZopeTestCase as ztc
16
17from Products.Five import zcml
18from Products.Five import fiveconfigure
19
20from Products.PloneTestCase import PloneTestCase as ptc
21from Products.PloneTestCase.layer import onsetup
22from Products.PloneTestCase.layer import PloneSite
23from Products.PloneTestCase.setup import portal_owner
24from Products.PloneTestCase.setup import default_password
25
26from XMLParser import parse, hasURL
27
28import quintagroup.plonegooglesitemaps
29from quintagroup.plonegooglesitemaps.config import PROJECTNAME
30from quintagroup.plonegooglesitemaps.config import ping_googlesitemap
31from quintagroup.plonegooglesitemaps.config import SUPPORT_BLAYER
32from quintagroup.plonegooglesitemaps.browser import mobilesitemapview
33from quintagroup.plonegooglesitemaps.interfaces import IGoogleSitemapsLayer
34
35from collective.testcaselayer.ptc import BasePTCLayer, ptc_layer
36
37quintagroup.plonegooglesitemaps.config.testing = 1
38quintagroup.plonegooglesitemaps.config.UPDATE_CATALOG = True
39
40PRODUCT = 'quintagroup.plonegooglesitemaps'
41
42
43class NotInstalled(BasePTCLayer):
44    """Initialize the package, without installation into portal
45    """
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
52
53        if not ptc.PLONE31:
54            ztc.installProduct("plone.browserlayer")
55
56        ztc.installPackage(PRODUCT)
57
58
59class 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
67
68class UnInstalled(BasePTCLayer):
69    """ UnInstall product from the portal
70    """
71    def afterSetUp(self):
72        qi = getattr(self.portal, 'portal_quickinstaller', None)
73        qi.uninstallProducts(products=[PRODUCT, ])
74
75
76NotInstalledLayer = NotInstalled([ptc_layer, ])
77InstalledLayer = Installed([NotInstalledLayer, ])
78UnInstalledLayer = UnInstalled([InstalledLayer, ])
79
80
81class IMobileMarker(Interface):
82    """Test Marker interface for mobile objects"""
83
84
85class MixinTestCase(object):
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()
92        self.workflow = self.portal.portal_workflow
93        self.orig_mobile_ifaces = None
94        alsoProvides(self.portal.REQUEST, IGoogleSitemapsLayer)
95
96    def patchMobile(self):
97        # patch mobile sitemap view
98        self.orig_mobile_ifaces = mobilesitemapview.MOBILE_INTERFACES
99        mobilesitemapview.MOBILE_INTERFACES = [IMobileMarker.__identifier__, ]
100
101    def beforeTearDown(self):
102        if getattr(self, 'orig_mobile_ifaces', None) is not None:
103            mobilesitemapview.MOBILE_INTERFACES = self.orig_mobile_ifaces
104
105
106class TestCaseNotInstalled(ptc.PloneTestCase):
107    layer = NotInstalledLayer
108
109
110class TestCase(ptc.PloneTestCase, MixinTestCase):
111    layer = InstalledLayer
112
113    def afterSetUp(self):
114        ptc.PloneTestCase.afterSetUp(self)
115        MixinTestCase.afterSetUp(self)
116
117    def beforeTearDown(self):
118        ptc.PloneTestCase.beforeTearDown(self)
119        MixinTestCase.beforeTearDown(self)
120
121
122class TestCaseUnInstalled(ptc.PloneTestCase):
123    layer = UnInstalledLayer
124
125
126class FunctionalTestCaseNotInstalled(ptc.FunctionalTestCase):
127    layer = NotInstalledLayer
128
129
130class FunctionalTestCase(ptc.FunctionalTestCase, MixinTestCase):
131    layer = InstalledLayer
132
133    def afterSetUp(self):
134        ptc.FunctionalTestCase.afterSetUp(self)
135        MixinTestCase.afterSetUp(self)
136        self.auth = "%s:%s" % (portal_owner, default_password)
137
138    def beforeTearDown(self):
139        ptc.FunctionalTestCase.beforeTearDown(self)
140        MixinTestCase.beforeTearDown(self)
141
142
143class FunctionalTestCaseUnInstalled(ptc.FunctionalTestCase):
144    layer = UnInstalledLayer
Note: See TracBrowser for help on using the repository browser.