summaryrefslogtreecommitdiff
path: root/tests/pkgs
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-10-15 01:55:54 -0500
committerMichael Merickel <michael@merickel.org>2018-10-15 09:24:07 -0500
commit0c29cf2df41600d3906d521c72991c7686018b71 (patch)
treeff907f90ec9467e12874c9b2c961549d0e7caf74 /tests/pkgs
parent851c368e3c158e264358de10446f5b5de240e534 (diff)
downloadpyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.gz
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.tar.bz2
pyramid-0c29cf2df41600d3906d521c72991c7686018b71.zip
format source using black
Diffstat (limited to 'tests/pkgs')
-rw-r--r--tests/pkgs/ccbugapp/__init__.py8
-rw-r--r--tests/pkgs/conflictapp/__init__.py9
-rw-r--r--tests/pkgs/conflictapp/included.py5
-rw-r--r--tests/pkgs/defpermbugapp/__init__.py34
-rw-r--r--tests/pkgs/eventonly/__init__.py15
-rw-r--r--tests/pkgs/exceptionviewapp/__init__.py56
-rw-r--r--tests/pkgs/exceptionviewapp/models.py6
-rw-r--r--tests/pkgs/exceptionviewapp/views.py9
-rw-r--r--tests/pkgs/fixtureapp/__init__.py10
-rw-r--r--tests/pkgs/fixtureapp/models.py3
-rw-r--r--tests/pkgs/fixtureapp/subpackage/__init__.py2
-rw-r--r--tests/pkgs/fixtureapp/views.py5
-rw-r--r--tests/pkgs/forbiddenapp/__init__.py36
-rw-r--r--tests/pkgs/forbiddenview/__init__.py12
-rw-r--r--tests/pkgs/hybridapp/__init__.py81
-rw-r--r--tests/pkgs/hybridapp/views.py10
-rw-r--r--tests/pkgs/includeapp1/root.py3
-rw-r--r--tests/pkgs/includeapp1/three.py7
-rw-r--r--tests/pkgs/includeapp1/two.py4
-rw-r--r--tests/pkgs/notfoundview/__init__.py9
-rw-r--r--tests/pkgs/permbugapp/__init__.py31
-rw-r--r--tests/pkgs/rendererscanapp/__init__.py5
-rw-r--r--tests/pkgs/rendererscanapp/two/__init__.py4
-rw-r--r--tests/pkgs/restbugapp/__init__.py32
-rw-r--r--tests/pkgs/restbugapp/views.py6
-rw-r--r--tests/pkgs/static_abspath/__init__.py4
-rw-r--r--tests/pkgs/static_assetspec/__init__.py1
-rw-r--r--tests/pkgs/static_routeprefix/__init__.py2
-rw-r--r--tests/pkgs/staticpermapp/__init__.py35
-rw-r--r--tests/pkgs/subrequestapp/__init__.py10
-rw-r--r--tests/pkgs/viewdecoratorapp/__init__.py1
-rw-r--r--tests/pkgs/viewdecoratorapp/views/views.py11
-rw-r--r--tests/pkgs/wsgiapp2app/__init__.py3
33 files changed, 295 insertions, 174 deletions
diff --git a/tests/pkgs/ccbugapp/__init__.py b/tests/pkgs/ccbugapp/__init__.py
index afe21d4e0..908a36e3e 100644
--- a/tests/pkgs/ccbugapp/__init__.py
+++ b/tests/pkgs/ccbugapp/__init__.py
@@ -1,16 +1,20 @@
from webob import Response
+
def rdf_view(request):
""" """
return Response('rdf')
+
def juri_view(request):
""" """
return Response('juri')
+
def includeme(config):
config.add_route('rdf', 'licenses/:license_code/:license_version/rdf')
- config.add_route('juri',
- 'licenses/:license_code/:license_version/:jurisdiction')
+ config.add_route(
+ 'juri', 'licenses/:license_code/:license_version/:jurisdiction'
+ )
config.add_view(rdf_view, route_name='rdf')
config.add_view(juri_view, route_name='juri')
diff --git a/tests/pkgs/conflictapp/__init__.py b/tests/pkgs/conflictapp/__init__.py
index d85aa0e1e..840813994 100644
--- a/tests/pkgs/conflictapp/__init__.py
+++ b/tests/pkgs/conflictapp/__init__.py
@@ -2,15 +2,19 @@ from pyramid.response import Response
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
+
def aview(request):
return Response('a view')
+
def routeview(request):
return Response('route view')
+
def protectedview(request):
return Response('protected view')
+
def includeme(config):
# purposely sorta-randomly ordered (route comes after view naming it,
# authz comes after views)
@@ -18,7 +22,8 @@ def includeme(config):
config.add_view(protectedview, name='protected', permission='view')
config.add_view(routeview, route_name='aroute')
config.add_route('aroute', '/route')
- config.set_authentication_policy(AuthTktAuthenticationPolicy(
- 'seekri1t', hashalg='sha512'))
+ config.set_authentication_policy(
+ AuthTktAuthenticationPolicy('seekri1t', hashalg='sha512')
+ )
config.set_authorization_policy(ACLAuthorizationPolicy())
config.include('tests.pkgs.conflictapp.included')
diff --git a/tests/pkgs/conflictapp/included.py b/tests/pkgs/conflictapp/included.py
index 0b76fb2bc..5f483ff81 100644
--- a/tests/pkgs/conflictapp/included.py
+++ b/tests/pkgs/conflictapp/included.py
@@ -1,6 +1,9 @@
from webob import Response
-def bview(request): return Response('b view')
+
+def bview(request):
+ return Response('b view')
+
def includeme(config):
config.add_view(bview)
diff --git a/tests/pkgs/defpermbugapp/__init__.py b/tests/pkgs/defpermbugapp/__init__.py
index 3e59aa623..81897e86a 100644
--- a/tests/pkgs/defpermbugapp/__init__.py
+++ b/tests/pkgs/defpermbugapp/__init__.py
@@ -2,25 +2,29 @@ from webob import Response
from pyramid.security import NO_PERMISSION_REQUIRED
from pyramid.view import view_config
+
@view_config(name='x')
-def x_view(request): # pragma: no cover
- return Response('this is private!')
+def x_view(request): # pragma: no cover
+ return Response('this is private!')
+
@view_config(name='y', permission='private2')
-def y_view(request): # pragma: no cover
- return Response('this is private too!')
-
+def y_view(request): # pragma: no cover
+ return Response('this is private too!')
+
+
@view_config(name='z', permission=NO_PERMISSION_REQUIRED)
def z_view(request):
- return Response('this is public')
+ return Response('this is public')
+
def includeme(config):
- from pyramid.authorization import ACLAuthorizationPolicy
- from pyramid.authentication import AuthTktAuthenticationPolicy
- authn_policy = AuthTktAuthenticationPolicy('seekt1t', hashalg='sha512')
- authz_policy = ACLAuthorizationPolicy()
- config.scan('tests.pkgs.defpermbugapp')
- config._set_authentication_policy(authn_policy)
- config._set_authorization_policy(authz_policy)
- config.set_default_permission('private')
-
+ from pyramid.authorization import ACLAuthorizationPolicy
+ from pyramid.authentication import AuthTktAuthenticationPolicy
+
+ authn_policy = AuthTktAuthenticationPolicy('seekt1t', hashalg='sha512')
+ authz_policy = ACLAuthorizationPolicy()
+ config.scan('tests.pkgs.defpermbugapp')
+ config._set_authentication_policy(authn_policy)
+ config._set_authorization_policy(authz_policy)
+ config.set_default_permission('private')
diff --git a/tests/pkgs/eventonly/__init__.py b/tests/pkgs/eventonly/__init__.py
index 452ae35a7..c48b539a1 100644
--- a/tests/pkgs/eventonly/__init__.py
+++ b/tests/pkgs/eventonly/__init__.py
@@ -1,6 +1,7 @@
from pyramid.view import view_config
from pyramid.events import subscriber
+
class Yup(object):
def __init__(self, val, config):
self.val = val
@@ -13,37 +14,46 @@ class Yup(object):
def __call__(self, event):
return getattr(event.response, 'yup', False)
+
class Foo(object):
def __init__(self, response):
self.response = response
+
class Bar(object):
pass
+
@subscriber(Foo)
def foo(event):
event.response.text += 'foo '
+
@subscriber(Foo, yup=True)
def fooyup(event):
event.response.text += 'fooyup '
-
+
+
@subscriber([Foo, Bar])
def foobar(event):
event.response.text += 'foobar '
+
@subscriber([Foo, Bar])
def foobar2(event, context):
event.response.text += 'foobar2 '
+
@subscriber([Foo, Bar], yup=True)
def foobaryup(event):
event.response.text += 'foobaryup '
+
@subscriber([Foo, Bar], yup=True)
def foobaryup2(event, context):
event.response.text += 'foobaryup2 '
+
@view_config(name='sendfoo')
def sendfoo(request):
response = request.response
@@ -51,6 +61,7 @@ def sendfoo(request):
request.registry.notify(Foo(response))
return response
+
@view_config(name='sendfoobar')
def sendfoobar(request):
response = request.response
@@ -58,7 +69,7 @@ def sendfoobar(request):
request.registry.notify(Foo(response), Bar())
return response
+
def includeme(config):
config.add_subscriber_predicate('yup', Yup)
config.scan('tests.pkgs.eventonly')
-
diff --git a/tests/pkgs/exceptionviewapp/__init__.py b/tests/pkgs/exceptionviewapp/__init__.py
index ffc1b47c6..19804d242 100644
--- a/tests/pkgs/exceptionviewapp/__init__.py
+++ b/tests/pkgs/exceptionviewapp/__init__.py
@@ -1,31 +1,47 @@
from pyramid.httpexceptions import HTTPException
+
def includeme(config):
config.add_route('route_raise_exception', 'route_raise_exception')
config.add_route('route_raise_httpexception', 'route_raise_httpexception')
- config.add_route('route_raise_exception2', 'route_raise_exception2',
- factory='.models.route_factory')
- config.add_route('route_raise_exception3', 'route_raise_exception3',
- factory='.models.route_factory2')
+ config.add_route(
+ 'route_raise_exception2',
+ 'route_raise_exception2',
+ factory='.models.route_factory',
+ )
+ config.add_route(
+ 'route_raise_exception3',
+ 'route_raise_exception3',
+ factory='.models.route_factory2',
+ )
config.add_route('route_raise_exception4', 'route_raise_exception4')
config.add_view('.views.maybe')
config.add_view('.views.no', context='.models.NotAnException')
config.add_view('.views.yes', context=".models.AnException")
config.add_view('.views.raise_exception', name='raise_exception')
- config.add_view('.views.raise_exception',
- route_name='route_raise_exception')
- config.add_view('.views.raise_exception',
- route_name='route_raise_exception2')
- config.add_view('.views.raise_exception',
- route_name='route_raise_exception3')
- config.add_view('.views.whoa', context='.models.AnException',
- route_name='route_raise_exception3')
- config.add_view('.views.raise_exception',
- route_name='route_raise_exception4')
- config.add_view('.views.whoa', context='.models.AnException',
- route_name='route_raise_exception4')
- config.add_view('.views.raise_httpexception',
- route_name='route_raise_httpexception')
+ config.add_view(
+ '.views.raise_exception', route_name='route_raise_exception'
+ )
+ config.add_view(
+ '.views.raise_exception', route_name='route_raise_exception2'
+ )
+ config.add_view(
+ '.views.raise_exception', route_name='route_raise_exception3'
+ )
+ config.add_view(
+ '.views.whoa',
+ context='.models.AnException',
+ route_name='route_raise_exception3',
+ )
+ config.add_view(
+ '.views.raise_exception', route_name='route_raise_exception4'
+ )
+ config.add_view(
+ '.views.whoa',
+ context='.models.AnException',
+ route_name='route_raise_exception4',
+ )
+ config.add_view(
+ '.views.raise_httpexception', route_name='route_raise_httpexception'
+ )
config.add_view('.views.catch_httpexception', context=HTTPException)
-
-
diff --git a/tests/pkgs/exceptionviewapp/models.py b/tests/pkgs/exceptionviewapp/models.py
index fe407badc..25f8e9156 100644
--- a/tests/pkgs/exceptionviewapp/models.py
+++ b/tests/pkgs/exceptionviewapp/models.py
@@ -1,18 +1,22 @@
-
class NotAnException(object):
pass
+
class AnException(Exception):
pass
+
class RouteContext(object):
pass
+
class RouteContext2(object):
pass
+
def route_factory(*arg):
return RouteContext()
+
def route_factory2(*arg):
return RouteContext2()
diff --git a/tests/pkgs/exceptionviewapp/views.py b/tests/pkgs/exceptionviewapp/views.py
index 4953056bc..ca2c4fffb 100644
--- a/tests/pkgs/exceptionviewapp/views.py
+++ b/tests/pkgs/exceptionviewapp/views.py
@@ -2,23 +2,30 @@ from webob import Response
from .models import AnException
from pyramid.httpexceptions import HTTPBadRequest
+
def no(request):
return Response('no')
+
def yes(request):
return Response('yes')
-
+
+
def maybe(request):
return Response('maybe')
+
def whoa(request):
return Response('whoa')
+
def raise_exception(request):
raise AnException()
+
def raise_httpexception(request):
raise HTTPBadRequest
+
def catch_httpexception(request):
return Response('caught')
diff --git a/tests/pkgs/fixtureapp/__init__.py b/tests/pkgs/fixtureapp/__init__.py
index 27063aae2..ffc8adb4a 100644
--- a/tests/pkgs/fixtureapp/__init__.py
+++ b/tests/pkgs/fixtureapp/__init__.py
@@ -3,10 +3,12 @@ def includeme(config):
config.add_view('.views.exception_view', context=RuntimeError)
config.add_view('.views.protected_view', name='protected.html')
config.add_view('.views.erroneous_view', name='error.html')
- config.add_view('.views.fixture_view', name='dummyskin.html',
- request_type='.views.IDummy')
+ config.add_view(
+ '.views.fixture_view',
+ name='dummyskin.html',
+ request_type='.views.IDummy',
+ )
from .models import fixture, IFixture
+
config.registry.registerUtility(fixture, IFixture)
config.add_view('.views.fixture_view', name='another.html')
-
-
diff --git a/tests/pkgs/fixtureapp/models.py b/tests/pkgs/fixtureapp/models.py
index d80d14bb3..5ad640df9 100644
--- a/tests/pkgs/fixtureapp/models.py
+++ b/tests/pkgs/fixtureapp/models.py
@@ -1,8 +1,9 @@
from zope.interface import Interface
+
class IFixture(Interface):
pass
+
def fixture():
""" """
-
diff --git a/tests/pkgs/fixtureapp/subpackage/__init__.py b/tests/pkgs/fixtureapp/subpackage/__init__.py
index d3173e636..5bb534f79 100644
--- a/tests/pkgs/fixtureapp/subpackage/__init__.py
+++ b/tests/pkgs/fixtureapp/subpackage/__init__.py
@@ -1 +1 @@
-#package
+# package
diff --git a/tests/pkgs/fixtureapp/views.py b/tests/pkgs/fixtureapp/views.py
index cbfc5a574..78df81c6f 100644
--- a/tests/pkgs/fixtureapp/views.py
+++ b/tests/pkgs/fixtureapp/views.py
@@ -2,21 +2,26 @@ from zope.interface import Interface
from webob import Response
from pyramid.httpexceptions import HTTPForbidden
+
def fixture_view(context, request):
""" """
return Response('fixture')
+
def erroneous_view(context, request):
""" """
raise RuntimeError()
+
def exception_view(context, request):
""" """
return Response('supressed')
+
def protected_view(context, request):
""" """
raise HTTPForbidden()
+
class IDummy(Interface):
pass
diff --git a/tests/pkgs/forbiddenapp/__init__.py b/tests/pkgs/forbiddenapp/__init__.py
index c378126fc..9ebf62a9d 100644
--- a/tests/pkgs/forbiddenapp/__init__.py
+++ b/tests/pkgs/forbiddenapp/__init__.py
@@ -2,23 +2,27 @@ from webob import Response
from pyramid.httpexceptions import HTTPForbidden
from pyramid.compat import bytes_
-def x_view(request): # pragma: no cover
- return Response('this is private!')
+
+def x_view(request): # pragma: no cover
+ return Response('this is private!')
+
def forbidden_view(context, request):
- msg = context.message
- result = context.result
- message = msg + '\n' + str(result)
- resp = HTTPForbidden()
- resp.body = bytes_(message)
- return resp
+ msg = context.message
+ result = context.result
+ message = msg + '\n' + str(result)
+ resp = HTTPForbidden()
+ resp.body = bytes_(message)
+ return resp
+
def includeme(config):
- from pyramid.authentication import AuthTktAuthenticationPolicy
- from pyramid.authorization import ACLAuthorizationPolicy
- authn_policy = AuthTktAuthenticationPolicy('seekr1t', hashalg='sha512')
- authz_policy = ACLAuthorizationPolicy()
- config._set_authentication_policy(authn_policy)
- config._set_authorization_policy(authz_policy)
- config.add_view(x_view, name='x', permission='private')
- config.add_view(forbidden_view, context=HTTPForbidden)
+ from pyramid.authentication import AuthTktAuthenticationPolicy
+ from pyramid.authorization import ACLAuthorizationPolicy
+
+ authn_policy = AuthTktAuthenticationPolicy('seekr1t', hashalg='sha512')
+ authz_policy = ACLAuthorizationPolicy()
+ config._set_authentication_policy(authn_policy)
+ config._set_authorization_policy(authz_policy)
+ config.add_view(x_view, name='x', permission='private')
+ config.add_view(forbidden_view, context=HTTPForbidden)
diff --git a/tests/pkgs/forbiddenview/__init__.py b/tests/pkgs/forbiddenview/__init__.py
index 6b4c3c116..4c78d961c 100644
--- a/tests/pkgs/forbiddenview/__init__.py
+++ b/tests/pkgs/forbiddenview/__init__.py
@@ -3,22 +3,27 @@ from pyramid.response import Response
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
+
@forbidden_view_config(route_name='foo')
-def foo_forbidden(request): # pragma: no cover
+def foo_forbidden(request): # pragma: no cover
return Response('foo_forbidden')
+
@forbidden_view_config()
def forbidden(request):
return Response('generic_forbidden')
+
@view_config(route_name='foo')
-def foo(request): # pragma: no cover
+def foo(request): # pragma: no cover
return Response('OK foo')
+
@view_config(route_name='bar')
-def bar(request): # pragma: no cover
+def bar(request): # pragma: no cover
return Response('OK bar')
+
def includeme(config):
authn_policy = AuthTktAuthenticationPolicy('seekri1', hashalg='sha512')
authz_policy = ACLAuthorizationPolicy()
@@ -28,4 +33,3 @@ def includeme(config):
config.add_route('foo', '/foo')
config.add_route('bar', '/bar')
config.scan('tests.pkgs.forbiddenview')
-
diff --git a/tests/pkgs/hybridapp/__init__.py b/tests/pkgs/hybridapp/__init__.py
index 1cc2dde83..001e1b882 100644
--- a/tests/pkgs/hybridapp/__init__.py
+++ b/tests/pkgs/hybridapp/__init__.py
@@ -1,39 +1,46 @@
def includeme(config):
- # <!-- we want this view to "win" -->
- config.add_route('route', 'abc')
- config.add_view('.views.route_view', route_name='route')
- # <!-- .. even though this one has a more specific context -->
- config.add_view('.views.global_view',
- context='pyramid.traversal.DefaultRootFactory')
- config.add_view('.views.global2_view',
- context='pyramid.traversal.DefaultRootFactory',
- name='global2')
- config.add_route('route2', 'def')
- # <!-- we want this view to win for route2 even though global view with
- # context is more specific -->
- config.add_view('.views.route2_view', route_name='route2')
+ # <!-- we want this view to "win" -->
+ config.add_route('route', 'abc')
+ config.add_view('.views.route_view', route_name='route')
+ # <!-- .. even though this one has a more specific context -->
+ config.add_view(
+ '.views.global_view', context='pyramid.traversal.DefaultRootFactory'
+ )
+ config.add_view(
+ '.views.global2_view',
+ context='pyramid.traversal.DefaultRootFactory',
+ name='global2',
+ )
+ config.add_route('route2', 'def')
+ # <!-- we want this view to win for route2 even though global view with
+ # context is more specific -->
+ config.add_view('.views.route2_view', route_name='route2')
- # <!-- the global view should be found for this route -->
- config.add_route('route3', 'ghi', use_global_views=True)
- # <!-- the global view should not be found for this route -->
- config.add_route('route4', 'jkl')
- # <!-- the global view should not be found for this route (/global2) -->
- config.add_route('route5', 'mno/*traverse')
- # <!-- the global view should be found for this route (/global2) -->
- config.add_route('route6', 'pqr/*traverse', use_global_views=True)
- config.add_route('route7', 'error')
- config.add_view('.views.erroneous_view', route_name='route7')
- config.add_route('route8', 'error2')
- config.add_view('.views.erroneous_view', route_name='route8')
- # <!-- we want this view to "win" for route7 as exception view -->
- config.add_view('.views.exception_view', context=RuntimeError)
- # <!-- we want this view to "win" for route8 as exception view-->
- config.add_view('.views.exception2_view', context=RuntimeError,
- route_name='route8')
- config.add_route('route9', 'error_sub')
- config.add_view('.views.erroneous_sub_view', route_name='route9')
- # <!-- we want this view to "win" for route9 as exception view... -->
- config.add_view('.views.exception2_view', context='.views.SuperException',
- route_name='route9')
- # <!-- ...even if we have more context-specialized view for exception -->
- config.add_view('.views.exception_view', context='.views.SubException')
+ # <!-- the global view should be found for this route -->
+ config.add_route('route3', 'ghi', use_global_views=True)
+ # <!-- the global view should not be found for this route -->
+ config.add_route('route4', 'jkl')
+ # <!-- the global view should not be found for this route (/global2) -->
+ config.add_route('route5', 'mno/*traverse')
+ # <!-- the global view should be found for this route (/global2) -->
+ config.add_route('route6', 'pqr/*traverse', use_global_views=True)
+ config.add_route('route7', 'error')
+ config.add_view('.views.erroneous_view', route_name='route7')
+ config.add_route('route8', 'error2')
+ config.add_view('.views.erroneous_view', route_name='route8')
+ # <!-- we want this view to "win" for route7 as exception view -->
+ config.add_view('.views.exception_view', context=RuntimeError)
+ # <!-- we want this view to "win" for route8 as exception view-->
+ config.add_view(
+ '.views.exception2_view', context=RuntimeError, route_name='route8'
+ )
+ config.add_route('route9', 'error_sub')
+ config.add_view('.views.erroneous_sub_view', route_name='route9')
+ # <!-- we want this view to "win" for route9 as exception view... -->
+ config.add_view(
+ '.views.exception2_view',
+ context='.views.SuperException',
+ route_name='route9',
+ )
+ # <!-- ...even if we have more context-specialized view for exception -->
+ config.add_view('.views.exception_view', context='.views.SubException')
diff --git a/tests/pkgs/hybridapp/views.py b/tests/pkgs/hybridapp/views.py
index 135ef8290..695a79531 100644
--- a/tests/pkgs/hybridapp/views.py
+++ b/tests/pkgs/hybridapp/views.py
@@ -1,39 +1,49 @@
from webob import Response
+
def route_view(request):
""" """
return Response('route')
+
def global_view(request):
""" """
return Response('global')
+
def global2_view(request):
""" """
return Response('global2')
+
def route2_view(request):
""" """
return Response('route2')
+
def exception_view(request):
""" """
return Response('supressed')
+
def exception2_view(request):
""" """
return Response('supressed2')
+
def erroneous_view(request):
""" """
raise RuntimeError()
+
def erroneous_sub_view(request):
""" """
raise SubException()
+
class SuperException(Exception):
""" """
+
class SubException(SuperException):
""" """
diff --git a/tests/pkgs/includeapp1/root.py b/tests/pkgs/includeapp1/root.py
index 986356d81..369ab9f38 100644
--- a/tests/pkgs/includeapp1/root.py
+++ b/tests/pkgs/includeapp1/root.py
@@ -1,10 +1,11 @@
from pyramid.response import Response
+
def aview(request):
return Response('root')
+
def configure(config):
config.add_view(aview)
config.include('tests.pkgs.includeapp1.two.configure')
config.commit()
-
diff --git a/tests/pkgs/includeapp1/three.py b/tests/pkgs/includeapp1/three.py
index 973f91d99..b8d881244 100644
--- a/tests/pkgs/includeapp1/three.py
+++ b/tests/pkgs/includeapp1/three.py
@@ -1,10 +1,11 @@
from pyramid.response import Response
+
def aview(request):
return Response('three')
+
def configure(config):
config.add_view(aview, name='three')
- config.include('tests.pkgs.includeapp1.two.configure') # should not cycle
- config.add_view(aview) # will be overridden by root when resolved
-
+ config.include('tests.pkgs.includeapp1.two.configure') # should not cycle
+ config.add_view(aview) # will be overridden by root when resolved
diff --git a/tests/pkgs/includeapp1/two.py b/tests/pkgs/includeapp1/two.py
index 6b8bb5539..727161c8e 100644
--- a/tests/pkgs/includeapp1/two.py
+++ b/tests/pkgs/includeapp1/two.py
@@ -1,9 +1,11 @@
from pyramid.response import Response
+
def aview(request):
return Response('two')
+
def configure(config):
config.add_view(aview, name='two')
config.include('tests.pkgs.includeapp1.three.configure')
- config.add_view(aview) # will be overridden by root when resolved
+ config.add_view(aview) # will be overridden by root when resolved
diff --git a/tests/pkgs/notfoundview/__init__.py b/tests/pkgs/notfoundview/__init__.py
index 8ba3ff9ed..f606ec671 100644
--- a/tests/pkgs/notfoundview/__init__.py
+++ b/tests/pkgs/notfoundview/__init__.py
@@ -1,30 +1,35 @@
from pyramid.view import notfound_view_config, view_config
from pyramid.response import Response
+
@notfound_view_config(route_name='foo', append_slash=True)
-def foo_notfound(request): # pragma: no cover
+def foo_notfound(request): # pragma: no cover
return Response('foo_notfound')
+
@notfound_view_config(route_name='baz')
def baz_notfound(request):
return Response('baz_notfound')
+
@notfound_view_config(append_slash=True)
def notfound(request):
return Response('generic_notfound')
+
@view_config(route_name='bar')
def bar(request):
return Response('OK bar')
+
@view_config(route_name='foo2')
def foo2(request):
return Response('OK foo2')
+
def includeme(config):
config.add_route('foo', '/foo')
config.add_route('foo2', '/foo/')
config.add_route('bar', '/bar/')
config.add_route('baz', '/baz')
config.scan('tests.pkgs.notfoundview')
-
diff --git a/tests/pkgs/permbugapp/__init__.py b/tests/pkgs/permbugapp/__init__.py
index 4868427a5..aedd405f8 100644
--- a/tests/pkgs/permbugapp/__init__.py
+++ b/tests/pkgs/permbugapp/__init__.py
@@ -2,21 +2,26 @@ from pyramid.compat import escape
from pyramid.security import view_execution_permitted
from pyramid.response import Response
-def x_view(request): # pragma: no cover
- return Response('this is private!')
+
+def x_view(request): # pragma: no cover
+ return Response('this is private!')
+
def test(context, request):
# should return false
- msg = 'Allow ./x? %s' % repr(view_execution_permitted(
- context, request, 'x'))
- return Response(escape(msg))
+ msg = 'Allow ./x? %s' % repr(
+ view_execution_permitted(context, request, 'x')
+ )
+ return Response(escape(msg))
+
def includeme(config):
- from pyramid.authentication import AuthTktAuthenticationPolicy
- from pyramid.authorization import ACLAuthorizationPolicy
- authn_policy = AuthTktAuthenticationPolicy('seekt1t', hashalg='sha512')
- authz_policy = ACLAuthorizationPolicy()
- config.set_authentication_policy(authn_policy)
- config.set_authorization_policy(authz_policy)
- config.add_view(test, name='test')
- config.add_view(x_view, name='x', permission='private')
+ from pyramid.authentication import AuthTktAuthenticationPolicy
+ from pyramid.authorization import ACLAuthorizationPolicy
+
+ authn_policy = AuthTktAuthenticationPolicy('seekt1t', hashalg='sha512')
+ authz_policy = ACLAuthorizationPolicy()
+ config.set_authentication_policy(authn_policy)
+ config.set_authorization_policy(authz_policy)
+ config.add_view(test, name='test')
+ config.add_view(x_view, name='x', permission='private')
diff --git a/tests/pkgs/rendererscanapp/__init__.py b/tests/pkgs/rendererscanapp/__init__.py
index f3276a063..1fc831e66 100644
--- a/tests/pkgs/rendererscanapp/__init__.py
+++ b/tests/pkgs/rendererscanapp/__init__.py
@@ -1,9 +1,10 @@
from pyramid.view import view_config
+
@view_config(name='one', renderer='json')
def one(request):
- return {'name':'One!'}
+ return {'name': 'One!'}
+
def includeme(config):
config.scan()
-
diff --git a/tests/pkgs/rendererscanapp/two/__init__.py b/tests/pkgs/rendererscanapp/two/__init__.py
index 6f575dd83..7d3990317 100644
--- a/tests/pkgs/rendererscanapp/two/__init__.py
+++ b/tests/pkgs/rendererscanapp/two/__init__.py
@@ -1,6 +1,6 @@
from pyramid.view import view_config
+
@view_config(name='two', renderer='json')
def two(request):
- return {'nameagain':'Two!'}
-
+ return {'nameagain': 'Two!'}
diff --git a/tests/pkgs/restbugapp/__init__.py b/tests/pkgs/restbugapp/__init__.py
index 9ad79e32e..ae0a80f01 100644
--- a/tests/pkgs/restbugapp/__init__.py
+++ b/tests/pkgs/restbugapp/__init__.py
@@ -1,15 +1,19 @@
def includeme(config):
- config.add_route('gameactions_pet_get_pets', '/pet',
- request_method='GET')
- config.add_route('gameactions_pet_care_for_pet', '/pet',
- request_method='POST')
- config.add_view('.views.PetRESTView',
- route_name='gameactions_pet_get_pets',
- attr='GET',
- permission='view',
- renderer='json')
- config.add_view('.views.PetRESTView',
- route_name='gameactions_pet_care_for_pet',
- attr='POST',
- permission='view',
- renderer='json')
+ config.add_route('gameactions_pet_get_pets', '/pet', request_method='GET')
+ config.add_route(
+ 'gameactions_pet_care_for_pet', '/pet', request_method='POST'
+ )
+ config.add_view(
+ '.views.PetRESTView',
+ route_name='gameactions_pet_get_pets',
+ attr='GET',
+ permission='view',
+ renderer='json',
+ )
+ config.add_view(
+ '.views.PetRESTView',
+ route_name='gameactions_pet_care_for_pet',
+ attr='POST',
+ permission='view',
+ renderer='json',
+ )
diff --git a/tests/pkgs/restbugapp/views.py b/tests/pkgs/restbugapp/views.py
index 2ace59fa9..161321aed 100644
--- a/tests/pkgs/restbugapp/views.py
+++ b/tests/pkgs/restbugapp/views.py
@@ -1,15 +1,17 @@
from pyramid.response import Response
+
class BaseRESTView(object):
def __init__(self, context, request):
self.context = context
self.request = request
-
+
+
class PetRESTView(BaseRESTView):
""" REST Controller to control action of an avatar """
+
def __init__(self, context, request):
super(PetRESTView, self).__init__(context, request)
def GET(self):
return Response('gotten')
-
diff --git a/tests/pkgs/static_abspath/__init__.py b/tests/pkgs/static_abspath/__init__.py
index 812cca467..0c875b96f 100644
--- a/tests/pkgs/static_abspath/__init__.py
+++ b/tests/pkgs/static_abspath/__init__.py
@@ -1,7 +1,7 @@
import os
+
def includeme(config):
- here = here = os.path.dirname(__file__)
+ here = here = os.path.dirname(__file__)
fixtures = os.path.normpath(os.path.join(here, '..', '..', 'fixtures'))
config.add_static_view('/', fixtures)
-
diff --git a/tests/pkgs/static_assetspec/__init__.py b/tests/pkgs/static_assetspec/__init__.py
index dcb438aff..e7d3e9373 100644
--- a/tests/pkgs/static_assetspec/__init__.py
+++ b/tests/pkgs/static_assetspec/__init__.py
@@ -1,3 +1,2 @@
def includeme(config):
config.add_static_view('/', 'tests:fixtures')
-
diff --git a/tests/pkgs/static_routeprefix/__init__.py b/tests/pkgs/static_routeprefix/__init__.py
index 6a3a80712..f64f31292 100644
--- a/tests/pkgs/static_routeprefix/__init__.py
+++ b/tests/pkgs/static_routeprefix/__init__.py
@@ -2,6 +2,6 @@ def includeme(config):
config.add_static_view('/static', 'tests:fixtures')
config.include(includeme2, route_prefix='/prefix')
+
def includeme2(config):
config.add_static_view('/static', 'tests:fixtures/static')
-
diff --git a/tests/pkgs/staticpermapp/__init__.py b/tests/pkgs/staticpermapp/__init__.py
index b5038260f..ffc87d39a 100644
--- a/tests/pkgs/staticpermapp/__init__.py
+++ b/tests/pkgs/staticpermapp/__init__.py
@@ -1,25 +1,32 @@
class RootFactory(object):
__acl__ = [('Allow', 'fred', 'view')]
+
def __init__(self, request):
pass
+
class LocalRootFactory(object):
__acl__ = [('Allow', 'bob', 'view')]
+
def __init__(self, request):
pass
-
+
def includeme(config):
- from pyramid.authentication import RemoteUserAuthenticationPolicy
- from pyramid.authorization import ACLAuthorizationPolicy
- authn_policy = RemoteUserAuthenticationPolicy()
- authz_policy = ACLAuthorizationPolicy()
- config._set_authentication_policy(authn_policy)
- config._set_authorization_policy(authz_policy)
- config.add_static_view('allowed', 'tests:fixtures/static/')
- config.add_static_view('protected', 'tests:fixtures/static/',
- permission='view')
- config.add_static_view('factory_protected',
- 'tests:fixtures/static/',
- permission='view',
- factory=LocalRootFactory)
+ from pyramid.authentication import RemoteUserAuthenticationPolicy
+ from pyramid.authorization import ACLAuthorizationPolicy
+
+ authn_policy = RemoteUserAuthenticationPolicy()
+ authz_policy = ACLAuthorizationPolicy()
+ config._set_authentication_policy(authn_policy)
+ config._set_authorization_policy(authz_policy)
+ config.add_static_view('allowed', 'tests:fixtures/static/')
+ config.add_static_view(
+ 'protected', 'tests:fixtures/static/', permission='view'
+ )
+ config.add_static_view(
+ 'factory_protected',
+ 'tests:fixtures/static/',
+ permission='view',
+ factory=LocalRootFactory,
+ )
diff --git a/tests/pkgs/subrequestapp/__init__.py b/tests/pkgs/subrequestapp/__init__.py
index e4b1d386a..261af6434 100644
--- a/tests/pkgs/subrequestapp/__init__.py
+++ b/tests/pkgs/subrequestapp/__init__.py
@@ -1,26 +1,31 @@
from pyramid.config import Configurator
from pyramid.request import Request
+
def view_one(request):
subreq = Request.blank('/view_two')
response = request.invoke_subrequest(subreq, use_tweens=False)
return response
+
def view_two(request):
# check that request.foo is valid for a subrequest
return 'This came from view_two, foo=%s' % (request.foo,)
+
def view_three(request):
subreq = Request.blank('/view_four')
try:
return request.invoke_subrequest(subreq, use_tweens=True)
- except: # pragma: no cover
+ except: # pragma: no cover
request.response.body = b'Value error raised'
return request.response
+
def view_four(request):
raise ValueError('foo')
+
def view_five(request):
subreq = Request.blank('/view_four')
try:
@@ -29,11 +34,13 @@ def view_five(request):
request.response.body = b'Value error raised'
return request.response
+
def excview(request):
request.response.status_int = 500
request.response.body = b'Bad stuff happened'
return request.response
+
def main():
config = Configurator()
config.add_route('one', '/view_one')
@@ -49,4 +56,3 @@ def main():
config.add_view(view_five, route_name='five')
config.add_request_method(lambda r: 'bar', 'foo', property=True)
return config
-
diff --git a/tests/pkgs/viewdecoratorapp/__init__.py b/tests/pkgs/viewdecoratorapp/__init__.py
index 099bd29d5..99b7ea9c7 100644
--- a/tests/pkgs/viewdecoratorapp/__init__.py
+++ b/tests/pkgs/viewdecoratorapp/__init__.py
@@ -1,3 +1,2 @@
def includeme(config):
config.scan('tests.pkgs.viewdecoratorapp')
-
diff --git a/tests/pkgs/viewdecoratorapp/views/views.py b/tests/pkgs/viewdecoratorapp/views/views.py
index 18ec78847..6879acd2b 100644
--- a/tests/pkgs/viewdecoratorapp/views/views.py
+++ b/tests/pkgs/viewdecoratorapp/views/views.py
@@ -1,12 +1,11 @@
from pyramid.view import view_config
+
@view_config(renderer='json', name='first')
def first(request):
- return {'result':'OK1'}
+ return {'result': 'OK1'}
-@view_config(
- renderer='json',
- name='second')
-def second(request):
- return {'result':'OK2'}
+@view_config(renderer='json', name='second')
+def second(request):
+ return {'result': 'OK2'}
diff --git a/tests/pkgs/wsgiapp2app/__init__.py b/tests/pkgs/wsgiapp2app/__init__.py
index e2024198e..f7452f52c 100644
--- a/tests/pkgs/wsgiapp2app/__init__.py
+++ b/tests/pkgs/wsgiapp2app/__init__.py
@@ -1,6 +1,7 @@
from pyramid.view import view_config
from pyramid.wsgi import wsgiapp2
+
@view_config(name='hello', renderer='string')
@wsgiapp2
def hello(environ, start_response):
@@ -10,8 +11,10 @@ def hello(environ, start_response):
start_response('200 OK', response_headers)
return [b'Hello!']
+
def main():
from pyramid.config import Configurator
+
c = Configurator()
c.scan()
return c