100
101
from testtools.matchers import MatchesRegex
101
102
from testtools.testcase import ExpectedException as TTExpectedException
102
103
import transaction
103
from zope.component import getUtility
104
from zope.component import (
104
109
import zope.event
110
from zope.interface import Interface
105
111
from zope.interface.verify import verifyClass
112
from zope.publisher.interfaces.browser import IBrowserRequest
106
113
from zope.security.proxy import (
107
114
isinstance as zope_isinstance,
108
115
removeSecurityProxy,
1429
1437
def stepstogo(self):
1430
1438
"""See `IBasicLaunchpadRequest`."""
1431
1439
return StepsToGo(self)
1442
class FakeAdapterMixin:
1443
"""A testcase mixin that helps register/unregister Zope adapters.
1445
These helper methods simplify the task to registering Zope adapters
1446
during the setup of a test and they will be unregistered when the
1449
def registerAdapter(self, adapter_class, for_interfaces,
1450
provided_interface, name=None):
1451
"""Register an adapter from the required interfacs to the provided.
1453
eg. registerAdapter(
1454
TestOtherThing, (IThing, ILayer), IOther, name='fnord')
1456
getSiteManager().registerAdapter(
1457
adapter_class, for_interfaces, provided_interface, name=name)
1459
getSiteManager().unregisterAdapter, adapter_class,
1460
for_interfaces, provided_interface, name=name)
1462
def registerAuthorizationAdapter(self, authorization_class,
1463
for_interface, permission_name):
1464
"""Register a security checker to test authorisation.
1466
eg. registerAuthorizationAdapter(
1467
TestChecker, IPerson, 'launchpad.View')
1469
self.registerAdapter(
1470
authorization_class, (for_interface, ), IAuthorization,
1471
name=permission_name)
1473
def registerBrowserViewAdapter(self, view_class, for_interface, name):
1474
"""Register a security checker to test authorization.
1476
eg registerBrowserViewAdapter(TestView, IPerson, '+test-view')
1478
self.registerAdapter(
1479
view_class, (for_interface, IBrowserRequest), Interface,
1482
def getAdapter(self, for_interfaces, provided_interface, name=None):
1483
return getMultiAdapter(for_interfaces, provided_interface, name=name)