Ignore:
Timestamp:
3 Feb 2012, 14:53:04 (13 years ago)
Author:
uli
Message:

Register/unregister IDataCenterConfig utility in non-functional tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/testing.py

    r7321 r7581  
    2323import os.path
    2424import re
     25import tempfile
     26import shutil
    2527import unittest
    2628import warnings
     
    2931from zope.app.testing.functional import (
    3032    ZCMLLayer, FunctionalTestSetup, getRootFolder, sync, FunctionalTestCase)
    31 from zope.component import getGlobalSiteManager
     33from zope.component import getGlobalSiteManager, queryUtility
    3234from zope.security.testing import addCheckerPublic
    3335from zope.testing import renormalizing
     
    186188    return True
    187189
     190def setup_datacenter_conf():
     191    """Register a datacenter config utility for non-functional tests.
     192    """
     193    from waeup.sirp.interfaces import IDataCenterConfig
     194    conf = queryUtility(IDataCenterConfig)
     195    if conf is not None:
     196        return
     197    path = tempfile.mkdtemp()
     198    conf = {'path': path}
     199    gsm = getGlobalSiteManager()
     200    gsm.registerUtility(conf, IDataCenterConfig)
     201    return
     202
     203def teardown_datacenter_conf():
     204    """Unregister a datacenter config utility for non-functional tests.
     205    """
     206    from waeup.sirp.interfaces import IDataCenterConfig
     207    conf = queryUtility(IDataCenterConfig)
     208    if conf is None:
     209        return
     210    path = conf['path']
     211    shutil.rmtree(path)
     212    gsm = getGlobalSiteManager()
     213    gsm.unregisterUtility(conf)
     214    return
    188215
    189216class SIRPUnitTestLayer(object):
     
    226253        #setUpZope(None)
    227254        grokked = maybe_grok()
    228         if grokked:
    229             pass
    230             #setUpZope(None)
     255        setup_datacenter_conf()
    231256        return
    232257
     
    234259    def tearDown(cls):
    235260        cleanUpZope(None)
     261        teardown_datacenter_conf()
     262        return
     263
    236264
    237265#: This extended :class:`doctest.OutputChecker` allows the following
Note: See TracChangeset for help on using the changeset viewer.