liveandletdie


Nameliveandletdie JSON
Version 0.0.9 PyPI version JSON
download
home_pagehttp://github.com/peterhudec/liveandletdie
SummarySimplifies launching and terminating of web development servers from BDD and functional tests.
upload_time2023-06-09 12:15:22
maintainerAuthomatic Project Community
docs_urlNone
authorPeter Hudec
requires_python
licenseMIT
keywords flask pyramid django google app engine gae bdd tdd functional testing live server
VCS
bugtrack_url
requirements tox
Travis-CI
coveralls test coverage No coveralls.
            ================
Live and Let Die
================
.. image:: https://travis-ci.org/peterhudec/liveandletdie.svg?branch=master
    :target: https://travis-ci.org/peterhudec/liveandletdie

**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 <peterhudec.github.io/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
^^^^^^

.. code-block:: python

    import liveandletdie

    # Django
    app = liveandletdie.Django('path/to/django/project/',
                               host='0.0.0.0',
                               port=5555)

Google App Engine
^^^^^^^^^^^^^^^^^

.. code-block:: python

    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"``.

.. note::

    If you are struggling with installation of
    `pyOpenSSL <https://pypi.python.org/pypi/pyOpenSSL>`__ on OSX due to
    ``'ffi.h' file not found`` error during installation of the
    `cryptography <https://pypi.python.org/pypi/cryptography/0.7.2>`__
    dependency, try the solution from this
    `Stackoverflow question <http://stackoverflow.com/questions/22875270/error-installing-bcrypt-with-pip-on-os-x-cant-find-ffi-h-libffi-is-installed>`__:

    .. code-block:: bash

        $ brew install pkg-config libffi
        $ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/
        $ pip install pyopenssl

.. code-block:: python

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


.. code-block:: python

    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)``.

If you set the ``ssl`` keyword argument to ``True``, the app will be run with
a self-signed certificate, and the schema of the ``self.check_url``
will be ``"https"``.

.. code-block:: python

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


.. code-block:: python

    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.

.. code-block:: python

    # 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:

