/usr/share/pyshared/zope/site/testing.py is in python-zope.site 3.9.2-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | ##############################################################################
#
# Copyright (c) 2001-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Reusable functionality for testing site-related code
"""
import zope.component
import zope.component.hooks
import zope.component.interfaces
import zope.container.interfaces
import zope.container.testing
import zope.site.site
from zope.component.interfaces import IComponentLookup
from zope.interface import Interface
from zope.site import LocalSiteManager, SiteManagerAdapter
from zope.site.folder import rootFolder
def createSiteManager(folder, setsite=False):
if not zope.component.interfaces.ISite.providedBy(folder):
folder.setSiteManager(LocalSiteManager(folder))
if setsite:
zope.component.hooks.setSite(folder)
return folder.getSiteManager()
def addUtility(sitemanager, name, iface, utility, suffix=''):
"""Add a utility to a site manager
This helper function is useful for tests that need to set up utilities.
"""
folder_name = (name or (iface.__name__ + 'Utility')) + suffix
default = sitemanager['default']
default[folder_name] = utility
utility = default[folder_name]
sitemanager.registerUtility(utility, iface, name)
return utility
def siteSetUp(site=False):
zope.container.testing.setUp()
zope.component.hooks.setHooks()
zope.component.provideAdapter(
SiteManagerAdapter, (Interface,), IComponentLookup)
if site:
site = rootFolder()
createSiteManager(site, setsite=True)
return site
def siteTearDown():
zope.container.testing.tearDown()
zope.component.hooks.resetHooks()
zope.component.hooks.setSite()
|