简化从BDD和功能测试启动和终止Web开发服务器。
项目描述
Live and Let Die 简化了从 BDD 或 功能 测试中启动和终止 Web 开发服务器。我为此创建了它,用于 Authomatic 包的功能测试。
当前版本支持 Google App engine、Django、Flask 和 wsgiref.simple_server。未来可能会添加对其他框架的支持。
使用方法
首先,您需要创建一个框架类的一个实例。
Django
import liveandletdie
# Django
app = liveandletdie.Django('path/to/django/project/',
host='0.0.0.0',
port=5555)
Google App Engine
import liveandletdie
app = liveandletdie.GAE('path/to/dev_appserver.py',
'path/to/gae/app/dir', # containing app.yaml file
host='0.0.0.0',
port=5555)
Flask
使用 Flask 时,您必须使用 liveandletdie.Flask.wrap(app) 包装 WSGI 应用程序。
如果您将 ssl 关键字参数设置为 True,应用程序将以 ssl_context="adhoc" 运行,并且 self.check_url 的方案将为 "https"。
# flask/app/main.py
from flask import Flask
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def home():
return 'Hello World!'
if __name__ == '__main__':
# This does nothing unless you run this module with --liveandletdie flag.
import liveandletdie
liveandletdie.Flask.wrap(app)
app.run()
import liveandletdie
app = liveandletdie.Flask('path/to/flask/app/main.py',
host='0.0.0.0',
port=5555)
Pyramid (wsgiref.simple_server)
使用 wsgiref.simple_server 时,您必须使用 liveandletdie.WsgirefSimpleServer.wrap(app) 包装 WSGI 应用程序。
如果您将 ssl 关键字参数设置为 True,应用程序将以自签名证书运行,并且 self.check_url 的方案将为 "https"。
# pyramid/app/main.py
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def home(request):
return Response('Hello World!')
if __name__ == '__main__':
config = Configurator()
config.add_route('home', '/')
config.add_view(home, route_name='home')
app = config.make_wsgi_app()
# This does nothing unless you run this module with --liveandletdie flag.
import liveandletdie
liveandletdie.WsgirefSimpleServer.wrap(app)
server = make_server('127.0.0.1', 8080, app)
server.serve_forever()
import liveandletdie
app = liveandletdie.Flask('path/to/pyramid/app/main.py',
host='0.0.0.0',
port=5555)
使用 App 实例
所有支持的框架的接口都是相同的。
# Start the app.
# If kill_port is True,
# it will kill any process listening on port 5555
process = app.live(kill_port=True)
# You can check whether it is running
is_running = app.check()
# Stop it
app.die()
简单的 UnitTest 示例:[https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py](https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py)
简单的 PyTest 示例:[https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py](https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py)
简单的 Lettuce 示例:[https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py](https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py)
调试
如果应用程序在 app.live() 调用中拒绝启动,它将抛出带有消息的 LiveAndLetDieError。
Flask server https://127.0.0.1:5555 didn't start in specified timeout 10.0 seconds! command: python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555
要了解更多关于应用程序为什么无法启动的原因,请手动运行错误消息中提供的命令。
$ python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555
开发者
克隆
$ git clone https://github.com/peterhudec/liveandletdie.git
启动开发环境。这将创建项目根目录中的 ./venv 虚拟环境。
$ sh bootstrap.sh
运行测试
$ sh run-all.sh
或一步启动并运行测试
$ sh bootstrap-and-test.sh
享受吧!
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码发行版
构建的发行版
liveandletdie-0.0.9.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6c86f8c1654cc5aef33842bf5bc29e5e03876be4edf7ff11e6df80343942b4f9 |
|
MD5 | a8696f40a3d39d7bc63adbbbf6c69b22 |
|
BLAKE2b-256 | d4485540ffa2eec03aa3a5e140fd06d8f381841387fcb4797047040600f3d7b9 |
liveandletdie-0.0.9-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | bf693a81ea1ffd2de9ae1a5b4fdab05eef1709d9b9fa9350614534ddbff5e861 |
|
MD5 | 2918f9127e7dd12264dbc8617c1bf35e |
|
BLAKE2b-256 | 14fa94e597d17dc526a253d5de5117dcfb3a65da2c32cd93854c543a66e62e7a |