summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Piercy <web@stevepiercy.com>2016-12-11 04:15:53 -0800
committerSteve Piercy <web@stevepiercy.com>2016-12-13 17:40:20 -0800
commit5b40cd38daf5c1a58810a0bff364be0043bc46ba (patch)
tree710839a27fc4619a3d03cab67c84e94c87b8d664
parentba93133ee29ecacad04770af7dffc39f2b2d3aff (diff)
downloadpyramid-5b40cd38daf5c1a58810a0bff364be0043bc46ba.tar.gz
pyramid-5b40cd38daf5c1a58810a0bff364be0043bc46ba.tar.bz2
pyramid-5b40cd38daf5c1a58810a0bff364be0043bc46ba.zip
update pviews with url, config_vars arguments
- fix run(self) method - use correct self.args.config_url and .url in tests
-rw-r--r--pyramid/scripts/pviews.py22
-rw-r--r--pyramid/tests/test_scripts/test_pviews.py38
2 files changed, 43 insertions, 17 deletions
diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py
index 4c511a102..c109f884a 100644
--- a/pyramid/scripts/pviews.py
+++ b/pyramid/scripts/pviews.py
@@ -36,6 +36,20 @@ class PViewsCommand(object):
default=None,
help='The URI to the configuration file.')
+ parser.add_argument('url',
+ nargs='?',
+ default=None,
+ help='The path info portion of the URL.')
+ parser.add_argument(
+ 'config_vars',
+ nargs='*',
+ default=(),
+ help="Variables required by the config file. For example, "
+ "`http_port=%%(http_port)s` would expect `http_port=8080` to be "
+ "passed here.",
+ )
+
+
bootstrap = (bootstrap,) # testing
def __init__(self, argv, quiet=False):
@@ -233,16 +247,16 @@ class PViewsCommand(object):
self.out("%sview predicates (%s)" % (indent, predicate_text))
def run(self):
- if len(self.args) < 2:
+ if not self.args.config_uri and not self.args.url:
self.out('Command requires a config file arg and a url arg')
return 2
- config_uri = self.args[0]
- url = self.args[1]
+ config_uri = self.args.config_uri
+ url = self.args.url
if not url.startswith('/'):
url = '/%s' % url
request = Request.blank(url)
- env = self.bootstrap[0](config_uri, options=parse_vars(self.args[2:]),
+ env = self.bootstrap[0](config_uri, options=parse_vars(self.args.config_vars),
request=request)
view = self._find_view(request)
self.out('')
diff --git a/pyramid/tests/test_scripts/test_pviews.py b/pyramid/tests/test_scripts/test_pviews.py
index b162144a7..a67a8c4d6 100644
--- a/pyramid/tests/test_scripts/test_pviews.py
+++ b/pyramid/tests/test_scripts/test_pviews.py
@@ -9,7 +9,7 @@ class TestPViewsCommand(unittest.TestCase):
def _makeOne(self, registry=None):
cmd = self._getTargetClass()([])
cmd.bootstrap = (dummy.DummyBootstrap(registry=registry),)
- cmd.args = ('/foo/bar/myapp.ini#myapp',)
+ cmd.args.config_uri = '/foo/bar/myapp.ini#myapp'
return cmd
def _makeRequest(self, url, registry):
@@ -242,7 +242,8 @@ class TestPViewsCommand(unittest.TestCase):
L = []
command.out = L.append
command._find_view = lambda arg1: None
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -255,7 +256,8 @@ class TestPViewsCommand(unittest.TestCase):
L = []
command.out = L.append
command._find_view = lambda arg1: None
- command.args = ('/foo/bar/myapp.ini#myapp', 'a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -269,7 +271,8 @@ class TestPViewsCommand(unittest.TestCase):
command.out = L.append
view = dummy.DummyView(context='context', view_name='a')
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -287,7 +290,8 @@ class TestPViewsCommand(unittest.TestCase):
def view(): pass
view.__request_attrs__ = {'context': 'context', 'view_name': 'a'}
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -305,7 +309,8 @@ class TestPViewsCommand(unittest.TestCase):
view = dummy.DummyView(context='context', view_name='a')
view.__permission__ = 'test'
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -326,7 +331,8 @@ class TestPViewsCommand(unittest.TestCase):
view = dummy.DummyView(context='context', view_name='a')
view.__predicates__ = [predicate]
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -346,7 +352,8 @@ class TestPViewsCommand(unittest.TestCase):
view = dummy.DummyView(context='context', view_name='a',
matched_route=route, subpath='')
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -374,7 +381,8 @@ class TestPViewsCommand(unittest.TestCase):
multiview2 = dummy.DummyMultiView(multiview1, context='context',
view_name='a')
command._find_view = lambda arg1: multiview2
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -397,7 +405,8 @@ class TestPViewsCommand(unittest.TestCase):
view = dummy.DummyView(context='context', view_name='a',
matched_route=route, subpath='')
command._find_view = lambda arg1: view
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -423,7 +432,8 @@ class TestPViewsCommand(unittest.TestCase):
view.__view_attr__ = 'call'
multiview = dummy.DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1: multiview
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -444,7 +454,8 @@ class TestPViewsCommand(unittest.TestCase):
view.__permission__ = 'test'
multiview = dummy.DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1: multiview
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')
@@ -468,7 +479,8 @@ class TestPViewsCommand(unittest.TestCase):
view.__predicates__ = [predicate]
multiview = dummy.DummyMultiView(view, context='context', view_name='a')
command._find_view = lambda arg1: multiview
- command.args = ('/foo/bar/myapp.ini#myapp', '/a')
+ command.args.config_uri = '/foo/bar/myapp.ini#myapp'
+ command.args.url = '/a'
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(L[1], 'URL = /a')