summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-12-03 23:06:20 +0000
committerChris McDonough <chrism@agendaless.com>2009-12-03 23:06:20 +0000
commitab4e7b9befb1b84deedfcb29766e8250113ba566 (patch)
tree669204dd5f167ee57fcc20fbf08621a559d161f3
parent49ce9b5339756a9c4f195e4987f3c233ee77a9f8 (diff)
downloadpyramid-ab4e7b9befb1b84deedfcb29766e8250113ba566.tar.gz
pyramid-ab4e7b9befb1b84deedfcb29766e8250113ba566.tar.bz2
pyramid-ab4e7b9befb1b84deedfcb29766e8250113ba566.zip
- ``repoze.bfg.testing.DummyModel`` now accepts a new constructor
keyword argument: ``__provides__``. If this constructor argument is provided, it should be an interface or a tuple of interfaces. The resulting model will then provide these interfaces (they will be attached to the constructed model via ``zope.interface.alsoProvides``).
-rw-r--r--CHANGES.txt13
-rw-r--r--docs/whatsnew-1.2.rst7
-rw-r--r--repoze/bfg/testing.py11
-rw-r--r--repoze/bfg/tests/test_testing.py4
4 files changed, 33 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 641da1317..db7415a2f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,16 @@
+Next release
+============
+
+Features
+--------
+
+- ``repoze.bfg.testing.DummyModel`` now accepts a new constructor
+ keyword argument: ``__provides__``. If this constructor argument is
+ provided, it should be an interface or a tuple of interfaces. The
+ resulting model will then provide these interfaces (they will be
+ attached to the constructed model via
+ ``zope.interface.alsoProvides``).
+
1.2a3 (2009-01-02)
==================
diff --git a/docs/whatsnew-1.2.rst b/docs/whatsnew-1.2.rst
index 603b2f087..862bef375 100644
--- a/docs/whatsnew-1.2.rst
+++ b/docs/whatsnew-1.2.rst
@@ -83,6 +83,13 @@ Minor Miscellaneous Feature Additions
function to be the global ZCA registry (the result of
``zope.component.getGlobalSiteManager``) once again.
+- ``repoze.bfg.testing.DummyModel`` now accepts a new constructor
+ keyword argument: ``__provides__``. If this constructor argument is
+ provided, it should be an interface or a tuple of interfaces. The
+ resulting model will then provide these interfaces (they will be
+ attached to the constructed model via
+ ``zope.interface.alsoProvides``).
+
Backwards Incompatibilites
--------------------------
diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py
index 9638fc21c..127f54283 100644
--- a/repoze/bfg/testing.py
+++ b/repoze/bfg/testing.py
@@ -8,6 +8,7 @@ from zope.deprecation import deprecated
from zope.interface import implements
from zope.interface import Interface
+from zope.interface import alsoProvides
from repoze.bfg.interfaces import IAuthenticationPolicy
from repoze.bfg.interfaces import IAuthorizationPolicy
@@ -387,13 +388,19 @@ class DummyModel:
to the constructor will be used as the ``__name__`` attribute of
the model. the value of ``parent`` will be used as the
``__parent__`` attribute of the model. """
- def __init__(self, __name__=None, __parent__=None, **kw):
+ def __init__(self, __name__=None, __parent__=None, __provides__=None,
+ **kw):
""" The he model's ``__name__`` attribute will be set to the
value of ``__name__``, and the model's ``__parent__``
- attribute will be set to the value of ``__parent__``. Any
+ attribute will be set to the value of ``__parent__``. If
+ ``__provides__`` is specified, it should be an interface
+ object or tuple of interface objects that will be attached to
+ the resulting model via ``zope.interface.alsoProvides``. Any
extra keywords will be set as direct attributes of the model."""
self.__name__ = __name__
self.__parent__ = __parent__
+ if __provides__ is not None:
+ alsoProvides(self, __provides__)
self.kw = kw
self.__dict__.update(**kw)
self.subs = {}
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 7c8b7ad30..72ecd96b0 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -402,6 +402,10 @@ class TestDummyModel(unittest.TestCase):
model = self._makeOne()
self.assertEqual(model.__nonzero__(), True)
+ def test_ctor_with__provides__(self):
+ model = self._makeOne(__provides__=IDummy)
+ self.failUnless(IDummy.providedBy(model))
+
class TestDummyRequest(unittest.TestCase):
def _getTargetClass(self):
from repoze.bfg.testing import DummyRequest