本文整理汇总了Python中wsgi_intercept.add_wsgi_intercept函数的典型用法代码示例。如果您正苦于以下问题:Python add_wsgi_intercept函数的具体用法?Python add_wsgi_intercept怎么用?Python add_wsgi_intercept使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_wsgi_intercept函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_module
def setup_module(module):
# cleanup
try:
shutil.rmtree('store')
except OSError:
pass
# establish web server
app = load_app()
def app_fn():
return app
httplib2_intercept.install()
wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
# establish store
store = Store(config['server_store'][0], config['server_store'][1],
environ={'tiddlyweb.config': config})
# make some stuff
bag = Bag('place')
store.put(bag)
for i in range(1, 10):
tiddler = Tiddler('tiddler%s' % i, 'place')
tiddler.text = 'hi%s'
store.put(tiddler)
module.http = httplib2.Http()
示例2: browser
def browser(db_session, request, setup_app):
""" returns an instance of `zope.testbrowser`. The `kotti.testing.user`
pytest marker (or `pytest.mark.user`) can be used to pre-authenticate
the browser with the given login name: `@user('admin')`.
"""
from wsgi_intercept import add_wsgi_intercept, zope_testbrowser
from kotti.testing import BASE_URL
host, port = BASE_URL.split(":")[-2:]
add_wsgi_intercept(host[2:], int(port), lambda: setup_app)
browser = zope_testbrowser.WSGI_Browser(BASE_URL + "/")
if "user" in request.keywords:
# set auth cookie directly on the browser instance...
from pyramid.security import remember
from pyramid.testing import DummyRequest
login = request.keywords["user"].args[0]
environ = dict(HTTP_HOST=host[2:])
for _, value in remember(DummyRequest(environ=environ), login):
cookie, _ = value.split(";", 1)
name, value = cookie.split("=")
if name in browser.cookies:
del browser.cookies[name]
browser.cookies.create(name, value.strip('"'), path="/")
return browser
示例3: _initialize_app
def _initialize_app(tmpdir): # XXX: side-effecty and inscrutable
instance_dir = os.path.join(tmpdir, 'instance')
spawn(instance_dir, init_config, instance)
old_cwd = os.getcwd()
os.chdir(instance_dir)
# force loading of instance's `tiddlywebconfig.py`
while old_cwd in sys.path:
sys.path.remove(old_cwd)
sys.path.insert(0, os.getcwd())
merge_config(CONFIG, {}, reconfig=True) # XXX: should not be necessary!?
CONFIG['server_host'] = {
'scheme': 'http',
'host': 'example.org',
'port': '8001',
}
# TODO: test with server_prefix
# add symlink to templates -- XXX: hacky, should not be necessary!?
templates_path = instance.__file__.split(os.path.sep)[:-2] + ['templates']
os.symlink(os.path.sep.join(templates_path), 'templates')
httplib2_intercept.install()
wsgi_intercept.add_wsgi_intercept('example.org', 8001, load_app)
示例4: setup_module
def setup_module(module):
module.store = Store('ramstore', {}, {})
config['server_store'] = ['ramstore', {}]
def app_fn():
return serve.load_app()
httplib2_intercept.install()
wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
示例5: __init__
def __init__(self, app):
self.app = app
host = 'example.com'
port = 80
self.base = 'http://%s:%d' % (host, port)
wsgi_intercept.add_wsgi_intercept(host, port, lambda: self.app)
self.opener = urllib2.build_opener(WSGI_HTTPHandler())
示例6: setup_module
def setup_module(module):
from paste.script import testapp
static_app = StaticURLParser(os.path.join(os.path.dirname(__file__),
'test-static'))
wsgi_intercept.add_wsgi_intercept('wsgify.org', 80, lambda : static_app)
wsgi_intercept.add_wsgi_intercept('wsgify.org', 9999, lambda : testapp.TestApplication(text=True))
示例7: setup
def setup(self, request, tmpdir):
if ver(radicale.VERSION) < ver('2.0.0-pre'):
raise RuntimeError('Testing against Radicale only works with '
'Radicale >= 2.0.0')
def get_app():
config = radicale.config.load(())
config.set('storage', 'filesystem_folder', str(tmpdir))
config.set('rights', 'type', 'owner_only')
app = radicale.Application(config, logger)
def is_authenticated(user, password):
return user == 'bob' and password == 'bob'
app.is_authenticated = is_authenticated
return app
wsgi_intercept.requests_intercept.install()
wsgi_intercept.add_wsgi_intercept('127.0.0.1', 80, get_app)
def teardown():
wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 80)
wsgi_intercept.requests_intercept.uninstall()
request.addfinalizer(teardown)
示例8: __init__
def __init__(self, port=8000):
"""Initializes the mock server on localhost port 8000. Use
urllib2.urlopen('http://localhost:8000') to reach the test
server. The constructor takes a 'port=<int>' argument if you
want the server to listen on a different port."""
wsgi_intercept.add_wsgi_intercept('localhost', port, self.interceptor)
wsgi_urllib2.install_opener()
示例9: setup_module
def setup_module(module):
make_test_env(module)
httplib2_intercept.install()
wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)
wsgi_intercept.add_wsgi_intercept('thing.0.0.0.0', 8080, app_fn)
module.http = httplib2.Http()
make_fake_space(store, 'thing')
示例10: setup_intercept
def setup_intercept(self, callbacks, intercept_api=False):
"""Setup the WSGI intercepts.
`callbacks` have to be provided to call upon request of the
intercepted urls. They should be supplied as a dictionary of
((hostname, port), callback).
Additionally one extra `default` callback has to be passed in,
in the form ('default', callback).
The `intercept_api` parameter is used to install the `httplib2`
intercepts, used to intercept the lazr.restful api calls.
"""
self.patch_wsgi_intercept()
self.intercepted = []
install_opener()
self.intercept_api = intercept_api
if intercept_api:
install()
for key, callback in callbacks.items():
if key == 'default':
continue
host, port = key
add_wsgi_intercept(host, port, callback)
self.intercepted.append((host, port))
示例11: initialize_fakes
def initialize_fakes(app):
# Set up WSGI interceptor. This sets up a fake host that responds each
# time httplib tries to communicate to localhost, port 8779.
def wsgi_interceptor(*args, **kwargs):
def call_back(env, start_response):
path_info = env.get('PATH_INFO')
if path_info:
env['PATH_INFO'] = urllib.unquote(path_info)
#print("%s %s" % (args, kwargs))
return app.__call__(env, start_response)
return call_back
wsgi_intercept.add_wsgi_intercept('localhost',
CONF.bind_port,
wsgi_interceptor)
# Finally, engage in some truly evil monkey business. We want
# to change anything which spawns threads with eventlet to instead simply
# put those functions on a queue in memory. Then, we swap out any functions
# which might try to take a nap to instead call functions that go through
# this queue and call the functions that would normally run in seperate
# threads.
import eventlet
from reddwarf.tests.fakes.common import event_simulator_sleep
eventlet.sleep = event_simulator_sleep
greenthread.sleep = event_simulator_sleep
import time
time.sleep = event_simulator_sleep
示例12: setup_module
def setup_module(module):
try:
shutil.rmtree('indexdir')
shutil.rmtree('store')
except:
pass
app = load_app()
def app_fn(): return app
requests_intercept.install()
wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)
store = get_store(config)
test_bag1 = Bag('newtank')
try:
store.delete(test_bag1)
except StoreError:
pass
test_bag1.policy.accept = ['NONE']
store.put(test_bag1)
module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
module.store = store
module.cookie, module.csrf = establish_user_auth(config, store,
'tankt.peermore.com:8080', 'tester')
示例13: test_mozilla_auth
def test_mozilla_auth(self):
if not DO_TESTS:
return
wsgi_intercept.add_wsgi_intercept('localhost', 80, fake_response)
auth = MozillaAuth('ldap://localhost',
'localhost', 'this_path', 'http')
auth.create_user('tarek', 'tarek', '[email protected]')
uid = auth.get_user_id('tarek')
auth_uid = auth.authenticate_user('tarek', 'tarek')
self.assertEquals(auth_uid, uid)
#password change with no old password (sreg)
self.assertTrue(auth.generate_reset_code(uid))
self.assertTrue(auth.admin_update_password(uid, 'newpass', key='foo'))
#password change with old password (ldap)
self.assertTrue(auth.update_password(uid, 'newpass', 'tarek'))
auth_uid = auth.authenticate_user('tarek', 'newpass')
self.assertEquals(auth_uid, uid)
self.assertEquals(auth.get_user_node(uid), 'foo')
auth.clear_reset_code(uid)
wsgi_intercept.add_wsgi_intercept('localhost', 80, bad_reset_code_resp)
self.assertFalse(auth.admin_update_password(uid, 'newpass', key='foo'))
示例14: setup_module
def setup_module(module):
module.store = get_store(config)
# cascade to deal with differently named files depending on
# anydbm impelementation
try:
os.unlink('links.db')
except OSError:
pass # not there
module.links_manager = LinksManager()
try:
shutil.rmtree('store')
except:
pass
def app():
return serve.load_app()
httplib2_intercept.install()
wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app)
# for @someone syntax to test correctly we need a corresponding
# recipe
module.store.put(Bag('cdent_public'))
recipe = Recipe('cdent_public')
recipe.set_recipe([('cdent_public', '')])
module.store.put(recipe)
示例15: get_storage_args
def get_storage_args(self, request, get_item, tmpdir, etesync_app):
import wsgi_intercept
import wsgi_intercept.requests_intercept
wsgi_intercept.requests_intercept.install()
wsgi_intercept.add_wsgi_intercept('127.0.0.1', 8000,
lambda: etesync_app)
def teardown():
wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 8000)
wsgi_intercept.requests_intercept.uninstall()
request.addfinalizer(teardown)
with open(os.path.join(os.path.dirname(__file__),
'[email protected]/auth_token')) as f:
token = f.read().strip()
headers = {'Authorization': 'Token ' + token}
r = requests.post('http://127.0.0.1:8000/reset/', headers=headers,
allow_redirects=False)
assert r.status_code == 200
def inner(collection='test'):
rv = {
'email': '[email protected]',
'db_path': str(tmpdir.join('etesync.db')),
'secrets_dir': os.path.dirname(__file__),
'server_url': 'http://127.0.0.1:8000/'
}
if collection is not None:
rv = self.storage_class.create_collection(
collection=collection,
**rv
)
return rv
return inner