This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Simplifies launching and terminating of web development servers from BDD and functional tests.

Project Description

Live and Let Die simplifies launching and terminating of web development servers from BDD or functional tests. I have created it for functional testing of the Authomatic package.

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)

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

By Flask you must wrap the WSGI application in liveandletdie.Flask.wrap(app).

If you set the ssl keyword argument to True, the app will be run with ssl_context="adhoc" and the schema of the self.check_url will be "https".

Warning

The Flask with ssl_context doesn’t work in Python 3 because Werkzeug still uses sys.maxint which is not supported in Python 3 (see https://github.com/mitsuhiko/werkzeug/issues/)

Note

If you are struggling with installation of pyOpenSSL on OSX due to 'ffi.h' file not found error during installation of the cryptography dependency, try the solution from this Stackoverflow question:

$ brew install pkg-config libffi
$ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
$ pip install pyopenssl
# 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)

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)

Using the App instance

The interface is the same for all of the supported frameworks.

# 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()

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

Debugging

If an app refuses to start on the app.live() call, it throws a LiveAndLetDieError with a message:

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

To find out more about why the app didn’t start run the command provided in the error message manually:

$ python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555

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

Or bootstrap and run tests in one step:

$ sh bootstrap-and-test.sh

Enjoy!

Release History

Release History

This version
History Node

0.0.6

History Node

0.0.5

History Node

0.0.4

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

History Node

0.0.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
liveandletdie-0.0.6.tar.gz (9.1 kB) Copy SHA256 Checksum SHA256 Source Jun 16, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting