/drink-partners

Primary LanguagePythonApache License 2.0Apache-2.0

Drink Partners API

Travis Build codecov

REST API responsible for managing partners

Install dependencies

  1. Create virtualenv:
    virtualenv drink_partner -p python3
  1. Install dependencies using pip
 make requirements-dev

Tests

  1. Install docker or download mongodb

    Docker for Mac

    Docker for Linux

    Docker for Windows

    Mongodb for Mac

    Mongodb for Linux

  2. Run docker-compose for project dependencies:

docker-compose up
  1. To run all suite tests:
make test
  1. To execute specific tests:
make test-matching Q=[test_name_or_test_class_name] 
  1. To execute test coverage:
make test-coverage

Running application

  1. Run service dependencies:
docker compose-up
  1. Run application:
make run

Documentation (Swagger)

  1. Execute steps Running application above

  2. Access doc endpoint:

127.0.0.1/docs/
  1. Set token by clicking in Authorize button and adding token test

Deploy

  1. Clone repository

  2. Install Heroku

  3. Configure account for heroku. If you already have one just login

    heroku login

Create App

To create app in your Heroku account:

heroku create app drink_partners

Set environment variables

heroku config:set GUNICORN_WORKERS=5 --app drink-partners

heroku config:set PORT=443 --app drink-partners

heroku config:set SIMPLE_SETTINGS=drink_partners.settings.production --app drink-partners

heroku config:set MONGODB_URI=mongodb://<address-mongodb> ---app drink-partners

heroku config:set MOTOR_DB=<database-name> ---app drink-partners

heroku config:set APP_TOKEN=<app-for-token-usage> ---app drink-partners

Configure MongoDB

If you do not have a MongoDB server available, you could the service using Add-ons from Heroku.

  1. Access you personal account in https://id.heroku.com/login
  2. Filter for the app name you have created (e.g: drink-partners)
  3. Click on Menu Resources
  4. In Add-ons, search for mongodb and click on mLab MongoDB
  5. It will automatically configure your mongodb for application

In this case, it will generate MONGODB_URI env var automatically. You can check use command heroku config as below:

heroku config
GUNICORN_WORKERS: 1
MONGODB_URI: mongodb://heroku_123:some_password@ds059215.mlab.com:59215/heroku_0dmrmq8z

The URI has the following pattern:

mongodb://<user>:<password>@<mongodb_address>/<database_name>

If you do so, you will need to set env var MOTOR_DB with the content from database name. In this example, database name is heroku_0dmrmq8z.

heroku config:set MOTOR_DB=heroku_0dmrmq8z ---app drink-partners

You also need to reset MONGODB_URI with ?retryWrites=false at the end of the connection string

heroku config:set MONGODB_URI="mongodb://heroku_123:some_password@ds059215.mlab.com:59215/heroku_0dmrmq8z?retryWrites=false"

Create Indexes

Access MongoDB and connect to database configured and execute commands in doc/mongodb_indexes.md

Deploy Application

Deploy your application to heroku with command:

git push heroku master

Check logs

heroku logs