summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2011-07-11 20:30:38 -0500
committerMichael Merickel <michael@merickel.org>2011-07-14 19:55:48 -0500
commita02407ee018a17a0186b3e139b15e05f8ff1c795 (patch)
tree27f8e268a984b3d71bbfdc42e7adcab6daa0cebf
parent37e3bebf0165ac5f32c82c0bc87296e0ca5fefd3 (diff)
downloadpyramid-a02407ee018a17a0186b3e139b15e05f8ff1c795.tar.gz
pyramid-a02407ee018a17a0186b3e139b15e05f8ff1c795.tar.bz2
pyramid-a02407ee018a17a0186b3e139b15e05f8ff1c795.zip
Updated scripting test coverage to 100%.
-rw-r--r--pyramid/scripting.py6
-rw-r--r--pyramid/tests/test_scripting.py61
2 files changed, 51 insertions, 16 deletions
diff --git a/pyramid/scripting.py b/pyramid/scripting.py
index fe942ceaf..e04c52a08 100644
--- a/pyramid/scripting.py
+++ b/pyramid/scripting.py
@@ -26,9 +26,9 @@ def get_root(app, request=None):
root = app.root_factory(request)
return root, closer
-def make_request(url, registry=None):
+def make_request(path, registry=None):
""" Return a :meth:`pyramid.request.Request` object anchored at a
- given URL. The object returned will be generated from the supplied
+ given path. The object returned will be generated from the supplied
registry's :term:`Request Factory` using the
:meth:`pyramid.interfaces.IRequestFactory.blank` method.
@@ -48,7 +48,7 @@ def make_request(url, registry=None):
if registry is None:
registry = global_registries.last
request_factory = registry.queryUtility(IRequestFactory, default=Request)
- request = request_factory.blank(url)
+ request = request_factory.blank(path)
request.registry = registry
return request
diff --git a/pyramid/tests/test_scripting.py b/pyramid/tests/test_scripting.py
index d2139b7db..6ed1325ce 100644
--- a/pyramid/tests/test_scripting.py
+++ b/pyramid/tests/test_scripting.py
@@ -2,11 +2,11 @@ import unittest
class TestGetRoot(unittest.TestCase):
def _callFUT(self, app, request=None):
- from pyramid.paster import get_root
+ from pyramid.scripting import get_root
return get_root(app, request)
def test_it_norequest(self):
- app = DummyApp()
+ app = DummyApp(registry=dummy_registry)
root, closer = self._callFUT(app)
self.assertEqual(len(app.threadlocal_manager.pushed), 1)
pushed = app.threadlocal_manager.pushed[0]
@@ -17,7 +17,7 @@ class TestGetRoot(unittest.TestCase):
self.assertEqual(len(app.threadlocal_manager.popped), 1)
def test_it_withrequest(self):
- app = DummyApp()
+ app = DummyApp(registry=dummy_registry)
request = DummyRequest({})
root, closer = self._callFUT(app, request)
self.assertEqual(len(app.threadlocal_manager.pushed), 1)
@@ -29,24 +29,58 @@ class TestGetRoot(unittest.TestCase):
self.assertEqual(len(app.threadlocal_manager.popped), 1)
def test_it_requestfactory_overridden(self):
+ app = DummyApp(registry=dummy_registry)
+ root, closer = self._callFUT(app)
+ self.assertEqual(len(app.threadlocal_manager.pushed), 1)
+ pushed = app.threadlocal_manager.pushed[0]
+ self.assertEqual(pushed['request'].environ['path'], '/')
+
+ def test_it_with_no_registry(self):
+ from pyramid.config import global_registries
app = DummyApp()
- request = Dummy()
- class DummyFactory(object):
- @classmethod
- def blank(cls, path):
- return request
+ # keep registry local so that global_registries is cleared after
registry = DummyRegistry(DummyFactory)
- app.registry = registry
+ global_registries.add(registry)
root, closer = self._callFUT(app)
self.assertEqual(len(app.threadlocal_manager.pushed), 1)
pushed = app.threadlocal_manager.pushed[0]
- self.assertEqual(pushed['request'], request)
+ self.assertEqual(pushed['request'].registry, registry)
+
+class TestMakeRequest(unittest.TestCase):
+ def _callFUT(self, path='/', registry=None):
+ from pyramid.scripting import make_request
+ return make_request(path, registry)
+
+ def test_it(self):
+ request = self._callFUT('/', dummy_registry)
+ self.assertEqual(request.environ['path'], '/')
+ self.assertEqual(request.registry, dummy_registry)
+
+ def test_it_with_nondefault_path(self):
+ request = self._callFUT('/users/login', dummy_registry)
+ self.assertEqual(request.environ['path'], '/users/login')
+ self.assertEqual(request.registry, dummy_registry)
+
+ def test_it_with_no_registry(self):
+ from pyramid.config import global_registries
+ # keep registry local so that global_registries is cleared after
+ registry = DummyRegistry(DummyFactory)
+ global_registries.add(registry)
+ request = self._callFUT()
+ self.assertEqual(request.environ['path'], '/')
+ self.assertEqual(request.registry, registry)
class Dummy:
pass
dummy_root = Dummy()
+class DummyFactory(object):
+ @classmethod
+ def blank(cls, path):
+ req = DummyRequest({'path': path})
+ return req
+
class DummyRegistry(object):
def __init__(self, result=None):
self.result = result
@@ -54,12 +88,13 @@ class DummyRegistry(object):
def queryUtility(self, iface, default=None):
return self.result or default
-dummy_registry = DummyRegistry()
+dummy_registry = DummyRegistry(DummyFactory)
class DummyApp:
- def __init__(self):
- self.registry = dummy_registry
+ def __init__(self, registry=None):
self.threadlocal_manager = DummyThreadLocalManager()
+ if registry:
+ self.registry = registry
def root_factory(self, environ):
return dummy_root