本文整理汇总了Python中aspen.testing.client.Client类的典型用法代码示例。如果您正苦于以下问题:Python Client类的具体用法?Python Client怎么用?Python Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: Harness
class Harness(object):
"""A harness to be used in the Aspen test suite itself. Probably not useful to you.
"""
def __init__(self):
self.fs = namedtuple('fs', 'www project')
self.fs.www = FilesystemTree()
self.fs.project = FilesystemTree()
self.client = Client(self.fs.www.root, self.fs.project.root)
def teardown(self):
self.fs.www.remove()
self.fs.project.remove()
# Simple API
# ==========
def simple(self, contents='Greetings, program!', filepath='index.html.spt', uripath=None,
argv=None, **kw):
"""A helper to create a file and hit it through our machinery.
"""
if filepath is not None:
self.fs.www.mk((filepath, contents))
if argv is not None:
self.client.hydrate_website(argv)
if uripath is None:
if filepath is None:
uripath = '/'
else:
uripath = '/' + filepath
if uripath.endswith('.spt'):
uripath = uripath[:-len('.spt')]
for indexname in self.client.website.indices:
if uripath.endswith(indexname):
uripath = uripath[:-len(indexname)]
break
return self.client.GET(uripath, **kw)
def make_request(self, *a, **kw):
kw['return_after'] = 'dispatch_request_to_filesystem'
kw['want'] = 'request'
return self.simple(*a, **kw)
def make_dispatch_result(self, *a, **kw):
kw['return_after'] = 'dispatch_request_to_filesystem'
kw['want'] = 'dispatch_result'
return self.simple(*a, **kw)
开发者ID:Acidburn0zzz,项目名称:aspen-python,代码行数:50,代码来源:harness.py
示例2: compile_assets
def compile_assets(website):
client = Client(website.www_root, website.project_root)
client._website = website
for spt in find_files(website.www_root+'/assets/', '*.spt'):
filepath = spt[:-4] # /path/to/www/assets/foo.css
urlpath = spt[spt.rfind('/assets/'):-4] # /assets/foo.css
try:
# Remove any existing compiled asset, so we can access the dynamic
# one instead (Aspen prefers foo.css over foo.css.spt).
os.unlink(filepath)
except:
pass
content = client.GET(urlpath).body
tmpfd, tmpfpath = mkstemp(dir='.')
os.write(tmpfd, content)
os.close(tmpfd)
os.rename(tmpfpath, filepath)
开发者ID:webmaven,项目名称:gratipay.com,代码行数:17,代码来源:wireup.py
示例3: compile_assets
def compile_assets(website):
client = Client(website.www_root, website.project_root)
client._website = website
for spt in find_files(website.www_root+'/assets/', '*.spt'):
filepath = spt[:-4] # /path/to/www/assets/foo.css
urlpath = spt[spt.rfind('/assets/'):-4] # /assets/foo.css
try:
# Remove any existing compiled asset, so we can access the dynamic
# one instead (Aspen prefers foo.css over foo.css.spt).
os.unlink(filepath)
except:
pass
headers = {}
if website.base_url:
url = urlparse.urlparse(website.base_url)
headers[b'HTTP_X_FORWARDED_PROTO'] = str(url.scheme)
headers[b'HTTP_HOST'] = str(url.netloc)
content = client.GET(urlpath, **headers).body
tmpfd, tmpfpath = mkstemp(dir='.')
os.write(tmpfd, content.encode('utf8'))
os.close(tmpfd)
os.rename(tmpfpath, filepath)
atexit.register(lambda: clean_assets(website.www_root))
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:23,代码来源:wireup.py
示例4: build_wsgi_environ
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
# csrf - for both anon and authenticated
self.cookie[b'csrf_token'] = b'sotokeny'
kw[b'HTTP_X-CSRF-TOKEN'] = b'sotokeny'
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as is None:
if SESSION in self.cookie:
del self.cookie[SESSION]
else:
user = User.from_username(auth_as)
user.sign_in(self.cookie)
return Client.build_wsgi_environ(self, *a, **kw)
开发者ID:atunit,项目名称:www.gittip.com,代码行数:18,代码来源:__init__.py
示例5: build_wsgi_environ
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
self.cookie.clear()
# csrf - for both anon and authenticated
csrf_token = kw.get('csrf_token', b'ThisIsATokenThatIsThirtyTwoBytes')
if csrf_token:
self.cookie[b'csrf_token'] = csrf_token
kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as:
user.User.from_username(auth_as).sign_in(self.cookie)
for k, v in kw.pop('cookies', {}).items():
self.cookie[k] = v
return Client.build_wsgi_environ(self, *a, **kw)
开发者ID:PeterDaveHello,项目名称:gratipay.com,代码行数:21,代码来源:harness.py
示例6: build_wsgi_environ
def build_wsgi_environ(self, *a, **kw):
"""Extend base class to support authenticating as a certain user.
"""
self.cookie.clear()
# csrf - for both anon and authenticated
csrf_token = kw.get('csrf_token', b'ThisIsATokenThatIsThirtyTwoBytes')
if csrf_token:
self.cookie[b'csrf_token'] = csrf_token
kw[b'HTTP_X-CSRF-TOKEN'] = csrf_token
# user authentication
auth_as = kw.pop('auth_as', None)
if auth_as:
assert auth_as.session_token
self.cookie[SESSION] = '%s:%s' % (auth_as.id, auth_as.session_token)
# cookies
for k, v in kw.pop('cookies', {}).items():
self.cookie[k] = v
return Client.build_wsgi_environ(self, *a, **kw)
开发者ID:fracolo,项目名称:liberapay.com,代码行数:23,代码来源:__init__.py
示例7: __init__
def __init__(self, *a, **kw):
Client.__init__(self, *a, **kw)
Client.website = website
开发者ID:PeterDaveHello,项目名称:gratipay.com,代码行数:3,代码来源:harness.py
示例8: __init__
def __init__(self, *a, **kw):
Client.__init__(self, *a, **kw)
Client.website = Client.hydrate_website(self)
开发者ID:beerm,项目名称:gratipay.com,代码行数:3,代码来源:__init__.py
示例9: __init__
def __init__(self):
self.fs = namedtuple("fs", "www project")
self.fs.www = FilesystemTree()
self.fs.project = FilesystemTree()
self.client = Client(self.fs.www.root, self.fs.project.root)
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:5,代码来源:harness.py
示例10: Harness
class Harness(object):
"""A harness to be used in the Aspen test suite itself. Probably not useful to you.
"""
def __init__(self):
self.fs = namedtuple("fs", "www project")
self.fs.www = FilesystemTree()
self.fs.project = FilesystemTree()
self.client = Client(self.fs.www.root, self.fs.project.root)
def teardown(self):
self.fs.www.remove()
self.fs.project.remove()
# Simple API
# ==========
def simple(self, contents="Greetings, program!", filepath="index.html.spt", uripath=None, argv=None, **kw):
"""A helper to create a file and hit it through our machinery.
"""
if filepath is not None:
self.fs.www.mk((filepath, contents))
if argv is not None:
self.client.hydrate_website(argv)
if uripath is None:
if filepath is None:
uripath = "/"
else:
uripath = "/" + filepath
if uripath.endswith(".spt"):
uripath = uripath[: -len(".spt")]
for indexname in self.client.website.indices:
if uripath.endswith(indexname):
uripath = uripath[: -len(indexname)]
break
return self.client.GET(uripath, **kw)
def make_request(self, *a, **kw):
kw["return_after"] = "dispatch_request_to_filesystem"
kw["want"] = "request"
return self.simple(*a, **kw)
# Sockets
# =======
def make_transport(self, content="", state=0):
self.fs.www.mk(("echo.sock.spt", content))
socket = self.make_socket()
transport = XHRPollingTransport(socket)
transport.timeout = 0.05 # for testing, could screw up the test
if state == 1:
transport.respond(Request(uri="/echo.sock"))
return transport
def make_socket_request(self, filename="echo.sock.spt"):
request = Request(uri="/echo.sock")
request.website = self.client.website
request.fs = self.fs.www.resolve(filename)
return request
def make_socket(self, filename="echo.sock.spt", channel=None):
request = self.make_socket_request(filename="echo.sock.spt")
if channel is None:
channel = Channel(request.line.uri.path.raw, ThreadedBuffer)
socket = Socket(request, channel)
return socket
def SocketInThread(harness):
class _SocketInThread(object):
def __enter__(self, filename="echo.sock.spt"):
self.socket = harness.make_socket(filename)
self.socket.loop.start()
return self.socket
def __exit__(self, *a):
self.socket.loop.stop()
return _SocketInThread()
开发者ID:BigBlueHat,项目名称:aspen-python,代码行数:80,代码来源:harness.py
示例11: client
def client():
client = Client(www_root='www', project_root='.')
client._website = website
yield client
开发者ID:gratipay,项目名称:inside.gratipay.com,代码行数:4,代码来源:test_security.py
示例12: __init__
def __init__(self, *a, **kw):
Client.__init__(self, *a, **kw)
Client.app = _get_app()
Client.website = Client.app.website
开发者ID:cyberjacob,项目名称:www.gittip.com,代码行数:4,代码来源:harness.py
注:本文中的aspen.testing.client.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论