def __init__(self, *args, **kargs): TestWSGIController.__init__(self, *args, **kargs) self.baseenviron = {} app = ControllerWrap(FilteredWSGIController) app = self.sap = SetupCacheGlobal(app, self.baseenviron) app = RegistryManager(app) self.app = TestApp(app)
def make_app(controller_klass, environ={}): """Creates a ``TestApp`` instance.""" # The basic middleware: app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # We're not going to use groups or permissions-related predicates here: groups_adapters = None permissions_adapters = None # Setting repoze.who up: cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, groups_adapters, permissions_adapters, identifiers=identifiers, authenticators=[], challengers=[], skip_authentication=True) app = httpexceptions.make_middleware(app) return TestApp(app)
def setUp(self): from pylons.testutil import ControllerWrap, SetupCacheGlobal ValidatingController = make_validating_controller() TestWSGIController.setUp(self) app = SetupCacheGlobal(ControllerWrap(ValidatingController), self.environ) app = RegistryManager(app) self.app = TestApp(app)
def setUp(self): from pylons.testutil import ControllerWrap, SetupCacheGlobal ProtectedController = make_protected() TestWSGIController.setUp(self) app = ControllerWrap(ProtectedController) app = SetupCacheGlobal(app, self.environ, setup_session=True) app = SessionMiddleware(app, {}, data_dir=session_dir) app = RegistryManager(app) self.app = TestApp(app)
def __init__(self, *args, **kargs): from pylons.testutil import ControllerWrap, SetupCacheGlobal BasicWSGIController, FilteredWSGIController = make_controllers() TestWSGIController.__init__(self, *args, **kargs) self.baseenviron = {} app = ControllerWrap(FilteredWSGIController) app = self.sap = SetupCacheGlobal(app, self.baseenviron) app = RegistryManager(app) self.app = TestApp(app)
def __init__(self, *args, **kwargs): from pylons.testutil import ControllerWrap, SetupCacheGlobal BaseJSONRPCController = make_basejsonrpc() TestWSGIController.__init__(self, *args, **kwargs) self.baseenviron = {} self.baseenviron['pylons.routes_dict'] = {} app = ControllerWrap(BaseJSONRPCController) app = self.sap = SetupCacheGlobal(app, self.baseenviron) app = RegistryManager(app) self.app = TestApp(app)
def setUp(self): from pylons.testutil import ControllerWrap, SetupCacheGlobal HttpsController = make_httpscontroller() TestWSGIController.setUp(self) from routes import Mapper map = Mapper() map.connect('/:action') map.connect('/:action/:id') map.connect('/:controller/:action/:id') map.connect('/:controller/:action') app = ControllerWrap(HttpsController) app = SetupCacheGlobal(app, self.environ, setup_cache=False) app = RoutesMiddleware(app, map) app = RegistryManager(app) self.app = TestApp(app)
def make_app(controller_klass=None, environ=None): """Creates a `TestApp` instance.""" if environ is None: environ = {} environ['pylons.routes_dict'] = {} environ['pylons.routes_dict']['action'] = "routes_placeholder" if controller_klass is None: controller_klass = TGController app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = beaker.middleware.SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) app = httpexceptions.make_middleware(app) return TestApp(app)
def __init__(self, *args, **kargs): TestWSGIController.__init__(self, *args, **kargs) class Callable(object): def __init__(self): self.called = False def __call__(self, *args, **kargs): self.called = True self.before_callable = Callable() self.after_callable = Callable() from pylons.controllers import WSGIController class Controller(WSGIController): def index(self): return 'index' __before__ = self.before_callable __after__ = self.after_callable from pylons.testutil import ControllerWrap, SetupCacheGlobal self.baseenviron = {} app = ControllerWrap(Controller) app = self.sap = SetupCacheGlobal(app, self.baseenviron) app = RegistryManager(app) self.app = TestApp(app)
def make_app(controller_klass, environ={}, with_errors=False): """Creates a ``TestApp`` instance.""" # The basic middleware: app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) if with_errors: app = ErrorHandler(app, {}, debug=False) app = StatusCodeRedirect(app, [403, 404, 500]) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # Setting repoze.who up: cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, TGAuthMetadata(), identifiers=identifiers, skip_authentication=True, authenticators=[], challengers=[]) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_app(controller_klass, environ={}): """Creates a `TestApp` instance.""" app = ControllerWrap(controller_klass) app = SetupCacheGlobal(app, environ, setup_cache=True, setup_session=True) app = RegistryManager(app) app = SessionMiddleware(app, {}, data_dir=session_dir) app = CacheMiddleware(app, {}, data_dir=os.path.join(data_dir, 'cache')) # Setting up the source adapters: groups_adapters = {'my_groups': FakeGroupSourceAdapter()} permissions_adapters = {'my_permissions': FakePermissionSourceAdapter()} # Setting up repoze.who: cookie = AuthTktCookiePlugin('secret', 'authtkt') identifiers = [('cookie', cookie)] app = setup_auth(app, groups_adapters, permissions_adapters, identifiers=identifiers, authenticators=[], challengers=[], skip_authentication=True) app = httpexceptions.make_middleware(app) return TestApp(app)
def make_cache_controller_app(): from pylons.testutil import ControllerWrap, SetupCacheGlobal from pylons.decorators import jsonify from pylons.controllers import WSGIController class CacheController(WSGIController): @jsonify def test_bad_json(self): return ["this is neat"] @jsonify def test_bad_json2(self): return ("this is neat", ) @jsonify def test_good_json(self): return dict(fred=42) environ = {} app = ControllerWrap(CacheController) app = sap = SetupCacheGlobal(app, environ) app = RegistryManager(app) app = TestApp(app) return app, environ
def make_cache_controller(): global sap import pylons from pylons.decorators.cache import beaker_cache, create_cache_key from pylons.controllers import WSGIController, XMLRPCController from pylons.testutil import SetupCacheGlobal, ControllerWrap class CacheController(WSGIController): @beaker_cache(key=None, invalidate_on_startup=True) def test_default_cache_decorator_invalidate(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(key=None) def test_default_cache_decorator(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter def test_default_cache_decorator_func(self): def func(): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter func = beaker_cache(key=None)(func) return func() def test_response_cache_func(self, use_cache_status=True): pylons.response.status_int = 404 def func(): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter if use_cache_status: func = beaker_cache(key=None)(func) else: func = beaker_cache(key=None, cache_response=False)(func) return func() @beaker_cache(key=None, type='dbm') def test_dbm_cache_decorator(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(key="param", query_args=True) def test_get_cache_decorator(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(query_args=True) def test_get_cache_default(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(expire=1) def test_expire_cache_decorator(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(expire=1) def test_expire_dbm_cache_decorator(self): pylons.app_globals.counter += 1 return 'Counter=%s' % pylons.app_globals.counter @beaker_cache(key="id") def test_key_cache_decorator(self, id): pylons.app_globals.counter += 1 return 'Counter=%s, id=%s' % (pylons.app_globals.counter, id) @beaker_cache(key=["id", "id2"]) def test_keyslist_cache_decorator(self, id, id2="123"): pylons.app_globals.counter += 1 return 'Counter=%s, id=%s' % (pylons.app_globals.counter, id) def test_invalidate_cache(self): ns, key = create_cache_key( CacheController.test_default_cache_decorator) c = pylons.cache.get_cache(ns) c.remove_value(key) def test_invalidate_dbm_cache(self): ns, key = create_cache_key( CacheController.test_dbm_cache_decorator) c = pylons.cache.get_cache(ns, type='dbm') c.remove_value(key) @beaker_cache(cache_headers=('content-type', 'content-length', 'x-powered-by')) def test_header_cache(self): pylons.response.headers['Content-Type'] = 'application/special' pylons.response.headers['x-powered-by'] = 'pylons' pylons.response.headers[ 'x-dont-include'] = 'should not be included' return "Hello folks, time is %s" % time.time() @beaker_cache(query_args=True) def test_cache_key_dupe(self): return "Hello folks, time is %s" % time.time() app = ControllerWrap(CacheController) app = sap = SetupCacheGlobal(app, environ, setup_cache=True) app = CacheMiddleware(app, {}, data_dir=cache_dir) app = RegistryManager(app) app = TestApp(app) # This one is missing cache middleware and the cache object to miss on purpsoe bad_app = ControllerWrap(CacheController) bad_app = SetupCacheGlobal(bad_app, environ, setup_cache=False) bad_app = RegistryManager(bad_app) bad_app = TestApp(bad_app) return app, bad_app
] return FeatureCollection(features) @_jsonify(cls=MapFishEncoder, cb='foo') def return_feature_with_callback(self): return Feature(id=1, geometry=Point(1, 2), properties={ "strkey": "strval", "boolkey": True }) environ = {} app = ControllerWrap(Controller) app = sap = SetupCacheGlobal(app, environ) app = RegistryManager(app) app = TestApp(app) class Test(TestWSGIController): def setUp(self): self.app = app TestWSGIController.setUp(self) warnings.simplefilter('error', Warning) def tearDown(self): warnings.simplefilter('always', Warning) def test_feature(self): response = self.get_response(action='return_feature')