diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-11-08 07:30:36 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-11-08 07:30:36 +0000 |
| commit | 738f325de6fac3551691d07ad0293891fb352b4e (patch) | |
| tree | 774cdef8619c87e7fdfd464bd45e99943178c7bc /repoze/bfg/testing.py | |
| parent | deb0dc316b64d5fb7bd0e15a1bafe269d3b33fbc (diff) | |
| download | pyramid-738f325de6fac3551691d07ad0293891fb352b4e.tar.gz pyramid-738f325de6fac3551691d07ad0293891fb352b4e.tar.bz2 pyramid-738f325de6fac3551691d07ad0293891fb352b4e.zip | |
Add makeRequest API.
Add minimal documentation of BFGTestCase.
Diffstat (limited to 'repoze/bfg/testing.py')
| -rw-r--r-- | repoze/bfg/testing.py | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/repoze/bfg/testing.py b/repoze/bfg/testing.py index 2ada3d20e..cfcbc3920 100644 --- a/repoze/bfg/testing.py +++ b/repoze/bfg/testing.py @@ -140,6 +140,19 @@ class BFGTestCase(unittest.TestCase, PlacelessSetup): ``__name__`` attribute that is the value of the key. A dummy model has no other attributes or methods.""" return DummyModel(name, parent) + + def makeRequest(self, path='/', params=None, environ=None, headers=None, + **kw): + """ Returns a ``DummyRequest`` object (mimics a WebOb Request + object) using ``path`` as the path. If ``environ`` is + non-None, it should contain keys that will form the request's + environment. If ``base_url`` is passed in, then the + ``wsgi.url_scheme``, ``HTTP_HOST``, and ``SCRIPT_NAME`` will + be filled in from that value. If ``headers`` is not None, + these will be used as ``request.headers``. The returned + request object will implement the ``repoze.bfg.IRequest`` + interface.""" + return makeRequest(path, params, environ, headers, **kw) def registerUtility(impl, iface, name=''): import zope.component @@ -187,6 +200,39 @@ def registerViewPermission(viewpermission, name, for_=(Interface, Interface)): from repoze.bfg.interfaces import IViewPermission return registerAdapter(viewpermission, for_, IViewPermission, name) +def makeRequest(path, environ=None, base_url=None, headers=None, **kw): + return DummyRequest(path, environ, base_url, headers, **kw) + +from zope.interface import implements +from repoze.bfg.interfaces import IRequest + +class DummyRequest: + implements(IRequest) + def __init__(self, path, params=None, environ=None, headers=None, **kw): + if environ is None: + environ = {} + if params is None: + params = {} + if headers is None: + headers = {} + self.environ = environ + self.headers = headers + self.params = params + self.GET = params + self.POST = params + self.application_url = 'http://example.com' + self.host_url = self.application_url + self.path_url = self.application_url + self.path = path + self.path_info = path + self.script_name = '' + self.path_qs = '' + self.url = self.application_url + self.host = 'example.com:80' + self.body = '' + self.cookies = {} + self.__dict__.update(kw) + class _DummySecurityPolicy: def __init__(self, userid=None, groupids=()): self.userid = userid @@ -270,6 +316,3 @@ class DummyModel: ob = self.subs[name] return ob - - - |
