Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
from pyramid.renderers import JSONP
self.config = testing.setUp()
self.config.add_renderer('jsonp', JSONP(param_name='callback'))
self.config.include("cornice")
self.authz_policy = ACLAuthorizationPolicy()
self.config.set_authorization_policy(self.authz_policy)
self.authn_policy = AuthTktAuthenticationPolicy('$3kr1t')
self.config.set_authentication_policy(self.authn_policy)
add_view(ThingImp.collection_get, permission='read')
thing_resource = add_resource(
ThingImp, collection_path='/thing', path='/thing/{id}',
name='thing_service')
add_view(UserImp.get, renderer='json')
add_view(UserImp.get, renderer='jsonp', accept='application/javascript')
add_view(UserImp.collection_post, renderer='json', accept='application/json')
user_resource = add_resource(
UserImp, collection_path='/users', path='/users/{id}',
name='user_service', factory=dummy_factory)
self.config.add_cornice_resource(thing_resource)
self.config.add_cornice_resource(user_resource)
self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
def setUp(self):
from pyramid.renderers import JSONP
self.config = testing.setUp(autocommit=False)
self.config.add_renderer('jsonp', JSONP(param_name='callback'))
self.config.include("cornice")
add_view(UserImp.get, renderer='json')
# pyramid does not allow having 2 views with same request conditions
add_view(UserImp.get, renderer='jsonp', accept='application/javascript')
add_view(UserImp.collection_post, renderer='json', accept='application/json')
user_resource = add_resource(
UserImp, collection_path='/users', path='/users/{id}',
name='user_service', factory=dummy_factory)
self.config.add_cornice_resource(user_resource)
self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
def test_path_clash(self, mocked_warn):
class BadThingImp(object):
def __init__(self, request, context=None):
pass
add_resource(BadThingImp, collection_path='/badthing/{id}',
path='/badthing/{id}',
name='bad_thing_service')
msg = "Warning: collection_path and path are not distinct."
mocked_warn.assert_called_with(msg)
"""Add related_processes resource basing on some parent resource
:param configurator: pyramid configurator.
:param base_path: path for the resource.
:param factory: factory method from the corresponding traversal module.
"""
postfix = '/related_processes/{relatedProcess_id}'
collection_postfix = '/related_processes'
rp_path = base_path + postfix
rp_collection_path = base_path + collection_postfix
rp_res = resource.add_resource(
resource_class,
collection_path=rp_collection_path,
path=rp_path,
factory=factory
)
configurator.add_cornice_resource(rp_res)