summaryrefslogtreecommitdiff
path: root/repoze/bfg/tests/test_testing.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-12-19 23:05:23 +0000
committerChris McDonough <chrism@agendaless.com>2009-12-19 23:05:23 +0000
commitf0d12ea82e494c13ce504b73a13c6967ab8fb3e1 (patch)
tree53574884314d3cf8c86494f13e90ce6db5b706a8 /repoze/bfg/tests/test_testing.py
parent0adc2fe61c2e225dfa1bcf9a3d814ba394e95ce7 (diff)
downloadpyramid-f0d12ea82e494c13ce504b73a13c6967ab8fb3e1.tar.gz
pyramid-f0d12ea82e494c13ce504b73a13c6967ab8fb3e1.tar.bz2
pyramid-f0d12ea82e494c13ce504b73a13c6967ab8fb3e1.zip
- Add four new testing-related APIs to the
``repoze.bfg.configuration.Configurator`` class: ``testing_securitypolicy``, ``testing_models``, ``testing_add_subscriber``, and ``testing_add_template``. These were added in order to provide more direct access to the functionality of the ``repoze.bfg.testing`` APIs named ``registerDummySecurityPolicy``, ``registerModels``, ``registerEventListener``, and ``registerTemplateRenderer`` when a configurator is used. The ``testing`` APIs named are nominally deprecated (although they will likely remain around "forever", as they are in heavy use in the wild). - Doc-deprecated most helper functions in the ``repoze.bfg.testing`` module. These helper functions likely won't be removed any time soon, nor will they generate a warning any time soon, due to their heavy use in the wild, but equivalent behavior exists in methods of a Configurator.
Diffstat (limited to 'repoze/bfg/tests/test_testing.py')
-rw-r--r--repoze/bfg/tests/test_testing.py46
1 files changed, 32 insertions, 14 deletions
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 72ecd96b0..4762eda19 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -221,28 +221,32 @@ class Test_registerView(TestBase):
class Test_registerAdapter(TestBase):
def test_registerAdapter(self):
- from zope.interface import implements
from zope.interface import Interface
class provides(Interface):
pass
class Provider:
- implements(provides)
- def __init__(self, context, request):
- self.context = context
- self.request = request
+ pass
class for_(Interface):
pass
- class For_:
- implements(for_)
- for1 = For_()
- for2 = For_()
from repoze.bfg import testing
testing.registerAdapter(Provider, (for_, for_), provides, name='foo')
- adapter = self.registry.getMultiAdapter(
- (for1, for2), provides, name='foo')
- self.failUnless(isinstance(adapter, Provider))
- self.assertEqual(adapter.context, for1)
- self.assertEqual(adapter.request, for2)
+ adapter = self.registry.adapters.lookup(
+ (for_, for_), provides, name='foo')
+ self.assertEqual(adapter, Provider)
+
+ def test_registerAdapter_notlist(self):
+ from zope.interface import Interface
+ class provides(Interface):
+ pass
+ class Provider:
+ pass
+ class for_(Interface):
+ pass
+ from repoze.bfg import testing
+ testing.registerAdapter(Provider, for_, provides, name='foo')
+ adapter = self.registry.adapters.lookup(
+ (for_,), provides, name='foo')
+ self.assertEqual(adapter, Provider)
class Test_registerUtility(TestBase):
def test_registerUtility(self):
@@ -259,6 +263,20 @@ class Test_registerUtility(TestBase):
testing.registerUtility(utility, iface, name='mudge')
self.assertEqual(self.registry.getUtility(iface, name='mudge')(), 'foo')
+class Test_registerSubscriber(TestBase):
+ def test_it(self):
+ from repoze.bfg import testing
+ L = []
+ def subscriber(event):
+ L.append(event)
+ testing.registerSubscriber(subscriber, iface=IDummy)
+ event = DummyEvent()
+ self.registry.notify(event)
+ self.assertEqual(len(L), 1)
+ self.assertEqual(L[0], event)
+ self.registry.notify(object())
+ self.assertEqual(len(L), 1)
+
class Test_registerRoute(TestBase):
def test_registerRoute(self):
from repoze.bfg.url import route_url