summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt12
-rw-r--r--docs/narr/commandline.rst125
-rw-r--r--docs/whatsnew-1.1.rst14
-rw-r--r--pyramid/paster.py23
-rw-r--r--pyramid/tests/test_paster.py187
5 files changed, 150 insertions, 211 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 5a709b332..9edeb63c9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,11 +17,13 @@ Backwards Incompatibilities
Features
--------
-- The ``paster pshell`` command now under the hood uses
- ``pyramid.paster.bootstrap``, which makes it possible to supply an
- ``.ini`` file without naming the "right" section in the file that points at
- the actual Pyramid application. Instead, you can generally just run
- ``paster pshell development.ini`` and it will do mostly the right thing.
+- The ``paster pshell``, ``paster pviews``, and ``paster proutes`` commands
+ each now under the hood uses ``pyramid.paster.bootstrap``, which makes it
+ possible to supply an ``.ini`` file without naming the "right" section in
+ the file that points at the actual Pyramid application. Instead, you can
+ generally just run ``paster {pshell|proutes|pviews} development.ini`` and
+ it will do mostly the right thing.
+
Bug Fixes
---------
diff --git a/docs/narr/commandline.rst b/docs/narr/commandline.rst
index 890f42c42..b52faed20 100644
--- a/docs/narr/commandline.rst
+++ b/docs/narr/commandline.rst
@@ -20,18 +20,19 @@ For a big application with several views, it can be hard to keep the view
configuration details in your head, even if you defined all the views
yourself. You can use the ``paster pviews`` command in a terminal window to
print a summary of matching routes and views for a given URL in your
-application. The ``paster pviews`` command accepts two arguments. The
-first argument to ``pviews`` is the path to your application's ``.ini`` file
-and section name inside the ``.ini`` file which points to your application.
-This should be of the format ``config_file#section_name``. The second argument
-is the URL to test for matching views.
+application. The ``paster pviews`` command accepts two arguments. The first
+argument to ``pviews`` is the path to your application's ``.ini`` file and
+section name inside the ``.ini`` file which points to your application. This
+should be of the format ``config_file#section_name``. The second argument is
+the URL to test for matching views. The ``section_name`` may be omitted; if
+it is, it's considered to be ``main``.
Here is an example for a simple view configuration using :term:`traversal`:
.. code-block:: text
:linenos:
- $ ../bin/paster pviews development.ini tutorial /FrontPage
+ $ ../bin/paster pviews development.ini#tutorial /FrontPage
URL = /FrontPage
@@ -125,9 +126,8 @@ application runs "for real". To do so, use the ``paster pshell`` command.
The argument to ``pshell`` follows the format ``config_file#section_name``
where ``config_file`` is the path to your application's ``.ini`` file and
``section_name`` is the ``app`` section name inside the ``.ini`` file which
-points to *your application* as opposed to any other section within the
-``.ini`` file. For example, if your application ``.ini`` file might have a
-``[app:MyProject]`` section that looks like so:
+points to your application. For example, if your application ``.ini`` file
+might have a ``[app:MyProject]`` section that looks like so:
.. code-block:: ini
:linenos:
@@ -145,58 +145,41 @@ name ``MyProject`` as a section name:
.. code-block:: text
- [chrism@vitaminf shellenv]$ ../bin/paster pshell development.ini#MyProject
- Python 2.4.5 (#1, Aug 29 2008, 12:27:37)
- [GCC 4.0.1 (Apple Inc. build 5465)] on darwin
-
- Default Variables:
- app The WSGI Application
- root The root of the default resource tree.
- registry The Pyramid registry object.
- settings The Pyramid settings object.
-
- >>> root
- <myproject.resources.MyResource object at 0x445270>
- >>> registry
- <Registry myproject>
- >>> settings['debug_notfound']
- False
- >>> from myproject.views import my_view
- >>> from pyramid.request import Request
- >>> r = Request.blank('/')
- >>> my_view(r)
- {'project': 'myproject'}
+ chrism@thinko env26]$ bin/paster pshell starter/development.ini#MyProject
+ Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32)
+ [GCC 4.4.3] on linux2
+ Type "help" for more information.
+
+ Environment:
+ app The WSGI application.
+ registry Active Pyramid registry.
+ request Active request object.
+ root Root of the default resource tree.
+ root_factory Default root factory used to create `root`.
+ >>> root
+ <myproject.resources.MyResource object at 0x445270>
+ >>> registry
+ <Registry myproject>
+ >>> registry.settings['debug_notfound']
+ False
+ >>> from myproject.views import my_view
+ >>> from pyramid.request import Request
+ >>> r = Request.blank('/')
+ >>> my_view(r)
+ {'project': 'myproject'}
The WSGI application that is loaded will be available in the shell as the
-``app`` global. Also, if the application that is loaded is the
-:app:`Pyramid` app with no surrounding middleware, the ``root`` object
-returned by the default :term:`root factory`, ``registry``, and ``settings``
-will be available.
+``app`` global. Also, if the application that is loaded is the :app:`Pyramid`
+app with no surrounding middleware, the ``root`` object returned by the
+default :term:`root factory`, ``registry``, and ``request`` will be
+available.
-The interactive shell will not be able to load some of the globals like
-``root``, ``registry`` and ``settings`` if the section name specified when
-loading ``pshell`` is not referencing your :app:`Pyramid` application directly.
-For example, if you have the following ``.ini`` file content:
+You can also simply rely on the ``main`` default section name by omitting any
+hash after the filename:
-.. code-block:: ini
- :linenos:
-
- [app:MyProject]
- use = egg:MyProject
- reload_templates = true
- debug_authorization = false
- debug_notfound = false
- debug_templates = true
- default_locale_name = en
-
- [pipeline:main]
- pipeline =
- egg:WebError#evalerror
- MyProject
+.. code-block:: text
-Use ``MyProject`` instead of ``main`` as the section name argument to
-``pshell`` against the above ``.ini`` file (e.g. ``paster pshell
-development.ini#MyProject``).
+ chrism@thinko env26]$ bin/paster pshell starter/development.ini
Press ``Ctrl-D`` to exit the interactive shell (or ``Ctrl-Z`` on Windows).
@@ -224,8 +207,27 @@ Here, we'll assume your model is stored in the ``myapp.models`` package.
t = transaction
When this INI file is loaded, the extra variables ``m``, ``session`` and
-``t`` will be available for use immediately. This happens regardless of
-whether the ``registry`` and other special variables are loaded.
+``t`` will be available for use immediately. For example:
+
+.. code-block:: text
+
+ chrism@thinko env26]$ bin/paster pshell starter/development.ini
+ Python 2.6.5 (r265:79063, Apr 29 2010, 00:31:32)
+ [GCC 4.4.3] on linux2
+ Type "help" for more information.
+
+ Environment:
+ app The WSGI application.
+ registry Active Pyramid registry.
+ request Active request object.
+ root Root of the default resource tree.
+ root_factory Default root factory used to create `root`.
+
+ Custom Variables:
+ m myapp.models
+ session myapp.models.DBSession
+ t transaction
+ >>>
IPython
~~~~~~~
@@ -258,9 +260,10 @@ You can use the ``paster proutes`` command in a terminal window to print a
summary of routes related to your application. Much like the ``paster
pshell`` command (see :ref:`interactive_shell`), the ``paster proutes``
command accepts one argument with the format ``config_file#section_name``.
-The ``config_file`` is the path to your application's ``.ini`` file,
-and ``section_name`` is the ``app`` section name inside the ``.ini`` file
-which points to your application.
+The ``config_file`` is the path to your application's ``.ini`` file, and
+``section_name`` is the ``app`` section name inside the ``.ini`` file which
+points to your application. By default, the ``section_name`` is ``main`` and
+can be omitted.
For example:
diff --git a/docs/whatsnew-1.1.rst b/docs/whatsnew-1.1.rst
index 40deb55e4..9e6d7b5ae 100644
--- a/docs/whatsnew-1.1.rst
+++ b/docs/whatsnew-1.1.rst
@@ -181,14 +181,12 @@ Minor Feature Additions
user. See "The Interactive Shell" in the "Creating a Pyramid Project"
narrative documentation section.
-- ``paster pshell`` now offers more built-in global variables by default
- (including ``app`` and ``settings``). See :ref:`interactive_shell`.
-
-- The ``paster pshell`` command now under the hood uses
- :func:`pyramid.paster.bootstrap`, which makes it possible to supply an
- ``.ini`` file without naming the "right" section in the file that points at
- the actual Pyramid application. Instead, you can generally just run
- ``paster pshell development.ini`` and it will do mostly the right thing.
+- The ``paster pshell``, ``paster pviews``, and ``paster proutes`` commands
+ each now under the hood uses :func:`pyramid.paster.bootstrap`, which makes
+ it possible to supply an ``.ini`` file without naming the "right" section
+ in the file that points at the actual Pyramid application. Instead, you
+ can generally just run ``paster {pshell|proutes|pviews} development.ini``
+ and it will do mostly the right thing.
- It is now possible to add a ``[pshell]`` section to your application's .ini
configuration file, which influences the global names available to a pshell
diff --git a/pyramid/paster.py b/pyramid/paster.py
index 444608f92..bb499ae8b 100644
--- a/pyramid/paster.py
+++ b/pyramid/paster.py
@@ -90,6 +90,7 @@ class PCommand(Command):
group_name = 'pyramid'
interact = (interact,) # for testing
loadapp = (loadapp,) # for testing
+ bootstrap = (bootstrap,) # testing
verbose = 3
def __init__(self, *arg, **kw):
@@ -129,7 +130,6 @@ class PShellCommand(PCommand):
dest='disable_ipython',
help="Don't use IPython even if it is available")
- bootstrap = (bootstrap,) # testing
ConfigParser = ConfigParser.ConfigParser # testing
def pshell_file_config(self, filename):
@@ -229,10 +229,6 @@ class PRoutesCommand(PCommand):
$ paster proutes myapp.ini#main
- .. note:: You should use a ``section_name`` that refers to the
- actual ``app`` section in the config file that points at
- your Pyramid app without any middleware wrapping, or this
- command will almost certainly fail.
"""
summary = "Print all URL dispatch routes related to a Pyramid application"
min_args = 1
@@ -241,9 +237,8 @@ class PRoutesCommand(PCommand):
parser = Command.standard_parser(simulate=True)
- def _get_mapper(self, app):
+ def _get_mapper(self, registry):
from pyramid.config import Configurator
- registry = app.registry
config = Configurator(registry = registry)
return config.get_routes_mapper()
@@ -256,9 +251,9 @@ class PRoutesCommand(PCommand):
from pyramid.interfaces import IView
from zope.interface import Interface
config_uri = self.args[0]
- app = self.get_app(config_uri, loadapp=self.loadapp[0])
- registry = app.registry
- mapper = self._get_mapper(app)
+ env = self.bootstrap[0](config_uri)
+ registry = env['registry']
+ mapper = self._get_mapper(registry)
if mapper is not None:
routes = mapper.get_routes()
fmt = '%-15s %-30s %-25s'
@@ -300,10 +295,6 @@ class PViewsCommand(PCommand):
$ paster proutes myapp.ini#main url
- .. note:: You should use a ``section_name`` that refers to the
- actual ``app`` section in the config file that points at
- your Pyramid app without any middleware wrapping, or this
- command will almost certainly fail.
"""
summary = "Print all views in an application that might match a URL"
min_args = 2
@@ -505,8 +496,8 @@ class PViewsCommand(PCommand):
config_uri, url = self.args
if not url.startswith('/'):
url = '/%s' % url
- app = self.get_app(config_uri, loadapp=self.loadapp[0])
- registry = app.registry
+ env = self.bootstrap[0](config_uri)
+ registry = env['registry']
view = self._find_view(url, registry)
self.out('')
self.out("URL = %s" % url)
diff --git a/pyramid/tests/test_paster.py b/pyramid/tests/test_paster.py
index 4a099bbdb..91677fff5 100644
--- a/pyramid/tests/test_paster.py
+++ b/pyramid/tests/test_paster.py
@@ -5,9 +5,8 @@ class TestPShellCommand(unittest.TestCase):
from pyramid.paster import PShellCommand
return PShellCommand
- def _makeOne(self, patch_interact=True, patch_bootstrap=True,
- patch_config=True, patch_args=True, patch_options=True):
- cmd = self._getTargetClass()('pshell')
+ def _patch(self, cmd, patch_interact=True, patch_bootstrap=True,
+ patch_config=True, patch_args=True, patch_options=True):
if patch_interact:
self.interact = DummyInteractor()
cmd.interact = (self.interact,)
@@ -25,6 +24,15 @@ class TestPShellCommand(unittest.TestCase):
self.options = Options()
self.options.disable_ipython = True
cmd.options = self.options
+ def _makeOne(self, patch_interact=True, patch_bootstrap=True,
+ patch_config=True, patch_args=True, patch_options=True):
+ cmd = self._getTargetClass()('pshell')
+ self._patch(cmd, patch_interact=patch_interact,
+ patch_bootstrap=patch_bootstrap,
+ patch_config=patch_config,
+ patch_args=patch_args,
+ patch_options=patch_options,
+ )
return cmd
def test_command_ipshell_is_None_ipython_enabled(self):
@@ -123,7 +131,10 @@ class TestPRoutesCommand(unittest.TestCase):
return PRoutesCommand
def _makeOne(self):
- return self._getTargetClass()('proutes')
+ cmd = self._getTargetClass()('proutes')
+ cmd.bootstrap = (DummyBootstrap(),)
+ cmd.args = ('/foo/bar/myapp.ini#myapp',)
+ return cmd
def test_no_routes(self):
command = self._makeOne()
@@ -131,10 +142,6 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
- app = DummyApp()
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(L, [])
@@ -144,10 +151,6 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg:None
L = []
command.out = L.append
- app = DummyApp()
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(L, [])
@@ -159,10 +162,6 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
- app = DummyApp()
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
@@ -183,11 +182,7 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
+ command.bootstrap = (DummyBootstrap(registry=registry),)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
@@ -213,11 +208,7 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
+ command.bootstrap = (DummyBootstrap(registry=registry),)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
@@ -246,11 +237,7 @@ class TestPRoutesCommand(unittest.TestCase):
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
- command.args = ('/foo/bar/myapp.ini#myapp',)
+ command.bootstrap = (DummyBootstrap(registry=registry),)
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
@@ -261,10 +248,7 @@ class TestPRoutesCommand(unittest.TestCase):
from pyramid.urldispatch import RoutesMapper
command = self._makeOne()
registry = Registry()
- class App: pass
- app = App()
- app.registry = registry
- result = command._get_mapper(app)
+ result = command._get_mapper(registry)
self.assertEqual(result.__class__, RoutesMapper)
class TestPViewsCommand(unittest.TestCase):
@@ -272,18 +256,22 @@ class TestPViewsCommand(unittest.TestCase):
from pyramid.paster import PViewsCommand
return PViewsCommand
- def _makeOne(self):
- return self._getTargetClass()('pviews')
+ def _makeOne(self, registry=None):
+ cmd = self._getTargetClass()('pviews')
+ cmd.bootstrap = (DummyBootstrap(registry=registry),)
+ cmd.args = ('/foo/bar/myapp.ini#myapp',)
+ return cmd
- def failUnless(self, condition):
- # silence stupid deprecation under Python >= 2.7
- self.assertTrue(condition)
+ def _register_mapper(self, registry, routes):
+ from pyramid.interfaces import IRoutesMapper
+ mapper = DummyMapper(*routes)
+ registry.registerUtility(mapper, IRoutesMapper)
def test__find_view_no_match(self):
from pyramid.registry import Registry
registry = Registry()
self._register_mapper(registry, [])
- command = self._makeOne()
+ command = self._makeOne(registry)
result = command._find_view('/a', registry)
self.assertEqual(result, None)
@@ -305,7 +293,7 @@ class TestPViewsCommand(unittest.TestCase):
(IViewClassifier, IRequest, root_iface),
IMultiView)
self._register_mapper(registry, [])
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/x', registry)
self.assertEqual(result, None)
@@ -325,7 +313,7 @@ class TestPViewsCommand(unittest.TestCase):
(IViewClassifier, IRequest, root_iface),
IView, name='a')
self._register_mapper(registry, [])
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
self.assertEqual(result, view1)
@@ -348,7 +336,7 @@ class TestPViewsCommand(unittest.TestCase):
(IViewClassifier, IRequest, root_iface),
IMultiView, name='a')
self._register_mapper(registry, [])
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
self.assertEqual(result, view)
@@ -376,7 +364,7 @@ class TestPViewsCommand(unittest.TestCase):
routes = [DummyRoute('a', '/a', factory=Factory, matchdict={}),
DummyRoute('b', '/b', factory=Factory)]
self._register_mapper(registry, routes)
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
self.assertEqual(result, view)
@@ -406,9 +394,9 @@ class TestPViewsCommand(unittest.TestCase):
routes = [DummyRoute('a', '/a', matchdict={}),
DummyRoute('b', '/a', matchdict={})]
self._register_mapper(registry, routes)
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
- self.failUnless(IMultiView.providedBy(result))
+ self.assertTrue(IMultiView.providedBy(result))
def test__find_view_route_multiview(self):
from zope.interface import Interface
@@ -444,12 +432,12 @@ class TestPViewsCommand(unittest.TestCase):
routes = [DummyRoute('a', '/a', matchdict={}),
DummyRoute('b', '/a', matchdict={})]
self._register_mapper(registry, routes)
- command = self._makeOne()
+ command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
- self.failUnless(IMultiView.providedBy(result))
+ self.assertTrue(IMultiView.providedBy(result))
self.assertEqual(len(result.views), 2)
- self.failUnless((None, view1, None) in result.views)
- self.failUnless((None, view2, None) in result.views)
+ self.assertTrue((None, view1, None) in result.views)
+ self.assertTrue((None, view2, None) in result.views)
def test__find_multi_routes_all_match(self):
command = self._makeOne()
@@ -484,15 +472,11 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_not_found(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
command._find_view = lambda arg1, arg2: None
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -501,15 +485,11 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_not_found_url_starts_without_slash(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
command._find_view = lambda arg1, arg2: None
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', 'a')
result = command.command()
self.assertEqual(result, None)
@@ -518,16 +498,12 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_traversal(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
view = DummyView(context='context', view_name='a')
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -538,17 +514,13 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_function_traversal(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
def view(): pass
view.__request_attrs__ = {'context': 'context', 'view_name': 'a'}
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -559,17 +531,13 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_traversal_with_permission(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
view = DummyView(context='context', view_name='a')
view.__permission__ = 'test'
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -581,8 +549,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_traversal_with_predicates(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
def predicate(): pass
@@ -590,10 +558,6 @@ class TestPViewsCommand(unittest.TestCase):
view = DummyView(context='context', view_name='a')
view.__predicates__ = [predicate]
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -605,18 +569,14 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_route(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
route = DummyRoute('a', '/a', matchdict={})
view = DummyView(context='context', view_name='a',
matched_route=route, subpath='')
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -632,8 +592,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_multi_view_nested(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
view1 = DummyView(context='context', view_name='a1')
@@ -643,10 +603,6 @@ class TestPViewsCommand(unittest.TestCase):
multiview2 = DummyMultiView(multiview1, context='context',
view_name='a')
command._find_view = lambda arg1, arg2: multiview2
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -658,8 +614,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_single_view_route_with_route_predicates(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
def predicate(): pass
@@ -668,10 +624,6 @@ class TestPViewsCommand(unittest.TestCase):
view = DummyView(context='context', view_name='a',
matched_route=route, subpath='')
command._find_view = lambda arg1, arg2: view
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -688,8 +640,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_multiview(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
view = DummyView(context='context')
@@ -697,10 +649,6 @@ class TestPViewsCommand(unittest.TestCase):
view.__view_attr__ = 'call'
multiview = DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1, arg2: multiview
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -711,8 +659,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_multiview_with_permission(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
view = DummyView(context='context')
@@ -721,10 +669,6 @@ class TestPViewsCommand(unittest.TestCase):
view.__permission__ = 'test'
multiview = DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1, arg2: multiview
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -736,8 +680,8 @@ class TestPViewsCommand(unittest.TestCase):
def test_views_command_multiview_with_predicates(self):
from pyramid.registry import Registry
- command = self._makeOne()
registry = Registry()
+ command = self._makeOne(registry=registry)
L = []
command.out = L.append
def predicate(): pass
@@ -748,10 +692,6 @@ class TestPViewsCommand(unittest.TestCase):
view.__predicates__ = [predicate]
multiview = DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1, arg2: multiview
- app = DummyApp()
- app.registry = registry
- loadapp = DummyLoadApp(app)
- command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini#myapp', '/a')
result = command.command()
self.assertEqual(result, None)
@@ -761,11 +701,6 @@ class TestPViewsCommand(unittest.TestCase):
self.assertEqual(L[8], ' pyramid.tests.test_paster.view.call')
self.assertEqual(L[9], ' view predicates (predicate = x)')
- def _register_mapper(self, registry, routes):
- from pyramid.interfaces import IRoutesMapper
- mapper = DummyMapper(*routes)
- registry.registerUtility(mapper, IRoutesMapper)
-
class TestGetApp(unittest.TestCase):
def _callFUT(self, config_file, section_name, loadapp):
from pyramid.paster import get_app
@@ -959,11 +894,21 @@ class DummyBootstrap(object):
def __init__(self, app=None, registry=None, request=None, root=None,
root_factory=None, closer=None):
self.app = app or DummyApp()
- self.registry = registry or dummy_registry
- self.request = request or DummyRequest({})
- self.root = root or dummy_root
- self.root_factory = root_factory or Dummy()
- self.closer = closer or DummyCloser()
+ if registry is None:
+ registry = DummyRegistry()
+ self.registry = registry
+ if request is None:
+ request = DummyRequest({})
+ self.request = request
+ if root is None:
+ root = Dummy()
+ self.root = root
+ if root_factory is None:
+ root_factory = Dummy()
+ self.root_factory = root_factory
+ if closer is None:
+ closer = DummyCloser()
+ self.closer = closer
def __call__(self, *a, **kw):
self.a = a