diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-12-19 21:14:30 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-12-19 21:14:30 +0000 |
| commit | 251ce7d166fa901b33f20cf46315ec464e3eac64 (patch) | |
| tree | 2cd31c1de76f3a915dfb702cc8c18edff27e60b1 /repoze/bfg/tests/test_configuration.py | |
| parent | 12daf9e069b66aef5715a14641fc269367c091dd (diff) | |
| download | pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.tar.gz pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.tar.bz2 pyramid-251ce7d166fa901b33f20cf46315ec464e3eac64.zip | |
- Add two new APIs to the ``repoze.bfg.configuration.Configurator``
class: ``add_adapter`` and ``add_utility``. These, respectively,
perform the same functions as the ``registerAdapter`` and
``registerUtility`` functions of a ZCA registry. They were added to
allow for a more consistent testing API for applications that make
use of the ZCA directly.
- Cause the ``adapter``, ``utility``, and ``subscriber`` ZCML
directives to use a ``Configurator`` instance and associated
configurator APIs rather than a ZCA registry directly.
Diffstat (limited to 'repoze/bfg/tests/test_configuration.py')
| -rw-r--r-- | repoze/bfg/tests/test_configuration.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 7d714f42a..520f9a5bc 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1813,6 +1813,37 @@ class ConfiguratorTests(unittest.TestCase): result = render_view_to_response(ctx, req, 'pod_notinit') self.assertEqual(result, None) + def test_add_subscription_adapter(self): + config = self._makeOne() + def factory(abc): pass + config.add_subscription_adapter(factory, (IDummy,), IDummy, + info='info') + adapters = config.registry.registeredSubscriptionAdapters() + self.assertEqual(list(adapters)[0].factory, factory) + + def test_add_adapter(self): + config = self._makeOne() + def factory(abc): return 'OK' + config.add_adapter(factory, (IDummy,), IDummy, name='foo', + info='info') + result = config.registry.adapters.lookup((IDummy,), IDummy, name='foo') + self.assertEqual(result(None), 'OK') + + def test_add_utility_no_factory(self): + config = self._makeOne() + def component(): pass + config.add_utility(component, IDummy, name='foo', info='info') + result = config.registry.queryUtility(IDummy, name='foo') + self.assertEqual(result, component) + + def test_add_utility_with_factory(self): + config = self._makeOne() + def factory(): return 'OK' + config.add_utility(None, IDummy, name='foo', info='info', + factory=factory) + result = config.registry.queryUtility(IDummy, name='foo') + self.assertEqual(result, 'OK') + class Test__map_view(unittest.TestCase): def setUp(self): from repoze.bfg.registry import Registry @@ -2812,3 +2843,12 @@ class DummyThreadLocalManager(object): self.pushed = d def pop(self): self.popped = True + +class IFactory(Interface): + pass + +class DummyFactory(object): + implements(IFactory) + def __call__(self): + """ """ + |