.. code-block:: bash

    $ 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!

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/peterhudec/liveandletdie",
    "name": "liveandletdie",
    "maintainer": "Authomatic Project Community",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "authomaticproject@protonmail.com",
    "keywords": "Flask,Pyramid,Django,Google App Engine,GAE,BDD,TDD,functional testing,live server",
    "author": "Peter Hudec",
    "author_email": "peterhudec@peterhudec.com",
    "download_url": "https://files.pythonhosted.org/packages/d4/48/5540ffa2eec03aa3a5e140fd06d8f381841387fcb4797047040600f3d7b9/liveandletdie-0.0.9.tar.gz",
    "platform": null,
    "description": "================\nLive and Let Die\n================\n.. image:: https://travis-ci.org/peterhudec/liveandletdie.svg?branch=master\n    :target: https://travis-ci.org/peterhudec/liveandletdie\n\n**Live and Let Die** simplifies launching and terminating of web development\nservers from **BDD** or **functional** tests. I have created it for functional\ntesting of the `Authomatic <peterhudec.github.io/authomatic/>`_ package.\n\nThe package Currently supports **Google App engine**, **Django**,\n**Flask** and **wsgiref.simple_server**. Support for other frameworks will\nhopefully be added in future.\n\nUsage\n-----\n\nYou first need to make instance of one of the framework classes.\n\nDjango\n^^^^^^\n\n.. code-block:: python\n\n    import liveandletdie\n\n    # Django\n    app = liveandletdie.Django('path/to/django/project/',\n                               host='0.0.0.0',\n                               port=5555)\n\nGoogle App Engine\n^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    import liveandletdie\n\n    app = liveandletdie.GAE('path/to/dev_appserver.py',\n                            'path/to/gae/app/dir', # containing app.yaml file\n                            host='0.0.0.0',\n                            port=5555)\n\nFlask\n^^^^^\n\nBy **Flask** you must wrap the **WSGI application** in\n``liveandletdie.Flask.wrap(app)``.\n\nIf you set the ``ssl`` keyword argument to ``True``, the app will be run with\n``ssl_context=\"adhoc\"`` and the schema of the ``self.check_url``\nwill be ``\"https\"``.\n\n.. note::\n\n    If you are struggling with installation of\n    `pyOpenSSL <https://pypi.python.org/pypi/pyOpenSSL>`__ on OSX due to\n    ``'ffi.h' file not found`` error during installation of the\n    `cryptography <https://pypi.python.org/pypi/cryptography/0.7.2>`__\n    dependency, try the solution from this\n    `Stackoverflow question <http://stackoverflow.com/questions/22875270/error-installing-bcrypt-with-pip-on-os-x-cant-find-ffi-h-libffi-is-installed>`__:\n\n    .. code-block:: bash\n\n        $ brew install pkg-config libffi\n        $ export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/\n        $ pip install pyopenssl\n\n.. code-block:: python\n\n    # flask/app/main.py\n    from flask import Flask\n\n    DEBUG = True\n    SECRET_KEY = 'development key'\n    USERNAME = 'admin'\n    PASSWORD = 'default'\n\n    app = Flask(__name__)\n    app.config.from_object(__name__)\n\n    @app.route('/')\n    def home():\n        return 'Hello World!'\n\n    if __name__ == '__main__':\n\n        # This does nothing unless you run this module with --liveandletdie flag.\n        import liveandletdie\n        liveandletdie.Flask.wrap(app)\n\n        app.run()\n\n\n.. code-block:: python\n\n    import liveandletdie\n\n    app = liveandletdie.Flask('path/to/flask/app/main.py',\n                              host='0.0.0.0',\n                              port=5555)\n\nPyramid (wsgiref.simple_server)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBy ``wsgiref.simple_server`` you must wrap the **WSGI application** in\n``liveandletdie.WsgirefSimpleServer.wrap(app)``.\n\nIf you set the ``ssl`` keyword argument to ``True``, the app will be run with\na self-signed certificate, and the schema of the ``self.check_url``\nwill be ``\"https\"``.\n\n.. code-block:: python\n\n    # pyramid/app/main.py\n    from wsgiref.simple_server import make_server\n\n    from pyramid.config import Configurator\n    from pyramid.response import Response\n\n\n    def home(request):\n        return Response('Hello World!')\n\n\n    if __name__ == '__main__':\n\n        config = Configurator()\n        config.add_route('home', '/')\n        config.add_view(home, route_name='home')\n        app = config.make_wsgi_app()\n\n        # This does nothing unless you run this module with --liveandletdie flag.\n        import liveandletdie\n        liveandletdie.WsgirefSimpleServer.wrap(app)\n\n        server = make_server('127.0.0.1', 8080, app)\n        server.serve_forever()\n\n\n.. code-block:: python\n\n    import liveandletdie\n\n    app = liveandletdie.Flask('path/to/pyramid/app/main.py',\n                              host='0.0.0.0',\n                              port=5555)\n\nUsing the App instance\n^^^^^^^^^^^^^^^^^^^^^^\n\nThe interface is the same for all of the supported frameworks.\n\n.. code-block:: python\n\n    # Start the app.\n    # If kill_port is True,\n    # it will kill any process listening on port 5555\n    process = app.live(kill_port=True)\n\n    # You can check whether it is running\n    is_running = app.check()\n\n    # Stop it\n    app.die()\n\nSimple UnitTest example:\nhttps://github.com/peterhudec/liveandletdie/blob/master/test_examples/unittest_example/tests.py\n\nSimple PyTest example:\nhttps://github.com/peterhudec/liveandletdie/blob/master/test_examples/pytest_example/tests.py\n\nSimple Lettuce example:\nhttps://github.com/peterhudec/liveandletdie/blob/master/test_examples/lettuce_example/tests.py\n\nDebugging\n---------\n\nIf an app refuses to start on the ``app.live()`` call, it throws a\n``LiveAndLetDieError`` with a message::\n\n    Flask server https://127.0.0.1:5555 didn't start in specified timeout 10.0 seconds!\n    command: python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555\n\nTo find out more about why the app didn't start run the command provided in the\nerror message manually:\n\n.. code-block:: bash\n\n    $ python sample_apps/flask/main.py --liveandletdie 127.0.0.1:5555\n\nDevelopers\n----------\n\nClone:\n\n::\n    \n    $ git clone https://github.com/peterhudec/liveandletdie.git\n\nBootstrap the development environment.\nThis will create the ``./venv`` virtual environment in the project root.\n\n::\n    \n    $ sh bootstrap.sh\n\nRun tests:\n\n::\n    \n    $ sh run-all.sh\n\nOr bootstrap and run tests in one step:\n\n::\n\n    $ sh bootstrap-and-test.sh\n\nEnjoy!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simplifies launching and terminating of web development servers from BDD and functional tests.",
    "version": "0.0.9",
    "project_urls": {
        "Homepage": "http://github.com/peterhudec/liveandletdie"
    },
    "split_keywords": [
        "flask",
        "pyramid",
        "django",
        "google app engine",
        "gae",
        "bdd",
        "tdd",
        "functional testing",
        "live server"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14fa94e597d17dc526a253d5de5117dcfb3a65da2c32cd93854c543a66e62e7a",
                "md5": "2918f9127e7dd12264dbc8617c1bf35e",
                "sha256": "bf693a81ea1ffd2de9ae1a5b4fdab05eef1709d9b9fa9350614534ddbff5e861"
            },
            "downloads": -1,
            "filename": "liveandletdie-0.0.9-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2918f9127e7dd12264dbc8617c1bf35e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8760,
            "upload_time": "2023-06-09T12:15:20",
            "upload_time_iso_8601": "2023-06-09T12:15:20.474225Z",
            "url": "https://files.pythonhosted.org/packages/14/fa/94e597d17dc526a253d5de5117dcfb3a65da2c32cd93854c543a66e62e7a/liveandletdie-0.0.9-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4485540ffa2eec03aa3a5e140fd06d8f381841387fcb4797047040600f3d7b9",
                "md5": "a8696f40a3d39d7bc63adbbbf6c69b22",
                "sha256": "6c86f8c1654cc5aef33842bf5bc29e5e03876be4edf7ff11e6df80343942b4f9"
            },
            "downloads": -1,
            "filename": "liveandletdie-0.0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "a8696f40a3d39d7bc63adbbbf6c69b22",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19268,
            "upload_time": "2023-06-09T12:15:22",
            "upload_time_iso_8601": "2023-06-09T12:15:22.504966Z",
            "url": "https://files.pythonhosted.org/packages/d4/48/5540ffa2eec03aa3a5e140fd06d8f381841387fcb4797047040600f3d7b9/liveandletdie-0.0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-09 12:15:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "peterhudec",
    "github_project": "liveandletdie",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "tox",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "liveandletdie"
}
        
Elapsed time: 0.09915s