summaryrefslogtreecommitdiff
path: root/repoze
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-11-08 07:30:36 +0000
committerChris McDonough <chrism@agendaless.com>2008-11-08 07:30:36 +0000
commit738f325de6fac3551691d07ad0293891fb352b4e (patch)
tree774cdef8619c87e7fdfd464bd45e99943178c7bc /repoze
parentdeb0dc316b64d5fb7bd0e15a1bafe269d3b33fbc (diff)
downloadpyramid-738f325de6fac3551691d07ad0293891fb352b4e.tar.gz
pyramid-738f325de6fac3551691d07ad0293891fb352b4e.tar.bz2
pyramid-738f325de6fac3551691d07ad0293891fb352b4e.zip
Add makeRequest API.
Add minimal documentation of BFGTestCase.
Diffstat (limited to 'repoze')
-rw-r--r--repoze/bfg/testing.py49
-rw-r--r--repoze/bfg/tests/test_testing.py15
2 files changed, 61 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
-
-
-
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py
index 23fbb7cc7..9368a3e5b 100644
--- a/repoze/bfg/tests/test_testing.py
+++ b/repoze/bfg/tests/test_testing.py
@@ -204,6 +204,21 @@ class TestBFGTestCase(unittest.TestCase, PlacelessSetup):
self.assertEqual(model.__name__, 'name')
self.assertEqual(model.__parent__, parent)
+ def test_makeRequest(self):
+ case = self._makeOne()
+ request = case.makeRequest('/abc',
+ params = {'say':'Hello'},
+ environ = {'PATH_INFO':'/foo'},
+ headers = {'X-Foo':'YUP'},
+ water = 1)
+ self.assertEqual(request.path, '/abc')
+ self.assertEqual(request.params['say'], 'Hello')
+ self.assertEqual(request.GET['say'], 'Hello')
+ self.assertEqual(request.POST['say'], 'Hello')
+ self.assertEqual(request.headers['X-Foo'], 'YUP')
+ self.assertEqual(request.environ['PATH_INFO'], '/foo')
+ self.assertEqual(request.water, 1)
+
class TestDummyAllowingSecurityPolicy(unittest.TestCase):
def _getTargetClass(self):
from repoze.bfg.testing import DummyAllowingSecurityPolicy