1. Functionalities covered:
- Rest API CRUD opertaions;
- Oauth2 integration handling both id and access token;
- Validation for request data using dtos and schemas;
- Unit tests with a mixin of unittest & pytest
- API docs with swagger;
- Code quality assured with pylint;
2. Programming principles covered:
- Best practices in Flask;
- Geneneric response format;
- Custom error handling for all response types;
It is assumed that:
-
Clone git repository:
git clone https://github.com/sorin-sabo/Flask-Rest-Api.git
-
Create virtual environment
- Windows
python -m venv $(pwd)/venv source venv/bin/activate
- OS X
python3 -m venv $(pwd)/venv source venv/bin/activate
-
Install requirements:
- Windows
pip install -r requirements.txt
- OS X
pip3 install -r requirements.txt
-
Add environment variables
- Create a file named
.env
in project root directory - Add and fill next environment variables with your local database config:
DATABASE_USERNAME= DATABASE_PASSWORD= DATABASE_NAME= DATABASE_PORT= DATABASE_HOST= OAUTH2_DOMAIN= OAUTH2_GUEST= OAUTH2_CLIENT=
- Create a file named
- Application can run directly from cmd using fallowing commands:
-
Using python run
- Windows
python app.py run
- OS X
python3 app.py run
-
Using flask run
flask run
-
- Tests are done with a mixin of unittest & pytest
- A base class is created for all unit tests to inherit and can be found in
tests/utils/base
-BaseTestCase
- A base class is created for all unit tests to inherit and can be found in
- Run:
-
Method1:
- Windows:
python app.py test
- OS X:
python3 app.py test
-
Method2 - Using pytest:
-
For fallowing options are available:
-v
- to have verbose tests-s
- to see logging from tests
-
Windows:
pytest tests
- OS X:
pytest -q tests
-
-
-
Run fallowing commands
- Windows
python app.py db init python app.py db migrate python app.py db upgrade
- OS X
python3 app.py db init python3 app.py db migrate python3 app.py db upgrade
- Before deploy check package dependencies (since 2020 Dec 01 is no longer done automatically):
python -m pip check
- Pylint used to maintain code quality;
- Rules for code quality can be consulted in
.pylintrc
- Current status:
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
- Make sure before deployment that code quality is the same;