/usr/share/pyshared/zope/site/tests/test_site.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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | ##############################################################################
#
# Copyright (c) 2004 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.
#
##############################################################################
"""Registration Tests
"""
__docformat__ = "reStructuredText"
import doctest
import unittest
import zope.interface
import zope.interface.verify
from zope.component.interfaces import ISite, IPossibleSite
from zope.site import folder
from zope.site import interfaces
from zope import site
from zope.site import testing
class SiteManagerStub(object):
zope.interface.implements(interfaces.ILocalSiteManager)
class CustomFolder(folder.Folder):
def __init__(self, name):
self.__name__ = name
super(CustomFolder, self).__init__()
def __repr__(self):
return '<%s %s>' %(self.__class__.__name__, self.__name__)
def test_SiteManagerAdapter():
"""
The site manager adapter is used to find the nearest site for any given
location. If the provided context is a site,
>>> site = folder.Folder()
>>> sm = SiteManagerStub()
>>> site.setSiteManager(sm)
then the adapter simply return's the site's site manager:
>>> from zope.site import SiteManagerAdapter
>>> SiteManagerAdapter(site) is sm
True
If the context is a location (i.e. has a `__parent__` attribute),
>>> ob = folder.Folder()
>>> ob.__parent__ = site
>>> ob2 = folder.Folder()
>>> ob2.__parent__ = ob
we 'acquire' the closest site and return its site manager:
>>> SiteManagerAdapter(ob) is sm
True
>>> SiteManagerAdapter(ob2) is sm
True
If we are unable to find a local site manager, then the global site
manager is returned.
>>> import zope.component
>>> orphan = CustomFolder('orphan')
>>> SiteManagerAdapter(orphan) is zope.component.getGlobalSiteManager()
True
"""
class BaseTestSiteManagerContainer(unittest.TestCase):
"""This test is for objects that don't have site managers by
default and that always give back the site manager they were
given.
Subclasses need to define a method, 'makeTestObject', that takes no
arguments and that returns a new site manager
container that has no site manager."""
def test_IPossibleSite_verify(self):
zope.interface.verify.verifyObject(IPossibleSite,
self.makeTestObject())
def test_get_and_set(self):
smc = self.makeTestObject()
self.failIf(ISite.providedBy(smc))
sm = site.LocalSiteManager(smc)
smc.setSiteManager(sm)
self.failUnless(ISite.providedBy(smc))
self.failUnless(smc.getSiteManager() is sm)
zope.interface.verify.verifyObject(ISite, smc)
def test_set_w_bogus_value(self):
smc=self.makeTestObject()
self.assertRaises(Exception, smc.setSiteManager, self)
class SiteManagerContainerTest(BaseTestSiteManagerContainer):
def makeTestObject(self):
from zope.site import SiteManagerContainer
return SiteManagerContainer()
def setUp(test):
testing.siteSetUp()
def tearDown(test):
testing.siteTearDown()
class Layer(object):
@staticmethod
def setUp():
pass
def test_suite():
site_suite = doctest.DocFileSuite('../site.txt',
setUp=setUp, tearDown=tearDown)
# XXX Isolate the site.txt tests within their own layer as they do some
# component registration.
site_suite.layer = Layer
return unittest.TestSuite((
doctest.DocTestSuite(),
unittest.makeSuite(SiteManagerContainerTest),
site_suite,
))
|