Skip to main content

Document a flask API with Optic

Project description

Optic for Flask

Optic Proxy Setup

Python APIs built on top of Flask are easy to connect to Optic using our custom middleware. In this tutorial we'll show you how to connect the Optic Documenting Middleware to your Flask app so that your integration tests document your code as they execute.

Add the Middleware to your Project

Install the Optic Documenting Middleware using pip

pip3 install optic-document-flask

Making the Middleware Run During Testing

Now add the middleware to your Flask App. Since we only want the middleware to run while Optic executes your tests, make sure you wrap it in a check for the OPTIC_SERVER_LISTENING environment variable.

We like performing this check within the block where we setup our test config, but you can do it anywhere that makes sense for your app.

from optic import OpticDocumentingMiddleware

def create_app(test_config=None):

    # Setup Code...

    if test_config is None:
        # load the instance config, if it exists, when not testing
        app.config.from_pyfile('config.py', silent=True)
    else:
        if 'OPTIC_SERVER_LISTENING' in os.environ:
            OpticDocumentingMiddleware(app)
        app.config.update(test_config)
    return app

Using the Proxy Fixture

The Documenting middleware will document all the requests/responses that your tests run. Since it is integrated at the middleware level there's no need to update any of your tests files or fixtures.

Project details


Download files

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

Source Distribution

optic-document-flask-0.1.3.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optic_document_flask-0.1.3-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file optic-document-flask-0.1.3.tar.gz.

File metadata

  • Download URL: optic-document-flask-0.1.3.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for optic-document-flask-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ca9bfe37a6c6f9b7981d053f9ed342a9c97eade372c8b6e6142a9ba4cc74b81e
MD5 0a347a4b445409dea817fb4a5290fcaa
BLAKE2b-256 1c21d61b7674d9203bf47c7b9554e852d3b25776a8f674c21a82de0d266228a3

See more details on using hashes here.

File details

Details for the file optic_document_flask-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: optic_document_flask-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

File hashes

Hashes for optic_document_flask-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c6de2a63167dee712ca2f43d4e3b9d7804227f9f36bcfa949389bb5dadb8e8f9
MD5 e37cb6fbf8df994cd7eb508165e27a05
BLAKE2b-256 0563d05daa0d8d01519016986e738ae02efdc172dd6848e26026e463d7469d9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page