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