Python/Flask simple web api. This API manage the following resources:
-
messages : Information about a specific message (duration, date, category, etc.)
-
messageCategories: CategoryName and relationship with messages
Install docker and run:
docker-compose build
docker-compose up -d
Initialize the postgre cointainer with the messages schema
docker-compose run web python3 migrate.py db upgrade
Visit http://localhost:5000
- To stop the containers
docker-compose down
- Create a database in PostgreSQL, login as the default user (set "messages" to your desired new db name)
sudo -u postgres createdb messages
sudo -u postgres -i
- Run the psql client and create a new user with a role to manage the new db. (set 'apiuser' to your user, 'password' to your password and 'messages' to your database name)
psql
CREATE ROLE apiuser WITH LOGIN PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE messages TO apiuser;
ALTER USER apiuser CREATEDB;
-
Update the contents of config.py with the values for your database name, database user, database host. The current values are used for docker images
-
Initialize the db via migration from flask
python migrate.py db upgrade
- Only if there are changes in the models that are not present on the migrations scripts, the following command must be executed to update the migration scripts
python migrate.py db migrate
- Install the requirements and run the app
pip install -r requirements.txt
python app.py
Visit http://localhost:5000
- Create a branch for features or fixes.
- After making changes rebuild the docker images and run the containers.
docker-compose build
docker-compose up -d
- Build the test images and run the tests
docker-compose -f docker-compose.tests.yml -p ci build
docker-compose -f docker-compose.tests.yml -p ci run test python -m pytest --cov=web/ tests
- First you need to setup a local database and update the config file with the values for your db name, user name, password and db hostname
- Create a database in PostgreSQL, login as the default user (set 'test_mesages' to your desired new db name)
sudo -u postgres createdb 'test_messages'
sudo -u postgres -i
- Run the psql client and set the privileges to our previously created user to manage the new db.
psql
GRANT ALL PRIVILEGES ON DATABASE test_messages TO apiuser;
pip install pytest pytest-cov pytest-flask
pytest --cov=web/ tests