Skip to content

PozziSan/manotes-api

 
 

Repository files navigation

manotes-api

A Python restful-api sample.

Coverage Status Maintainability

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. If you prefer, you can also use Docker to get your copy running.

Prerequisites - Local Installation

  • Linux
  • Python 3+
  • Pip3
  • Virtualenvwrapper (optional but recommended)
  • PostgreSQL 10+

Prerequisites - Docker

  • Docker CE
  • docker-compose

Installing - Local Installation

Installing requirements

$ sudo apt-get install redis-server
$ git clone git@github.com:antunesleo/manotes-api.git
$ mkvirtualenv manotes-api (Optional)
$ workon manotes-api (Optional)
$ pip install -r requirements.txt
$ pip install -r requirements_dev.txt

Dealing with environments variables

$ cd
$ vim .bashrc

Add this in the end of file and reopen the terminal
alias load-env='export $(cat .env | xargs)'
alias load-env-test='export $(cat .env.test | xargs)'

$ load-env

Setting up database

$ sudo apt-get install postgres
$ sudo su postgres
$ psql
$ CREATE ROLE manotes SUPERUSER LOGIN PASSWORD 'manotes'
$ CREATE DATABASE manotes
$ ALTER DATABASE manotes OWNER TO manotes;
$ \q
$ exit

Create a .env file based on .env.sample, with your custom configuration (if necessary) and then:
$ load-env
$ python manage.py db upgrade

Configuring tests coverage

sudo vim .coveralls.yml

repo_token: <repo_token>
service_name: manotes

Running the tests - Local Installation

load-env-test
python -m testtools.run

Updating testing-coverage - Local Installation

coverage run --omit=<path_to_envs>/* -m testtools.run
coveralls

Running API - Local Installation

load-env
python run.py

Installing - Docker

Preparing the Environment Variables

$ cp .env.sample.docker .env

You can also copy using your file browser, if you prefer.

Change the default configurations, as TEMP_FILE_PATH or TEMP_PATH to your project home path.

$ docker-compose up --build -d
$ docker-compose exec web bash
# python manage.py db upgrade

The last command will run the migrations

This will also take your project running!

Running the tests - Docker

$ docker-compose up -d
$ docker-copose exec web bash

This will take you inside the Web Container Bash.

$ python -m testtools.run

Updating The Coverage - Docker

$ docker-compose up -d
$ docker-compose exec web bash

This will take you inside the Web Container Bash.

coverage run --omit=<path_to_envs>/* -m testtools.run
coveralls

Running API - Docker

$ docker-compose up -d

Features

Features Description
Login [POST] in the endpoint 'api/login' unauthenticated users can login
Create Account [POST] in the endpoint 'api/account' users can create account passing email, username and password
Update Account [PUT] in the endpoint 'api/account' authenticated users can update account infos passing email and/or username
Update Avatar [PUT] in the endpoint 'api/avatar' authenticated users can update avatar passing a file binary keyed avatar
Create Note [POST] in the endpoint 'api/notes' authenticated user can create a note passing name, content and color
Update Note [PUT] in the endpoint 'api/notes' authenticated user can update a note passing name, content and color
Get Note [GET] in the endpoint 'api/notes/<note_id>' authenticated user can list all notes or get a specific note if note_id is passed
Delete Note [DELETE] in the endpoint 'api/notes/<note_id>' authenticated user can delete a note

Built With

  • Alembic - lightweight database migration tool for usage with the SQLAlchemy Database Toolkit
  • boto3 - AWS SDK for Python, which allows Python developers to write software that makes use of services like S3.
  • celery - Distributed task queue
  • coveralls - Python interface to coveralls.io API
  • coverage - Code coverage measurement for Python
  • Flask - The web framework used
  • flask-CORS - A Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible.
  • Flask Migrate - an extension that handles SQLAlchemy database migrations for Flask applications using Alembic.
  • Flask-RESTful - an extension for Flask that adds support for quickly building REST APIs
  • gunicorn - a Python WSGI HTTP Server for UNIX
  • mock - mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
  • passlib - comprehensive password hashing framework
  • pip - Dependency Management
  • Psycopg - PostgreSQL adapter for the Python programming language
  • SQLAlchemy - Python SQL toolkit and Object Relational Mapper
  • SQLAlchemy-Utils - Various utility functions for SQLAlchemy.
  • testtools - testtools is a set of extensions to Python’s standard unittest module.

Authors

  • Leonardo Antunes - Initial work - antunesleo
  • Pedro Pozzi Ferreira - Dockerization and Packages Update - PozziSan

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

pass

About

A Python RESTful API sample

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.8%
  • Mako 0.2%