Simplifies launching and terminating of web development servers from **BDD** or **functional** tests
Project description
Test Live Server moved to Live and Let Die!
https://pypi-hypernode.com/pypi/liveandletdie https://github.com/peterhudec/liveandletdie
Live and Let Die is a simple package to simplify launching and terminating of web development servers from BDD or functional tests. I have created it for functional testing of the Authomatic package.
Note that the package has just recently been renamed from former testliveserver to current liveandletdie!
The package Currently supports Google App engine, Django, Flask and wsgiref.simple_server. Support for other frameworks will hopefully be added in future.
Usage
You first need to make instance of one of the framework classes.
Django
import liveandletdie
# Django
app = liveandletdie.Django('path/to/django/project/',
host='0.0.0.0',
port=5555,
timeout=60.0)
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,
timeout=60.0)
Flask
By Flask you must wrap the WSGI application in liveandletdie.Flask.wrap(app).
# 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,
timeout=60.0)
Pyramid (wsgiref.simple_server)
By wsgiref.simple_server you must wrap the WSGI application in liveandletdie.WsgirefSimpleServer.wrap(app).
# 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,
timeout=60.0)
Using the App instance
The interface is the same for all of the supported frameworks.
# Start the app.
# If kill is True, it will kill any Python process listening on port 5555
process = app.live(kill=True)
# You can check whether it is running
is_running = app.check()
# Stop it
app.die()
Simple UnitTest example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py
Simple PyTest example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py
Simple Lettuce example: https://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py
Developers
Clone:
$ git clone https://github.com/peterhudec/liveandletdie.git
Bootstrap the development environment. This will create the ./venv virtual environment in the project root.
$ sh bootstrap.sh
Run tests:
$ sh run-all.sh
Enjoy!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file TestLiveServer-0.0.2.tar.gz
.
File metadata
- Download URL: TestLiveServer-0.0.2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dcabb9b19f333edf6ac7dd21c2a4a6f46af8c790d2d9d9b4710c3520e38d6ff |
|
MD5 | dfdd9c4109df3000f5dab751fe7ed915 |
|
BLAKE2b-256 | 59467eb0d472cb01fb10cc1b0c3e9c9b0e7d2ea20819e89417a08996f73435a3 |