source: products/quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests/base.py @ 2991

Last change on this file since 2991 was 2991, checked in by mylan, 14 years ago

#228: Fixed ran of tearing down testing layers

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1#
2# Tests for quintagroup.plonegooglesitemaps
3#
4
5import re, sys
6from urllib import urlencode
7from StringIO import StringIO
8import unittest
9
10from zope.testing import doctestunit
11from zope.interface import Interface
12from zope.component import testing
13from zope.interface import alsoProvides
14from Testing import ZopeTestCase as ztc
15
16from Products.Five import zcml
17from Products.Five import fiveconfigure
18
19from Products.PloneTestCase import PloneTestCase as ptc
20from Products.PloneTestCase.layer import onsetup
21from Products.PloneTestCase.layer import PloneSite
22from Products.PloneTestCase.setup import portal_owner
23from Products.PloneTestCase.setup import default_password
24
25from XMLParser import parse, hasURL
26
27import quintagroup.plonegooglesitemaps
28from quintagroup.plonegooglesitemaps.config import PROJECTNAME
29from quintagroup.plonegooglesitemaps.config import ping_googlesitemap
30from quintagroup.plonegooglesitemaps.config import SUPPORT_BLAYER
31from quintagroup.plonegooglesitemaps.browser import mobilesitemapview
32from quintagroup.plonegooglesitemaps.interfaces import IGoogleSitemapsLayer
33
34quintagroup.plonegooglesitemaps.config.testing = 1
35quintagroup.plonegooglesitemaps.config.UPDATE_CATALOG = True
36
37PRODUCT = 'quintagroup.plonegooglesitemaps'
38
39@onsetup
40def setup_product():
41    """Set up the package and its dependencies.
42
43    The @onsetup decorator causes the execution of this body to be
44    deferred until the setup of the Plone site testing layer. We could
45    have created our own layer, but this is the easiest way for Plone
46    integration tests.
47    """
48    fiveconfigure.debug_mode = True
49    import quintagroup.plonegooglesitemaps
50    zcml.load_config('configure.zcml', quintagroup.plonegooglesitemaps)
51    zcml.load_config('overrides.zcml', quintagroup.plonegooglesitemaps)
52    fiveconfigure.debug_mode = False
53
54    if not ptc.PLONE31:
55        ztc.installPackage("plone.browserlayer")
56
57    ztc.installPackage(PRODUCT)
58
59setup_product()
60ptc.setupPloneSite( products=(PRODUCT,))
61
62
63class IMobileMarker(Interface):
64    """Test Marker interface for mobile objects"""
65
66
67class MixinTestCase(object):
68    """ Define layer and common afterSetup method with package installation.
69        Package installation on plone site setup impossible because of
70        five's registerPackage directive not recognized on module initializing.
71    """
72    layer = PloneSite
73
74    def afterSetUp(self):
75        self.loginAsPortalOwner()
76        self.workflow = self.portal.portal_workflow
77        self.orig_mobile_ifaces = None
78        alsoProvides(self.portal.REQUEST, IGoogleSitemapsLayer)
79
80    def patchMobile(self):
81        # patch mobile sitemap view
82        self.orig_mobile_ifaces = mobilesitemapview.MOBILE_INTERFACES
83        mobilesitemapview.MOBILE_INTERFACES = [IMobileMarker.__identifier__,]
84
85    def beforeTearDown(self):
86        if getattr(self, 'orig_mobile_ifaces', None) is not None:
87            mobilesitemapview.MOBILE_INTERFACES = self.orig_mobile_ifaces
88
89
90class TestCase(MixinTestCase, ptc.PloneTestCase):
91    """ For unit tests """
92   
93    def afterSetUp(self):
94        MixinTestCase.afterSetUp(self)
95        ptc.PloneTestCase.afterSetUp(self)
96
97    def beforeTearDown(self):
98        MixinTestCase.beforeTearDown(self)
99        ptc.PloneTestCase.beforeTearDown(self)
100
101
102
103class FunctionalTestCase(MixinTestCase, ptc.FunctionalTestCase):
104    """ For functional tests """
105
106    def afterSetUp(self):
107        MixinTestCase.afterSetUp(self)
108        ptc.FunctionalTestCase.afterSetUp(self)
109        self.auth = "%s:%s" % (portal_owner, default_password)
110
111    def beforeTearDown(self):
112        MixinTestCase.beforeTearDown(self)
113        ptc.FunctionalTestCase.beforeTearDown(self)
114
Note: See TracBrowser for help on using the repository browser.