/bpm-projects-api

API for managing projects in the BPM

Primary LanguagePython

BPM Projects API

Build Status Build status Deployment Status

API for BPM Projects

Getting started

Follow the following instructions to get the project ready to use ASAP:

Requirements

Be sure you have installed in your system

Install

Go to the directory of the project

  1. Install the virtual environment

    virtualenv env
    source env/bin/activate
  2. Install the dependencies using the requirements.txt

    For development

     pip install -r requirements/dev.txt

    For production

     pip install -r requirements.txt

Current Environments

There are dependencies for multiple environments:

  • dev: Used for development. Tries to simplify complexity in sake of a better understanding of the bussiness logic.

  • prod: Like dev but for production.

  • azure-dev: Used for development using real Azure resources, i.e. it connects remotely to try real PaaS provided by Azure, e.g. a Mongo database in Azure Cosmos DB. It requires:

    • A MongoDB database installed and running in the local pc
  • azure-prod: Alike to azure-dev but for production

Its highly recommended a virtual environment be created for each configuration.

Usage

Run the project using

  1. For using Flask's development capabilities as the autoloading set this FLASK_ENV environment variable to development, i.e.

    export FLASK_ENV=development
  2. Run the app with one of the following commands:

    • python3 -m bpm_projects_api thanks to the __main__.py
    • gunicorn -b 0.0.0.0:8000 run:app

What it basically does is to set the FLASK_APP env variable to the main package and run the app using Flask. If you are using an IDE like PyCharm the process is way easier because they support configurations for running Flask projects.

  1. The main page provides a nice client to test the API and even for you to provide your JWT: Click the lock.
  2. To get a token, go to /login and authenticate with any username and password secret (Just for now of course).
  3. In the main page you will also find a Models section for you to check the schema of the managed resources: projects and its metadata.
  4. The swagger schema can be found in /swagger.json. You can even generate client code for this API thanks to this file.

The use of an IDE is highly recommended, namely PyCharm.

Notes

Have in consideration that the token will expire each minute.

Tests

To execute all tests just run

 python3 -m pytest -v

The -v shows which tests failed or succeeded. Have in count that you can also debug each test (test_* files) with the help of an IDE like PyCharm.

Coverage

To check the coverage of the tests execute

 coverage run -m pytest -v

To get a report table

 coverage report

To get a full report in html

 coverage html

Then check in the htmlcov/index.html to see it

CLI

To show all possible commands to use in the project please execute:

 python cli.py

Generate postman collections

You can generate Postman collections with the CLI using

 python cli.py gen_postman_collection

It will print the collection json code to the console. If you want to write the result in a file use the -f or --filename option

 python cli.py gen_postman_collection -f ~/bpm-projects-collection.json

Afterwards you can import this collection into Postman and use it instead of the main web app to test this api

Built with

License

Copyright 2018 ioet Inc. All Rights Reserved.