From 6801b595308651a4d103b2e1c45d4f5387e151e5 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 7 Jan 2009 13:09:22 +0000 Subject: Add a 'post' argument to the DummyRequest ctor. --- repoze/bfg/testing.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'repoze/bfg/testing.py') diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py index 3480184bd..5a90033c7 100644 --- a/repoze/bfg/testing.py +++ b/repoze/bfg/testing.py @@ -306,17 +306,26 @@ class DummyModel: return inst class DummyRequest: - """ A dummy request object (imitates a :term:`WebOb` ``Request`` - object). The named constructor arguments correspond to their - WebOb equivalents. Extra keyword arguments are assigned as - attributes of the request itself.""" + """ A dummy request object (imitates a :term:`WebOb` ``Request`` object). + + The ``params``, ``environ``, ``headers``, ``path``, and ``cookies`` + arguments correspond to their WebOb equivalents. + + The ``post`` argument, if passed, populates the request's + ``POST`` attribute, but *not* ``params``, in order to allow testing + that the app accepts data for a given view only from POST requests. + This argument also sets ``self.method`` to "POST". + + Extra keyword arguments are assigned as attributes of the request + itself. + """ implements(IRequest) method = 'GET' application_url = 'http://example.com' host = 'example.com:80' content_length = 0 def __init__(self, params=None, environ=None, headers=None, path='/', - cookies=None, **kw): + cookies=None, post=None, **kw): if environ is None: environ = {} if params is None: @@ -330,7 +339,11 @@ class DummyRequest: self.params = params self.cookies = cookies self.GET = params - self.POST = params + if post is not None: + self.method = 'POST' + self.POST = post + else: + self.POST = params self.host_url = self.application_url self.path_url = self.application_url self.url = self.application_url -- cgit v1.2.3